Convert DGN to PDF in C#

DGN files are 2D or 3D drawing files that are created and supported by CAD applications. DGN file is used to create and save designs for construction projects such as highways, bridges, and buildings. In certain cases, we may need to export drawings from DGN files to PDF documents programmatically. In this article, we will learn how to convert a DGN file to a PDF in C#.

The following topics shall be covered in this article:

  1. C# DGN to PDF Converter – Free Download
  2. Steps to Convert DGN File to PDF Document
  3. Convert DGN to PDF Programmatically
  4. Export DGN to PDF with Options

C# DGN to PDF Converter – Free Download

To convert a DGN file to a PDF document, we will be using the Aspose.CAD for .NET API. It allows creating, editing, and manipulating DGN files and several other file formats.

The Image class of the API is the base class for all types of drawings. The DgnImage class represents a DGN image. We can set PageWidth and PageHeight properties using the CadRasterizationOptions class. The PdfOptions class of the API allows specifying the PDF options.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.CAD

How to Convert DGN File to PDF using C#

We can easily convert a DGN file to a PDF document using Aspose.CAD for .NET by following the steps given below:

  • Load a DGN drawing file.
  • Save DGN as PDF.

Now, let’s see how to perform these steps in C# to convert a DGN file to a PDF document.

Convert DGN to PDF Programmatically in C#

Please follow the steps given below to convert a DGN to a PDF:

  1. Firstly, load an input DGN file using the Image class.
  2. After that, create an instance of the PdfOptions class.
  3. Finally, call Save() method to save it as a PDF. It takes the output PDF file path and PdfOptions as arguments.

The following code sample shows how to convert a DGN file to a PDF document using C#.

Export DGN to PDF with Options in C#

We can specify PDF save options while converting a DGN file to a PDF document by following the steps given below:

  1. Firstly, load an input DGN file using the Image class.
  2. Next, create an instance of the CadRasterizationOptions class.
  3. Then, specify the page height and width.
  4. Next, create an instance of the PdfOptions class.
  5. After that, set the VectorRasterizationOptions property as CadRasterizationOptions.
  6. Finally, call Save() method to save it as a PDF. It takes the output PDF file path and PdfOptions as arguments.

The following code sample shows how to specify the page height and width while saving a DGN file as a PDF document using C#.

Get Free Temporary License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • load an existing DGN drawing file;
  • specify page height and width;
  • define save options;
  • save DGN as a PDF in C#.

Besides converting a DGN to a PDF in C#, you can learn more about Aspose.CAD for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also