指定サイズへのDWG/DXF図面とレイアウトのエクスポート
Contents
[
Hide
]A4 PDFサイズへのモデルとすべてのレイアウトのエクスポート
Aspose.CAD APIは、DWG/DXFファイルのすべてのシートを指定された物理PDFサイズにエクスポートすることを可能にします。 以下のサンプルコードは、所望のPDFサイズを達成するためにCadRasterizationOptionsオブジェクトのサイズを設定します。 A4用紙のサイズは210x297ミリメートル(8.27x11.69インチ)であり、これらの値がコードに使用されています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
異なるサイズのPDFへのCADレイアウトのエクスポート
時には、レイアウトをその物理サイズでエクスポートする必要があります。以下の例は、各ページにレイアウトコンテンツを持つマルチページPDFへの図面のエクスポートを示しています。 この例では、getLayoutPageSizesプロパティを使用しています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |