تحويل DWG إلى PDF مع الإحداثيات
Contents
[
Hide
]كيف يتم تحويل DWG إلى PDF مع الإحداثيات
تقدم Aspose.CAD ميزة تحميل ملف AutoCAD DWG وتصديره إلى تنسيق PDF من خلال توفير إحداثيات. لهذا، توفر واجهة برمجة التطبيقات CadVportTableObject . تستخدم فئة CadVportTableObject لتحديد الإحداثيات لتحويلها.
يعرض مثال الكود أدناه كيفية تحويل ملف DWG إلى تنسيق PDF من خلال توفير الإحداثيات باستخدام Aspose.CAD لجافا.
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
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
String srcFile = dataDir + "visualization_-_conference_room.dwg"; | |
CadImage cadImage = (CadImage)Image.load(srcFile); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setLayouts(new String[]{"Model"}); | |
rasterizationOptions.setNoScaling(true); | |
// note: preserving some empty borders around part of image is the responsibility of customer | |
// top left point of region to draw | |
Point topLeft = new Point(500, 1000); | |
double width = 3108; | |
double height = 2489; | |
CadVportTableObject newView = new CadVportTableObject(); | |
CadStringParameter cadStringParameter = new CadStringParameter(); | |
cadStringParameter.init("*Active"); | |
newView.setName(cadStringParameter); | |
newView.getCenterPoint().setX(topLeft.getX() + width / 2f); | |
newView.getCenterPoint().setY(topLeft.getY() - height / 2f); | |
newView.getViewHeight().setValue(height);; | |
newView.getViewAspectRatio().setValue(width / height); | |
for (int i = 0; i < cadImage.getViewPorts().size(); i++) | |
{ | |
CadVportTableObject currentView = (CadVportTableObject)(cadImage.getViewPorts().get_Item(i)); | |
if (cadImage.getViewPorts().size() == 1 || currentView.getName().getValue().equalsIgnoreCase("*active")) | |
{ | |
cadImage.getViewPorts().set_Item(i, newView); | |
break; | |
} | |
} | |
// Create an instance of PdfOptions | |
PdfOptions pdfOptions = new PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
dataDir = dataDir + "ConvertDWGToPDFBySupplyingCoordinates_out.pdf"; | |
//Export the DWG to PDF | |
cadImage.save(dataDir, pdfOptions); | |