Convert AutoCAD Drawings to PDF using C#

AutoCAD is used by designers to create various types of designs of buildings, bridges, automobiles, chips and etc. in a wide range of industries. However, the AutoCAD formats (DWG, DXF, etc.) can only be viewed in a dedicated software or an online AutoCAD viewer. To make things easier, the AutoCAD drawings could be converted into PDF files which can be viewed anywhere without any dependency. In this article, you will learn how to convert AutoCAD DWG/DXF drawings to PDF programmatically using C#.

C# AutoCAD to PDF Converter API

Aspose.CAD for .NET is a powerful AutoCAD to PDF converter API that lets you convert DWG and DXF files to PDF format quiet easily. In addition, it allows you to convert the AutoCAD drawings to raster images. The API can be installed using the NuGet or downloaded as DLL from the Downloads section.

PM> Install-Package Aspose.CAD

Convert AutoCAD Drawing to PDF using C#

The following are the steps to convert an AutoCAD DWG/DXF file to PDF format using Aspose.CAD for .NET API.

The following code sample shows how to convert AutoCAD DWG to PDF using C#.

Set Canvas Size in AutoCAD to PDF using C#

Aspose.CAD for .NET also allows you to specify the size of the pages (height and width) in the converted PDF document. The following are the steps to customize page size in AutoCAD to PDF conversion.

The following code sample shows how to convert AutoCAD DXF to PDF using C#.

Perform Auto Scaling in AutoCAD to PDF in C#

AutoCAD drawing may consist of multiple layers where each layer might have a different dimension. In various scenarios, you may want to have a unified scaling in the converted PDF file. For such cases, you can configure the API to auto-scale the layers in accordance with the page size in the PDF document. The following are the steps to perform auto-scaling in AutoCAD to PDF conversion.

The following code sample shows how to convert AutoCAD drawing to PDF with auto-scaling using C#.

Modify Background and Drawing Color in PDF using C#

Aspose.CAD for .NET also lets you modify the default color scheme of the AutoCAD drawings in the converted PDF document. The following are the steps to specify the background and drawing colors.

The following code sample shows how to convert AutoCAD drawing to PDF with customized background and drawing colors.

Convert Specific Layers of AutoCAD Drawing to PDF using C#

In case there are multiple layers in the AutoCAD drawing, you can specify the layers you want to have in the converted PDF document. For this, you can provide the list of the layers’ names to the API using CadRasterizationOptions.Layers property. The following code sample shows how to convert a specific layer of the AutoCAD drawing to PDF using C#.

Conclusion

In this article, you have seen how to convert AutoCAD DWG or DXF drawing to PDF using C#. Furthermore, you have learned how to customize the AutoCAD to PDF conversion in various scenarios using Aspose.CAD for .NET API. You can explore more about the API using the documentation.

See Also