การส่งออก CAD
ส่งออกภาพ 3D AutoCAD ไปยัง PDF
Aspose.CAD ช่วยให้คุณสามารถส่งออกภาพ 3D AutoCAD ไปยัง PDF ได้ โปรดใช้ TypeOfEntities.Entities3D ใน ImageOptions.CadRasterizationOptions เพื่อระบุว่าคุณต้องการส่งออกเอนทิตี 3D ตัวอย่างโค้ดด้านล่างโหลดไฟล์ AutoCAD 3D และส่งออกไปยัง PDF เมื่อไฟล์ถูกแปลงเป็น PDF คุณสามารถเปิดด้วย PDF viewer ที่คุณชื่นชอบ
ตัวอย่างโค้ดด้านล่างแสดงวิธีการส่งออกภาพ 3D AutoCAD ไปยัง PDF
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(Export3DAutoCADImagesToPDF.class) + "ExportingCAD/"; | |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
Image cadImage = Image.load(srcFile); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(500); | |
rasterizationOptions.setPageHeight(500); | |
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D); | |
rasterizationOptions.setLayouts(new String[] {"Model"}); | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
cadImage.save(dataDir + "Export3DImagestoPDF_out_.pdf", pdfOptions); |
การส่งออก CAD Layouts ไปยัง PDF
Aspose.CAD สำหรับ Java ช่วยให้คุณส่งออก CAD layouts ไปยัง PDF ได้ save วิธีการของคลาส CadImage สามารถใช้ส่งออกเลย์เอาต์ไปยังรูปแบบ PDF ตัวอย่างโค้ดด้านล่างโหลดไฟล์ CAD และส่งออกเลย์เอาต์ “Model” ไปยัง PDF เมื่อไฟล์ถูกแปลงเป็น PDF คุณสามารถเปิดด้วย PDF viewer ที่คุณชื่นชอบ
นี่คือตัวอย่างโค้ด
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(ExportCADLayoutsToPDF.class) + "ExportingCAD/"; | |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
// Create an instance of CadImage class and load the file. | |
Image cadImage = Image.load(srcFile); | |
// Create an instance of CadRasterizationOptions class | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(1600); | |
rasterizationOptions.setPageHeight(1600); | |
// Set the Entities type property to Entities3D. | |
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D); | |
rasterizationOptions.setScaleMethod(ScaleType.GrowToFit); | |
rasterizationOptions.setContentAsBitmap(true); | |
// Set Layouts | |
rasterizationOptions.setLayouts(new String[] {"Model"}); | |
// Create an instance of PDF options class | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
// Set Graphics options | |
rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality); | |
rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit); | |
rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic); | |
// Export to PDF by calling the Save method | |
cadImage.save(dataDir + "CADLayoutsToPDF_out_.pdf", pdfOptions); |
สนับสนุนการตั้งค่าปากกาในการส่งออก
Aspose.CAD สำหรับ Java ช่วยให้คุณเพิ่มตัวเลือกปากกาในการส่งออกคุณสมบัติของ CAD โดยใช้ rasterizationOptions เราสามารถตั้งค่าตัวเลือกคุณสมบัติของปากกาได้
ด้านล่างคือตัวอย่างโค้ดเพื่อให้บรรลุตามความต้องการที่ระบุ
String dataDir = Utils.getDataDir(PenSupportInExport.class) + "CADConversion/"; | |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
CadImage cadImage = ((CadImage)(Image.load(srcFile))); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(cadImage.getWidth() * 100); | |
rasterizationOptions.setPageHeight(cadImage.getHeight() * 100); | |
PdfOptions pdfOptions = new PdfOptions(); | |
// Here user can change default start cap and end cap of pens when exporting CadImage object to | |
// image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf. | |
// If user doesn't use PenOptions, system will use its own default pens (different in defferent places). | |
PenOptions penOts = new PenOptions(); | |
penOts.setStartCap(LineCap.Flat); | |
penOts.setEndCap(LineCap.Flat); | |
//rasterizationOptions.setPenOptions(penOts); | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
cadImage.save((dataDir+"9LHATT-A56_generated.pdf"),pdfOptions); | |
ย่อยวัตถุ Cad Insert
Aspose.CAD สำหรับ Java ช่วยให้คุณสามารถย่อยวัตถุ cad และประมวลผลเอนทิตีแยกภายในการแทรก ด้านล่างคือ ตัวอย่างโค้ดเพื่อให้บรรลุตามความต้องการที่ระบุ
String srcFile = dataDir + "conic_pyramid.dxf"; | |
CadImage cadImage =(CadImage) Image.load(srcFile); | |
try | |
{ | |
for (int i=0; i<cadImage.getEntities().length;i++) | |
{ | |
if (cadImage.getEntities()[i].getTypeName() == CadEntityTypeName.INSERT) | |
{ | |
CadBlockEntity block = | |
(CadBlockEntity)cadImage.getBlockEntities().get_Item(((CadInsertObject)cadImage.getEntities()[i]).getName()); | |
for (CadBaseEntity blockChild : block.getEntities()) | |
{ | |
// process entities | |
} | |
} | |
} | |
} | |
finally | |
{ | |
cadImage.dispose(); | |
} |
สนับสนุนเอนทิตี ACAD Proxy
Aspose.CAD สำหรับ Java ช่วยให้คุณสามารถอ่านและส่งออกเอนทิตี ACAD_PROXY_ENTITY ด้านล่างคือ ตัวอย่างโค้ดเพื่อให้บรรลุตามความต้องการที่ระบุ
String dataDir = Utils.getDataDir(PenSupportInExport.class) + "CADConversion/"; | |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
CadImage cadImage = ((CadImage)(Image.load(srcFile))); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(cadImage.getWidth() * 100); | |
rasterizationOptions.setPageHeight(cadImage.getHeight() * 100); | |
PdfOptions pdfOptions = new PdfOptions(); | |
// Here user can change default start cap and end cap of pens when exporting CadImage object to | |
// image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf. | |
// If user doesn't use PenOptions, system will use its own default pens (different in defferent places). | |
PenOptions penOts = new PenOptions(); | |
penOts.setStartCap(LineCap.Flat); | |
penOts.setEndCap(LineCap.Flat); | |
//rasterizationOptions.setPenOptions(penOts); | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
cadImage.save((dataDir+"9LHATT-A56_generated.pdf"),pdfOptions); | |
รวมฟอร์แมต IGES
Aspose.CAD สำหรับ Java ช่วยให้คุณอ่านและส่งออกฟอร์แมต IGES ด้านล่างคือ ตัวอย่างโค้ดเพื่อให้บรรลุตามความต้องการที่ระบุ
String dataDir = Utils.getDataDir(ExportIGEStoPDF.class) + "IGESDrawings/"; | |
String PLTPathToFile = dataDir + "figa2.igs"; | |
Image image = Image.load(PLTPathToFile); | |
//Setting PDF Options | |
PdfOptions pdfOptions = new PdfOptions(); | |
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions(); | |
cadRasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor); | |
cadRasterizationOptions.setPageHeight(1000); | |
cadRasterizationOptions.setPageWidth(1000); | |
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions); | |
//Saving to PDF | |
image.save(dataDir+"figa2.pdf", pdfOptions); | |
สนับสนุนโมเดล Mesh
Aspose.CAD สำหรับ Java ช่วยให้คุณสามารถดำเนินการและนับโมเดล mesh เช่นขอบ, จุดยอด และหน้าต่างที่ใช้การแทนรูปแบบพอดี ด้านล่างคือ ตัวอย่างโค้ดเพื่อให้บรรลุตามความต้องการที่ระบุ
String srcFile = dataDir + "meshes.dwg"; | |
// com.aspose.cad. objImage = com.aspose.cad.CImage.load(srcFile); | |
CadImage cadImage =(CadImage) com.aspose.cad.Image.load(srcFile); | |
try | |
{ | |
for (CadBaseEntity entity : cadImage.getEntities()) | |
{ | |
if (entity instanceof CadPolyFaceMesh) | |
{ | |
CadPolyFaceMesh asFaceMesh= (CadPolyFaceMesh)entity; | |
if (asFaceMesh != null) | |
{ | |
System.out.println("Vetexes count: " + asFaceMesh.getMeshMVertexCount()); | |
} | |
} | |
else if (entity instanceof CadPolygonMesh) | |
{ | |
CadPolygonMesh asPolygonMesh= (CadPolygonMesh)entity; | |
if (asPolygonMesh != null) | |
{ | |
System.out.println("Vetexes count: " + asPolygonMesh.getMeshMVertexCount()); | |
} | |
} | |
} | |
} | |
finally | |
{ | |
cadImage.dispose(); | |
} |
ตั้งค่ามุมมองที่กำหนดเอง
Aspose.CAD สำหรับ Java ช่วยให้คุณตั้งค่ามุมมองที่กำหนดเองสำหรับเลย์เอาต์โมเดล โดยใช้ vectorRasterizationOptions คุณสามารถตั้งค่ามุมมองที่กำหนดเอง ตัวอย่างโค้ดด้านล่างแสดงวิธีการตั้งค่ามุมมองที่กำหนดเอง
String dataDir = Utils.getDataDir(FreePointOfView.class) + "CADConversion/"; | |
// Path to source file | |
String sourceFilePath = dataDir+"conic_pyramid.dxf"; | |
// Load a CAD drawing in an instance of Image | |
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(sourceFilePath); | |
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions(); | |
cadRasterizationOptions.setPageHeight(1500); | |
cadRasterizationOptions.setPageWidth(1500); | |
// Create an instance of JpegOptions class | |
com.aspose.cad.imageoptions.JpegOptions options = new com.aspose.cad.imageoptions.JpegOptions(); | |
options.setVectorRasterizationOptions(cadRasterizationOptions); | |
float xAngle = 10; //Angle of rotation along the X axis | |
float yAngle = 30; //Angle of rotation along the Y axis | |
float zAngle = 40; //Angle of rotation along the Z axis | |
ObserverPoint obvPoint = new ObserverPoint(xAngle,yAngle,zAngle); | |
cadRasterizationOptions.setObserverPoint(obvPoint); | |
options.setVectorRasterizationOptions(cadRasterizationOptions); | |
//Saving to Image | |
objImage.save(dataDir+"FreePointOfView_out.jpeg", options); |