We are trying to use Aspose.CAD to get pdfs from DWG files, and we are getting exceptions while trying to convert. The exception is not always the same, and it is not consistent, and loading and saving files directly from the disk or MemoryStreams seems to make a difference in the outcome as well.
My code is as follows:
string file = "path/to/dwg/file";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(file))
{
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.White;
rasterizationOptions.PageWidth = 800;
rasterizationOptions.PageHeight = 600;
rasterizationOptions.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor;
rasterizationOptions.GraphicsOptions.InterpolationMode = Aspose.CAD.InterpolationMode.Low;
rasterizationOptions.GraphicsOptions.SmoothingMode = Aspose.CAD.SmoothingMode.None;
rasterizationOptions.GraphicsOptions.TextRenderingHint = Aspose.CAD.TextRenderingHint.SystemDefault;
rasterizationOptions.Quality.Arc = Aspose.CAD.ImageOptions.RasterizationQualityValue.Low;
rasterizationOptions.Quality.Hatch = Aspose.CAD.ImageOptions.RasterizationQualityValue.Low;
rasterizationOptions.Quality.Text = Aspose.CAD.ImageOptions.RasterizationQualityValue.Low;
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
var tempPath = "C:\\temp\\" + Path.GetRandomFileName();
image.Save(tempPath, pdfOptions);
var returnBytes = File.ReadAllBytes(tempPath);
File.Delete(tempPath);
return returnBytes;
}
The most common exception I get is this one:
Inner Exception Type: Aspose.CAD.CadExceptions.ImageSaveException
Inner Exception: Image export failed.
Inner Source: Aspose.CAD
Inner Stack Trace:
at Aspose.CAD.Image.SaveInternal(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
at Aspose.CAD.FileFormats.Cad.CadImage.SaveInternal(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
at .(Object )
at .(MethodBase , Boolean )
at . ()
at .()
at .(Object )
at .()
at .(Object , UInt32 )
at .()
at .()
at . ()
at .(Object )
at .()
at .(Object , UInt32 )
at . ()
at .(Object[] , Type[] , Type[] , Object[] )
at Aspose.CAD.Image.Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
at Aspose.CAD.Image.SaveInternal(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
Inner Exception Type: System.IndexOutOfRangeException
Inner Exception: Index was outside the bounds of the array.
Inner Source: Aspose.CAD
Inner Stack Trace:
at .Export(Image , Stream , ImageOptionsBase , Rectangle )
at Aspose.CAD.Image.SaveInternal(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Exception Type: Aspose.CAD.CadExceptions.ImageSaveException
Exception: Image saving failed.
Stack Trace:
at Aspose.CAD.Image.SaveInternal(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
at Aspose.CAD.Image.Save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
at Aspose.CAD.Image.Save(String filePath, ImageOptionsBase options)
Some more info that maybe could help: This code is part of a WCF service that convert files to PDF. Each call this service receives, it fires a individual task to convert the file to PDF. We use multiple Aspose libraries in it, such as Words, Sheets and Email. It seems like the Exception is most likely to happen when you fire 2 DWG convertions at the same, but we managed to convert multiple DWGs at the same time and get the exception while converting only one DWG.
We are using the latest version of Aspose.CAD, 19.7.
estrutura-alterada.zip (424.1 KB)