Exportar dibujos y diseños DWG/DXF en tamaño especificado

Exportar modelo y todos los diseños en tamaño PDF A4

La API Aspose.CAD te permite exportar todas las hojas del archivo DWG/DXF en un tamaño físico PDF especificado. El siguiente código de ejemplo configura el tamaño del objeto CadRasterizationOptions para lograr el tamaño PDF deseado. El tamaño de la hoja de papel A4 es de 210x297 milímetros o 8.27x11.69 pulgadas y estos valores se utilizan en el código.

CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
boolean isMetric = false;
double coefficient = 1.0;
switch (cadImage.getUnitType())
{
// it is possible to extend this with more types that may appear in drawings
case UnitType.Meter:
isMetric = true;
coefficient = 1.0;
break;
case UnitType.Millimeter:
isMetric = true;
coefficient = 0.001;
break;
case UnitType.Inch:
coefficient = 1.0;
break;
}
SizeF size;
if (isMetric)
{
double metersCoeff = 1 / 1000.0;
double scaleFactor = metersCoeff / coefficient;
size = new SizeF((float)(210 * scaleFactor), (float)(297 * scaleFactor));
cadRasterizationOptions.setUnitType(UnitType.Millimeter);
}
else
{
size = new SizeF((float)(8.3f / coefficient), (float)(11.7f / coefficient));
cadRasterizationOptions.setUnitType(UnitType.Inch);
}
cadRasterizationOptions.setPageSize(size);

Exportar diseños CAD a PDF en diferentes tamaños

A veces es necesario exportar el diseño en su tamaño físico. El ejemplo a continuación muestra la exportación del dibujo en un PDF multipágina donde cada página con contenido de diseño tiene su propio tamaño físico PDF. Este ejemplo utiliza la propiedad getLayoutPageSizes .

CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
for (String layoutName : cadImage.getLayouts().getKeysTyped())
{
CadLayout layout = cadImage.getLayouts().get(layoutName);
if (layout.getLayoutName() == "Model") continue;
System.out.println(layout.getLayoutName());
SizeF pageSize = GetPageSizeFromLayout(layout);
cadRasterizationOptions.getLayoutPageSizes().put(layout.getLayoutName(), pageSize);
}
private static SizeF GetPageSizeFromLayout(CadLayout layout)
{
boolean isLandscape = IsLayoutLandscape(layout);
float pageWidth;
float pageHeight;
if (layout.getPlotPaperUnits() == CadPlotPaperUnits.PlotInInches)
{
pageWidth = (float)MillimetersToInches(layout.getPlotPaperSize().getWidth());
pageHeight = (float)MillimetersToInches(layout.getPlotPaperSize().getHeight());
}
else
{
pageWidth = (float)layout.getPlotPaperSize().getWidth();
pageHeight = (float)layout.getPlotPaperSize().getHeight();
}
if (isLandscape)
{
return new SizeF(pageHeight, pageWidth);
}
else
{
return new SizeF(pageWidth, pageHeight);
}
}
private static boolean IsLayoutLandscape(CadLayout layout)
{
short plotRotation = layout.getPlotRotation();
return plotRotation == CadPlotRotation.Clockwise90Degrees || plotRotation == CadPlotRotation.Counterclockwise90Degrees;
}
private static double MillimetersToInches(double millimeters)
{
double MillimetersToInchesFactor = 0.0393701;
return millimeters * MillimetersToInchesFactor;
}