การส่งออกภาพวาด DXF

การส่งออกภาพวาด DXF ไปยัง PDF

Aspose.CAD มีฟีเจอร์ในการโหลดวัตถุของภาพวาด AutoCAD DXF และเรนเดอร์พวกเขาเป็นภาพวาดทั้งหมดในรูปแบบ PDF วิธีการแปลง DXF เป็น PDF ทำงานดังนี้:

  1. โหลดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอ็อบเจ็กต์ของคลาส CadRasterizationOptions และตั้งค่าอสมการ PageHeight & PageWidth
  3. สร้างอ็อบเจ็กต์ของคลาส PdfOptions และตั้งค่าอสมการ VectorRasterizationOptions
  4. เรียกใช้ Image.Save ในขณะที่ส่งอ็อบเจ็กต์ของ PdfOptions เป็นพารามิเตอร์ที่สอง

ตัวอย่างโค้ดด้านล่างแสดงวิธีการแปลงไฟล์โดยใช้การตั้งค่าเริ่มต้น

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.White;
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}

รูปแบบที่รองรับ

ในขณะนี้เราสนับสนุนรูปแบบไฟล์ AutoCAD DXF 2010 อย่างเต็มที่ รูปแบบ DXF ก่อนหน้านี้ไม่รับประกันว่าจะถูกต้อง 100% เราวางแผนที่จะรวมรูปแบบและฟีเจอร์เพิ่มเติมในเวอร์ชัน Aspose.CAD ในอนาคต

หน่วยงานที่รองรับ

ในขณะนี้เราสนับสนุนหน่วยงาน 2D ที่แพร่หลายทั้งหมดและพารามิเตอร์เริ่มต้นพื้นฐานของพวกเขาดังต่อไปนี้:

  1. มิติที่เรียงพิมพ์
  2. มิติที่มุม
  3. อาร์ค
  4. แอตทริบิวต์
  5. อ้างอิงบล็อก
  6. วงกลม
  7. มิติเส้นผ่านศูนย์กลาง
  8. รูปไข่
  9. การขีด
  10. เส้น
  11. ข้อความหลายบรรทัด
  12. มิติที่กำหนด
  13. จุด
  14. โพลีไลน์
  15. มิติรัศมี
  16. รังสี
  17. มิติที่หมุน
  18. ตาราง
  19. ข้อความ
  20. Xline

การจัดการหน่วยความจำ

อสมการ ExactReallocateOnly ของคลาส Cache สามารถใช้ควบคุมการจัดสรรหน่วยความจำใหม่ การจัดสรรใหม่จะเกิดขึ้นได้เมื่อแคชที่จัดสรรล่วงหน้าไม่เพียงพอ

  • หากตั้งค่า ExactReallocateOnly เป็นค่าเริ่มต้น False พื้นที่จะถูกจัดสรรใหม่ไปยังสื่อเดิม
  • เมื่อถูกตั้งค่าเป็น True การจัดสรรใหม่ไม่สามารถเกินพื้นที่สูงสุดที่กำหนด ในกรณีนี้แคชในหน่วยความจำที่มีอยู่ (ซึ่งต้องมีการจัดสรรใหม่) จะถูกปล่อยและพื้นที่เพิ่มเติมจะถูกจัดสรรในดิสก์

การส่งออกเลเยอร์เฉพาะของภาพวาด DXF ไปยัง PDF

วิธีการนี้ทำงานดังนี้:

  1. เปิดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอินสแตนซ์ของ CadRasterizationOptions และระบุอสมการ PageWidth & PageHeight
  3. เพิ่มเลเยอร์ไปยังอ็อบเจ็กต์ของ CadRasterizationOptions
  4. สร้างอินสแตนซ์ของ PdfOptions & ตั้งค่าอสมการ VectorRasterizationOptions
  5. เรียกใช้วิธี Image.Save และส่งอ็อบเจ็กต์ของ PdfOptions เป็นพารามิเตอร์ที่สอง

