Font Thickness and Line Thickness different when Normalize export page size despite of unit type defined on drawing

Hello,

When we generate pdf from dxf appying Normalize export page size despite of unit type defined on drawing, then the line thickness and text thickness is more than given in actual drawing. line thickness and text thickness are normal if we do not scale the page size

Code for Output without applying pdf page size

String dataDir = Utils.getDataDir(ExportDXFDrawingToPDF.class) + "DXFDrawings/";
String srcFile = dataDir + filename + ".dxf";
Image image = Image.load(srcFile);

CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());

CadImage cadImage = (CadImage) image;

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save(dataDir + filename + ".pdf", pdfOptions);

Code for Output applying pdf page size
Reference: Image - Aspose.CAD for Java - API Reference

String filename = "WKT GA";
String dataDir = Utils.getDataDir(ExportDXFDrawingToPDF.class) + "DXFDrawings/";
String srcFile = dataDir + filename + ".dxf";
Image image = Image.load(srcFile);

CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());

Boolean currentUnitIsMetric = false;
double currentUnitCoefficient = 1.0;
PageSize pageSize = new PageSize(cadImage.getUnitType());
currentUnitIsMetric = pageSize.getIsMetric();
currentUnitCoefficient = pageSize.getCoefficient();

if (currentUnitIsMetric) {
double metersCoeff = 1 / 1000.0;
double scaleFactor = metersCoeff / currentUnitCoefficient;
rasterizationOptions.setPageWidth((float) (297 * scaleFactor));
rasterizationOptions.setPageHeight((float) (210 * scaleFactor));
rasterizationOptions.setUnitType(UnitType.Millimeter);
} else {
rasterizationOptions.setPageWidth((float) (11.69f / currentUnitCoefficient));
rasterizationOptions.setPageHeight((float) (8.27f / currentUnitCoefficient));
rasterizationOptions.setUnitType(UnitType.Inch);
}

CadImage cadImage = (CadImage) image;

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save(dataDir + filename + ".pdf", pdfOptions);

Could you please help how to keep text and line thickness same as per drawing when Normalize export page size

Issue.png (87.4 KB)
Output applying pdf page size.pdf (562.0 KB)
Output without applying pdf page size.pdf (536.3 KB)
WKT GA.zip (120.5 KB)

@velotech,
Hello.

Widths of lines come from the drawing and they look correctly in both results with scaling and without. But because one PDF is much bigger in size lines are visually thin in it.

You can try to apply this option to make text looking thin:

RasterizationQuality q = new RasterizationQuality();
q.setTextThicknessNormalization(true);
rasterizationOptions.setQuality(q);

Additionally, you can change the line widths in all layers in the drawing before export with:

for (int i = 0, size = cadImage.getLayers().size(); i < size; i++)
{
CadLayerTable layer = (CadLayerTable) cadImage.getLayers().get_Item(i);
layer.setLineWeight((short) 0);
}

Here is the result on my side: WKT GA.dxf_java_.pdf (1.7 MB)

This code solved the issue. Thanks

1 Like

@velotech,
we were happy to help :slight_smile: