Free Support Forum - aspose.com

CadImage.Save(...) with margins set to zero still adds margins to output image

I am using the latest version of Aspose.CAD .NET and trying to save a drawing (DWG) to PNG in parts using RelativeScale and RelativePosition. The Margins property of CadRasterizationOptions is set to zero as I do not wish to have a margin. The resulting image still has a margin, which means the resulting image parts cannot be put together to form a complete image.

I would like an option for the margin to actually be zero when it is set to zero. Right now I am not really sure how the margin is calculated or what unit it is using, so it’s very difficult to remove it entirely.

Setting the Margins to a negative number when using RelativeScale and RelativeSize also causes the right and bottom side of the resulting image to miss the edge of the drawing. In other words, even if I calculate the margin with some degree of accuracy, the resulting image is still not rendered as expected.

To sum up, I want to save a drawing as PNG tiles that match up when put side-by-side. But right now the Margins property makes this impossible. The tiles don’t match up. A new option in CadRasterizationOptions called NoMargins (or something similar) would be much appreciated.

If there is a way to do this already, I would very much like to know.

Another thing I’ve noticed, is that when trying to save a CadImage from multiple threads, a static dictionary created during the save process causes this to fail. Is that something you can change, to make it thread-safe?

Thanks!

@ImmeroSoftworks

You can use API property (Zoom) to improve scaling. If this value is set to 1, no margins will be visible. By default this value is a bit less than 1 to preserve margins. This can be one possible solution for you.

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);
}

Epic, that did the trick! Thank you very much!

@ImmeroSoftworks

Great to listen that suggested option worked for you.