Exporting DGN AutoCAD
Exporting DGN AutoCAD Format To PDF
Aspose.CAD for .NET API has introduced the functionality to load a DGN AutoCAD file and convert it to PDF format. CadImage class serves the purpose.
You need to load an existing DGN file as CadImage. Create an instance of the CadRasterizationOptions class and set different properties. Create an instance of PdfOptions class and pass the CadRasterizationOptions instance. Now call the Save method of CadImage class instance.
Sample Code
Following is the code demonstration to convert/export DGN to PDF format.
// 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); | |
} |
Exporting DGN AutoCAD Format To Raster Image Format
Aspose.CAD for .NET API has introduced the functionality to load a DGN AutoCAD file and convert it to a raster image. CadImage class serves the purpose.
You need to load an existing DGN file as CadImage. Create an instance of the CadRasterizationOptions class and set different properties. Create an instance of JpegOptions class and pass the CadRasterizationOptions instance. Now call the Save method of CadImage class instance.
Sample Code
Following is the code demonstration to convert/export DGN to JPEG image.
// 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); | |
} |
3D entities support for DGN v7
Aspose.CAD for .NET API has introduced the functionality to load a DGN AutoCAD file and support 3D entities for DGN v7. CadImage class serves the purpose. Each DGN image supports 9 predefined views. It’s enumerated from 1 to 9. If view not defined on export, for multi-paged output formats (like PDF) all views will be exported, each on a separate page. 3D entities supported on DGN file format, as well as 2D. For this, VectorRasterizationOptions is used, TypeOfEntities is not used anymore for DGN format (both 2D and 3D supported simultaneously).
Sample Code
The following is the sample code to look at supported DGN elements.
// 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); | |
} |