How to retrieve height and width of drawing at DWG file

Hello, we are trying to use the Aspose.Imaging for .NET 2.4.0 (see the link) to convert the DWG file to PDF file.

The conversion is successful as long as there are no 3D objects inside the AutoCAD file.

One thing we are looking into is what width and height we should supply for the converted PDF file before conversion. We would like to read the width and height of the drawing at the AutoCAD file and derive the PDF width/height based on those. However we didn't find any API at Aspose library for getting height and width of original drawing. Please let us know if it is possible.

Thanks very much in advance.

Hi Pingzhong,


Thank you for contacting Aspose support.

You may use the Image.Width & Height properties to retrieve the dimensions (image bounds) of the loaded image, and set the same to PdfOptions.PageWidth & PageHeight respectively. Please check the below code snippet for your reference.

C#

using (var image = Aspose.Imaging.Image.Load(myDir + “sample.dwg”))
{
var options = new Aspose.Imaging.ImageOptions.PdfOptions();
options.PageHeight = image.Height;
options.PageWidth = image.Width;
image.Save(myDir + “output.pdf”, options);
}

Moreover, you may set any reasonable values to the PdfOptions.PageWidth & PageHeight properties, and render the drawing in that predefined page size by using the PdfOptions.ScaleMethod property. Please check the following piece of code.

C#
using (var image = Aspose.Imaging.Image.Load(myDir + "sample.dwg")) { var options = new Aspose.Imaging.ImageOptions.PdfOptions(); options.PageHeight = 500; options.PageWidth = 500; options.ScaleMethod = Aspose.Imaging.FileFormats.Cad.ScaleType.ShrinkToFit; image.Save(myDir + "output.pdf", options); }

Thanks Babar. We will do some testing and let you know our findings.

Hi, Babar, we did some testing and we found out that image.height and image.width are the size of the DWG file, rather the size of drawing inside the file. Just wonder if we could get the size of drawing inside the DWG file. Thanks

Hi Pingzhong,


Thank you for writing back.

I am afraid, the current implementation of Aspose.Imaging for .NET API does not provide means to retrieve the drawing size inside the DWG file. We have logged a feature request (IMAGING-34284) in our database to look further into this matter. In the meanwhile, if there is a workaround for this situation, we will post here for your kind reference.

Sure, thanks Babar.

Hi Pingzhong,


You may use the following piece of code to retrieve the CAD drawing’s start & end points.

C#

CadImage image = (CadImage)Image.Load(filename);
Aspose.Imaging.PointF minPoint = image.MinPoint;
Aspose.Imaging.PointF maxPoint = image.MaxPoint;

Please note, Min/Max points show physical size of a drawing (corresponding to EXTMAX and EXTMIN here and may be infinities in case of infinite entities presence, e.g. xlines), height/width are estimated according to max and min points and layout min/max parameters (LIMMAX and LIMMIN).

Please let us know if this satisfies your requirement.

Hi Pingzhong,


This is to update you that we are about to close the ticket logged earlier as IMAGING-34284 against your request of providing mechanism to retrieve the size of the drawing in a CAD file. The solution has been delivered in our previous post. However, if you have any other concerns or more requests, we can tackle them under separate incidents.

Please feel free to write back in case you have any concerns or questions.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.