I’m struggeling with the fact that I want to set the PageWidth and PageHeight properties in a new instance of the CadRasterizationOptions class that I’ll pass into the PdfOptions.
I set the UnitType to UnitType.Millimeter.
But whatever I do, it applies the PDF Width/Height as Inches, and not as Millimeters.
Result is a PDF with page size 25,40 x 38,10 cm, which is exactly 10 x 15 inch.
Off course I can simply divide the number of milimeters in the CadRasterizationOptions with 25.4 to get the corresponding number of inches and the result PDF will be fine. But it looks a bit strange to me. Is this a bug? Or do you need to do something different here?
It appears you are encountering an issue with the CadRasterizationOptions class, where the PageWidth and PageHeight properties are not being interpreted in millimeters as expected, but rather in inches.
This behavior may stem from how the CadRasterizationOptions class processes unit types. Although you have set the UnitType to Millimeter, it seems that the PageWidth and PageHeight properties are still being treated as inches.
As a workaround, you can manually convert the dimensions from millimeters to inches by dividing the values by 25.4. Here’s how you can adjust your code:
using (CadImage cadImage = (CadImage)Image.Load("architectural_example-imperial.dwg"))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
Layouts = new string[] { "Model" },
UnitType = UnitType.Millimeter,
PageWidth = 10 / 25.4, // Convert mm to inches
PageHeight = 15 / 25.4, // Convert mm to inches
AutomaticLayoutsScaling = true,
DrawType = CadDrawTypeMode.UseObjectColor,
BackgroundColor = Color.White
};
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save("architectural_example-imperial.dwg.pdf", pdfOptions);
}
This adjustment should yield the correct page size in the resulting PDF. If the issue persists, consider consulting the official documentation or reaching out to support for further clarification on the expected behavior of the CadRasterizationOptions.
@elw00d,
Hi,
yes, if you need to get output of the desired size you need to do conversion between initial units and desired yourself, like it is shown in this example. Applying UnitType without these calculations is useful for quick scaling of the output canvas size (mainly for Unitless drawings).
UnitType of my CAD image (DWG) is Unitless.
So the example code you reference will not do anything, because there is no case for that.
And I still believe it would make sense to be able to set the UnitType to millimeters for the output. Especially if the source image is unitless.
So for example, DWG is unitless with size 1189 x 841 ‘undefined units’.
I say, okay let’s convert that to PDF and my desired size will be 1189 x 841 ‘millimeters’. Valid use case to me. It’s strange that the outcome now is that it will create a PDF with size 1189 x 841 ‘inches’, which comes out of nowhere. And it’s not possible because the max PDF canvas size is 200 x 200 inches.
@elw00d,
Yes, all your points are valid But UnitType property in options was not developed to be the complement to PageWidth/PageHeight in order to define physical size of the output canvas. It is supposed to be used more for the opposite - to apply some independent scaling factor when the physical size of the output canvas doesn’t matter, e.g., it could be used when PageWidth and PageHeight are not set at all. But let us revise how it works right now and think one more time about its probably better usage.
@oleksii.gorokhovatskyi
Ok, I understand.
I just tested with a DWG with a unitless size of 1189 x 841, and I used these raster. options (not setting PageWidth and PageHeight myself):