Set PDF margins when converting DWG to PDF using Aspose.CAD(C#)

I am trying to convert DWG to PDF files using CadImage.Save(pdfFileName, pdfOptions). Is there a way that I can specify what the margins of the document should be?

Thanks.

@trippshelnutt,

I have observed your comments. I have Shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue. Also please visit this documentation link for more details.

using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
cadImage.UpdateSize();

CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

rasterizationOptions.UnitType = UnitType.Micrometer;
rasterizationOptions.PageHeight = cadImage.Height;
rasterizationOptions.PageWidth = cadImage.Width;
rasterizationOptions.CenterDrawing = true;
rasterizationOptions.Zoom = 1f;

rasterizationOptions.Layers.Add(“Print”);
rasterizationOptions.Layers.Add(“L1_RegMark”);
rasterizationOptions.Layers.Add(“L2_RegMark”);

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(outDir + fileName + “.pdf”, pdfOptions);
}

Thanks for the help.

I should have clarified from my initial post that I’m using Aspose.CAD 17.12 in .Net.

I’ve tried to implement some of the methods that are missing from my code (UpdateSize is one). I think the Layer options are DWG specific so I have let those out.

Where is the documentation for CadRasterizationOptions.Zoom property? This property is not available to me in the version that I am using.

Also, I’m looking for something along the lines of Aspose.Pdf.Document.PageInfo.Margin where I can set .Top, .Left, .Right, .Bottom. Is there a way to accomplish this?

Thanks.

@trippshelnutt,

I have observed your following comments.

Please visit this API reference link to CadRasterizationOptions class. There is no such property as zoom available. Can you please elaborate your requirements that what you want to achieve on your end. Secondly, the sample shared by Adnan for width and height in CadRasterizationOptions are possible available options.

Here is some more information about my requirements. I need to scale the DWG to the specified PageWidth and PageHeight leaving room for margins on all sides of the document. Currently the entire model is being scaled out to the edges of the document. I would like the ability to specify margins on the page so that the model doesn’t scale out to the edges of the page, but would leave a margin instead.

Here is an example of what I’d like to accomplish and we are using this code in other places for image conversion. When Page margin is specified in this way for images, the converted image leaves room on the outer edges of the page.

private static void SetMargins(Page page)
{
    page.PageInfo.Margin.Top = Margin;
    page.PageInfo.Margin.Left = Margin;
    page.PageInfo.Margin.Right = Margin;
    page.PageInfo.Margin.Bottom = Margin;
}

@trippshelnutt,

I have observed your requirements and like to share that in upcoming product release, Aspose.CAD for .NET 18.2, we have provided CadRasterizationOptions.Zoom property. The default value is 1 which corresponds to full scaling without margins. You can set any value lesser than 1 to get the margin effect. We will share the information with you once the support will be available.

The issues you have found earlier (filed as CADNET-506) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by mudassir.fayyaz