I got the following exception while converting a .DWG file to a PDF using Aspose.CAD:
Image export failed: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
public MemoryStream ConvertCADToPDF(Stream cadStream, CompressionType? compressionType = null)
{
try
{
//Aspose.CAD.License lic = new Aspose.CAD.License();
//lic.SetLicense(Serv.ImageProcessing.lic.generateLicenceStream());
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(cadStream))
{
// Create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
// Set page width & height
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// Create an instance of PngOptions for the resultant image
Aspose.CAD.ImageOptionsBase options = new Aspose.CAD.ImageOptions.PdfOptions();
// Set rasterization options
options.VectorRasterizationOptions = rasterizationOptions;
//saveDir = saveDir + "conic_pyramid_raster_image_out.pdf";
// Save resultant image
//image.Save(saveDir, options);
MemoryStream memStream = new MemoryStream();
image.Save(memStream, options);
memStream.Seek(0, System.IO.SeekOrigin.Begin);
if (compressionType != null)
{
memStream = CompressPDFInMemory(memStream, compressionType);
}
return memStream;
}
}
catch (Exception ex)
{
throw ex;
}
}
Attached sample CAD files throwing this exception.
CAD Files.zip (3.3 MB)