Error on loading dxf

With sample dxf file in attachment we are receiving a 0 pages aspose document
this is our code:
m_oDocument = Aspose.Imaging.Image.Load(_oInputStream);
m_iPageCount = ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Layouts.Count;

it works with dwg files… this is because dwg has layouts but dxf har layers, so what is the right way to load and convert into images and pdf?
a loop over layers or a loop over layouts?


more over we can see in aspose object this exeption in its BitsPerPixel property
’((Aspose.Imaging.FileFormats.Cad.CadImage)(m_oDocument)).BitsPerPixel’ threw an exception of type 'System.NotImplementedException’

thanks a lot

Hi Valerio,

Thank you for your inquiry.

You can use following line of code to get the layers count:

Aspose.Imaging.FileFormats.Cad.CadImage.Layers.Count

Furthermore we have tried to convert DXF file provided by you to PDF using following code snippet. Output PDF file has also been attached for your reference.

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath))
{
//Create an instance of CadRasterizationOptions and set its various properties
Aspose.Imaging.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
//Add desired layers
rasterizationOptions.Layers.Add("SLD-0");
//Add desired layout
//rasterizationOptions.Layouts = new string[] { "Model" };
//Create an instance of PdfOptions
Aspose.Imaging.ImageOptions.PdfOptions pdfOptions = new Aspose.Imaging.ImageOptions.PdfOptions();
//Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
//Export the DXF to PDF
image.Save("Gear Sample-iss4_out.pdf", pdfOptions);
}

For more details please visit the online documentation link AutoCAD DXF Drawings.

Ok so in a general method to convert DWG and DXF files, is it right to check if the aspose object has layouts and or layers?
For instance, today we first check if object has layouts: if so then convert every layout into images, and pdf pages, if not we suppose just a single page DXF and save every layer into one image and a pdf.
Is it the correct way/strategy?
Thank you

Hi Valerio,

Yes, in case of DWG file you will have both layers count and layouts count values. On the other hand for DXF file you will get layers count.