ייצוא של שרטוטים ופריסות DWG/DXF לגודל ספציפי
ייצוא מודל וכל הפריסות לגודל PDF A4
ממשק ה-API של Aspose.CAD מאפשר לך לייצא את כל הגליונות של קובץ DWG/DXF לגודל PDF פיזי ספציפי.
הקוד לדוגמה הבא קובע את גודל האובייקט CadRasterizationOptions כדי להשיג את גודל ה-PDF הרצוי. הגודל של דף נייר A4 הוא 210x297 מילימטרים או 8.27x11.69 אינצ’ים וערכים אלו משמשים בקוד.
bool currentUnitIsMetric = false; | |
double currentUnitCoefficient = 1.0; | |
DefineUnitSystem(cadImage.UnitType, out currentUnitIsMetric, out currentUnitCoefficient); | |
if (currentUnitIsMetric) | |
{ | |
double metersCoeff = 1 / 1000.0; | |
double scaleFactor = metersCoeff / currentUnitCoefficient; | |
rasterizationOptions.PageWidth = (float)(210 * scaleFactor); | |
rasterizationOptions.PageHeight = (float)(297 * scaleFactor); | |
rasterizationOptions.UnitType = UnitType.Millimeter; | |
} | |
else | |
{ | |
rasterizationOptions.PageWidth = (float)(8.27f / currentUnitCoefficient); | |
rasterizationOptions.PageHeight = (float)(11.69f / currentUnitCoefficient); | |
rasterizationOptions.UnitType = UnitType.Inch; | |
} | |
private static void DefineUnitSystem(UnitType unitType, out bool isMetric, out double coefficient) | |
{ | |
isMetric = false; | |
coefficient = 1.0; | |
switch (unitType) | |
{ | |
case UnitType.Parsec: | |
coefficient = 3.0857 * 10000000000000000.0; | |
isMetric = true; | |
break; | |
case UnitType.LightYear: | |
coefficient = 9.4607 * 1000000000000000.0; | |
isMetric = true; | |
break; | |
case UnitType.AstronomicalUnit: | |
coefficient = 1.4960 * 100000000000.0; | |
isMetric = true; | |
break; | |
case UnitType.Gigameter: | |
coefficient = 1000000000.0; | |
isMetric = true; | |
break; | |
case UnitType.Kilometer: | |
coefficient = 1000.0; | |
isMetric = true; | |
break; | |
case UnitType.Decameter: | |
isMetric = true; | |
coefficient = 10.0; | |
break; | |
case UnitType.Hectometer: | |
isMetric = true; | |
coefficient = 100.0; | |
break; | |
case UnitType.Meter: | |
isMetric = true; | |
coefficient = 1.0; | |
break; | |
case UnitType.Centimenter: | |
isMetric = true; | |
coefficient = 0.01; | |
break; | |
case UnitType.Decimeter: | |
isMetric = true; | |
coefficient = 0.1; | |
break; | |
case UnitType.Millimeter: | |
isMetric = true; | |
coefficient = 0.001; | |
break; | |
case UnitType.Micrometer: | |
isMetric = true; | |
coefficient = 0.000001; | |
break; | |
case UnitType.Nanometer: | |
isMetric = true; | |
coefficient = 0.000000001; | |
break; | |
case UnitType.Angstrom: | |
isMetric = true; | |
coefficient = 0.0000000001; | |
break; | |
case UnitType.Inch: | |
coefficient = 1.0; | |
break; | |
case UnitType.MicroInch: | |
coefficient = 0.000001; | |
break; | |
case UnitType.Mil: | |
coefficient = 0.001; | |
break; | |
case UnitType.Foot: | |
coefficient = 12.0; | |
break; | |
case UnitType.Yard: | |
coefficient = 36.0; | |
break; | |
case UnitType.Mile: | |
coefficient = 63360.0; | |
break; | |
} | |
} |
ייצוא פריסות CAD ל-PDF בגודל שונה
לעיתים נדרש לייצא פריסה לגודלה הפיזי. הדוגמה להלן ממחישה את ייצוא השרטוט ל-PDF רב-עמודי שבו כל עמוד עם תוכן פריסה יש לו גודל PDF פיזי משלו. דוגמה זו משתמשת בנכס LayoutPageSizes .
using (CadImage cadImage = (CadImage)Image.Load(fileName)) | |
{ | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
foreach (CadLayout layout in cadImage.Layouts.Values) | |
{ | |
if (layout.LayoutName == "Model") continue; | |
SizeF pageSize = GetPageSizeFromLayout(layout); | |
rasterizationOptions.LayoutPageSizes.Add(layout.LayoutName, pageSize); | |
} | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(outPath, pdfOptions); | |
} | |
private static SizeF GetPageSizeFromLayout(CadLayout layout) | |
{ | |
var isLandscape = IsLayoutLandscape(layout); | |
float pageWidth; | |
float pageHeight; | |
if (layout.PlotPaperUnits == CadPlotPaperUnits.PlotInInches) | |
{ | |
pageWidth = (float)MillimetersToInches(layout.PlotPaperSize.Width); | |
pageHeight = (float)MillimetersToInches(layout.PlotPaperSize.Height); | |
} | |
else | |
{ | |
pageWidth = (float)layout.PlotPaperSize.Width; | |
pageHeight = (float)layout.PlotPaperSize.Height; | |
} | |
if (isLandscape) | |
{ | |
return new SizeF(pageHeight, pageWidth); | |
} | |
else | |
{ | |
return new SizeF(pageWidth, pageHeight); | |
} | |
} | |
private static bool IsLayoutLandscape(CadLayout layout) | |
{ | |
return layout.PlotRotation == CadPlotRotation.Clockwise90Degrees || layout.PlotRotation == CadPlotRotation.Counterclockwise90Degrees; | |
} | |
private static double MillimetersToInches(double millimeters) | |
{ | |
const double MillimetersToInchesFactor = 0.0393701; | |
return millimeters * MillimetersToInchesFactor; | |
} |