ตัวอย่างโค้ดด้านล่างแสดงวิธีการแปลงเลเยอร์เฉพาะของ DXF เป็น PDF

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Add desired layers
rasterizationOptions.Layers = new string[] { "LayerA" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layer_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}

เรนเดอร์ไฟล์ PDF เป็นส่วนหนึ่งของภาพวาด DXF

วิธีการนี้ทำงานดังนี้:

  1. โหลดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอ็อบเจ็กต์ของคลาส CadRasterizationOptions และโหลดไฟล์ PDF
  3. ตั้งค่าอสมการ PageHeight & PageWidth
  4. เรียก Image.Save และบันทึกไฟล์

ตัวอย่างโค้ดด้านล่างแสดงวิธีการเรนเดอร์ไฟล์ PDF เป็นส่วนหนึ่งของภาพวาด DXF

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Specify desired layout name
rasterizationOptions.Layouts = new string[] { "Model" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layout_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}

การส่งออก DGN ที่ถูกฝังอยู่สำหรับรูปแบบ DXF

Aspose.CAD มีฟีเจอร์ในการโหลดไฟล์ AutoCAD DXF และส่งออก DGN ที่ถูกฝังอยู่สำหรับรูปแบบ DXF

ตัวอย่างโค้ดด้านล่างแสดงวิธีการบรรลุความต้องการที่กำหนด

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new[] { "Model" };
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(MyDir + "conic_pyramid.pdf", pdfOptions);
}

การสนับสนุนการบันทึกไฟล์ DXF

Aspose.CAD มีฟีเจอร์ในการโหลดไฟล์ AutoCAD DXF และทำการเปลี่ยนแปลงในไฟล์นั้นและบันทึกลงในไฟล์ DXF อีกครั้ง

ตัวอย่างโค้ดด้านล่างแสดงวิธีการบรรลุความต้องการที่กำหนด

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
// any entities updates
cadImage.Save(MyDir+"conic.dxf");
}

การส่งออก DXF ไปยัง WMF

วิธีการนี้ทำงานดังนี้:

  1. โหลดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอ็อบเจ็กต์ของคลาส CadRasterizationOptions และโหลดไฟล์ PDF
  3. ตั้งค่าอสมการ PageHeight & PageWidth
  4. เรียก Image.Save และบันทึกไฟล์
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (var image = Image.Load("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn"))
{
var vectorOptions = new CadRasterizationOptions();
vectorOptions.AutomaticLayoutsScaling = true;
vectorOptions.BackgroundColor = Color.Black;
vectorOptions.PageWidth = 500;
vectorOptions.PageHeight = 500;
WmfOptions wmfOptions = new WmfOptions()
{
VectorRasterizationOptions = vectorOptions
};
image.Save("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn.wmf", wmfOptions);
}

การส่งออกเลย์เอาต์เฉพาะ DXF ไปยัง PDF

วิธีการนี้ทำงานดังนี้:

  1. เปิดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอินสแตนซ์ของ CadRasterizationOptions และระบุอสมการ PageWidth & PageHeight
  3. ระบุชื่อเลย์เอาต์ที่ต้องการโดยใช้อสมการ CadRasterizationOptions.Layouts
  4. สร้างอินสแตนซ์ของ PdfOptions & ตั้งค่าอสมการ VectorRasterizationOptions
  5. ส่งออกภาพวาดไปยัง PDF โดยเรียก Image.Save และส่งอ็อบเจ็กต์ของ PdfOptions เป็นพารามิเตอร์ที่สอง

ตัวอย่างโค้ดด้านล่างแสดงวิธีการแปลงเลย์เอาต์เฉพาะของ DXF เป็น PDF

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Specify desired layout name
rasterizationOptions.Layouts = new string[] { "Model" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layout_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}

การสนับสนุนการตัดบล็อก

