导出DGN AutoCAD

将DGN AutoCAD格式导出为PDF

Aspose.CAD for .NET API引入了加载DGN AutoCAD文件并将其转换为PDF格式的功能。CadImage类用于此目的。

您需要将现有DGN文件加载为CadImage。创建CadRasterizationOptions类的实例并设置不同的属性。创建PdfOptions类的实例,并传递CadRasterizationOptions实例。现在调用CadImage类实例的Save方法。

示例代码

以下是将DGN转换/导出为PDF格式的代码演示。

// 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);
}

将DGN AutoCAD格式导出为光栅图像格式

Aspose.CAD for .NET API引入了加载DGN AutoCAD文件并将其转换为光栅图像的功能。CadImage类用于此目的。

您需要将现有DGN文件加载为CadImage。创建CadRasterizationOptions类的实例并设置不同的属性。创建JpegOptions类的实例,并传递CadRasterizationOptions实例。现在调用CadImage类实例的Save方法。

示例代码

以下是将DGN转换/导出为JPEG图像的代码演示。

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an object of DgnRasterizationOptions class and define/set different properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 600;
rasterizationOptions.PageHeight = 300;
rasterizationOptions.NoScaling = true;
rasterizationOptions.AutomaticLayoutsScaling = false;
// Create an object of JpegOptions class as we are converting the DGN to jpeg and assign DgnRasterizationOptions object to it.
Aspose.CAD.ImageOptionsBase options = new Aspose.CAD.ImageOptions.JpegOptions();
options.VectorRasterizationOptions = rasterizationOptions;
// Call the save method of the CadImage class object.
cadImage.Save(MyDir + "ExportDGNToRasterImage_out.pdf", options);
}

DGN v7的3D实体支持

Aspose.CAD for .NET API引入了加载DGN AutoCAD文件并支持DGN v7的3D实体的功能。CadImage类用于此目的。每个DGN图像支持9个预定义视图。它的编号从1到9。如果导出时未定义视图,对于多页面输出格式(如PDF),将导出所有视图,每个视图在单独的页面上。DGN文件格式支持3D实体,以及2D。为此,使用VectorRasterizationOptions,不再使用TypeOfEntities用于DGN格式(同时支持2D和3D)。

示例代码

以下是查看支持的DGN元素的示例代码。

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
string outFile = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (DgnImage dgnImage = (DgnImage)Image.Load(sourceFilePath))
{
var options = new PdfOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = 1500,
PageHeight = 1500,
AutomaticLayoutsScaling = true,
BackgroundColor = Color.Black,
Layouts = new string[] { "1", "2", "3", "9" }//only export 4 (1,2,3 and 9) views
}
};
dgnImage.Save(outFile, options);
}