I was trying to convert some dwg files to pdf using the basic convertion code using this code in Azure Databricks:
import os
import aspose.cad as cad
try:
# Iterate through all files in the directory and its subdirectories
for foldername, subfolders, filenames in os.walk(root_directory):
for filename in filenames:
if filename.endswith(".dwg"):
# Construct the full path to the DWG file
dwg_path = os.path.join(foldername, filename)
# Construct the output PDF file path
pdf_output_path = os.path.join(foldername, filename[:-4] + "-Conv.pdf")
# Check if a PDF file with the same name already exists
if not os.path.exists(pdf_output_path):
# Load an existing DWG file
image = cad.Image.load(dwg_path)
# Initialize and specify CAD options
rasterizationOptions = cad.imageoptions.CadRasterizationOptions()
rasterizationOptions.page_width = 1200.0
rasterizationOptions.page_height = 1200.0
rasterizationOptions.draw_type = cad.fileformats.cad.CadDrawTypeMode.USE_OBJECT_COLOR
# Specify PDF Options
pdfOptions = cad.imageoptions.PdfOptions()
pdfOptions.vector_rasterization_options = rasterizationOptions
# Save as PDF
image.save(pdf_output_path, pdfOptions)
print(f"Conversion complete for: {dwg_path}. Output saved to: {pdf_output_path}")
else:
print(f"PDF file already exists for: {dwg_path}. Skipping conversion.")
except Exception as e:
raise (e)
This code has been working for a while now but since today I am getting this error:
Proxy error(TypeInitializationException): The type initializer for 'Aspose.CAD.Image' threw an exception. ---> FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
Even when I tried changing the test files the same error still persists.