Aspose.CAD มีฟีเจอร์การตัดบล็อก วิธีการตัดบล็อกทำงานดังนี้:

  1. โหลดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอ็อบเจ็กต์ของคลาส CadRasterizationOptions และโหลดไฟล์ PDF
  3. ตั้งค่าสมบัติที่ต้องการของ CadRasterizationOptions
  4. เรียก Image.Save ในขณะที่ส่งอ็อบเจ็กต์ของ PdfOptions เป็นพารามิเตอร์ที่สองและบันทึกไฟล์

ตัวอย่างโค้ดด้านล่างแสดงวิธีการตัดบล็อกทำงาน

// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string inputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.dxf";
string outputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.pdf";
using (CadImage cadImage = (CadImage)Image.Load(inputFile))
{
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions
{
BackgroundColor = Aspose.CAD.Color.White,
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
PageWidth = 1200,
PageHeight = 1600,
Margins = new Margins
{
Top = 5,
Right = 30,
Bottom = 5,
Left = 30
},
Layouts = new string[] { "Model" }
};
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
cadImage.Save(outputFile, pdfOptions);

การส่งภาพไปยัง DXF

ด้วยการใช้ Aspose.CAD คุณสามารถส่งภาพไปยังรูปแบบ DXF โดยใช้วิธีการนี้คุณสามารถทำการกระทำต่อไปนี้:

  1. ตั้งฟอนต์ใหม่
  2. ซ่อนหน่วยงาน
  3. ปรับปรุงข้อความ

ตัวอย่างโค้ดด้านล่างแสดงวิธีการดำเนินการตามรายการด้านบน

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
foreach (var file in new DirectoryInfo(MyDir).EnumerateFiles("*.dxf"))
{
// ****************************
// Set new font per document
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
// Iterate over the items of CadStyleTableObject
foreach (CadStyleTableObject style in cadImage.Styles)
{
// Set font name
style.PrimaryFontName = "Broadway";
}
cadImage.Save(file.FullName + "_font.dxf");
}
// ****************************
// Hide all "straight" lines
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
foreach (var entity in cadImage.Entities)
{
// Make lines invisible
if (entity.TypeName == CadEntityTypeName.LINE)
{
entity.Visible = 0;
}
}
cadImage.Save(file.FullName + "_lines.dxf");
}
// ****************************
// Manipulations with text
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
foreach (var entity in cadImage.Entities)
{
if (entity.TypeName == CadEntityTypeName.TEXT)
{
((CadText)entity).DefaultValue = "New text here!!! :)";
break;
}
}
cadImage.Save(file.FullName + "_text.dxf");
}
}

การส่งออกเลเยอร์เฉพาะของภาพวาด DXF ไปยังภาพ

วิธีการนี้ทำงานดังนี้:

  1. เปิดไฟล์ภาพวาด DXF โดยใช้วิธีการสร้าง Image.Load
  2. สร้างอินสแตนซ์ของ CadRasterizationOptions และระบุอสมการ PageWidth และ PageHeight
  3. เพิ่มเลเยอร์ไปยังอ็อบเจ็กต์ของ CadRasterizationOptions
  4. สร้างอินสแตนซ์ของ JpegOptions และตั้งค่าอสมการ VectorRasterizationOptions
  5. ส่งออกภาพวาดไปยัง PDF โดยใช้วิธี Image.Save

ตัวอย่างโค้ดด้านล่างแสดงวิธีการแปลงเลเยอร์เฉพาะของ DXF เป็นภาพ

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "for_layers_test.dwf";
using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
// Set image width & height
rasterizationOptions.PageWidth = 500;
rasterizationOptions.PageHeight = 500;
// Set the drawing to render at the center of image
// rasterizationOptions.CenterDrawing = true;
// Get the layers in an instance of CadLayersDictionary
var layersList = image.Layers;
// Iterate over the layers
foreach (var layerName in layersList.GetLayersNames())
{
// Display layer name for tracking
Console.WriteLine("Start with " + layerName);
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.Layers = new string[] { "LayerA" };
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
var options = new Aspose.CAD.ImageOptions.JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
//Export each layer to Jpeg format
image.Save(layerName + "_out.jpg", options);
}
}