CAD 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 CAD formats (DWG, DXF, etc.) can only be viewed in a dedicated software or an online CAD viewer. To make things easier, the DWG/DXF files could be converted into PDF files which can be viewed anywhere without any dependency. In this article, you will learn how to convert CAD’s DWG or DXF files to PDF using C#.
- C# CAD to PDF Converter API
- Convert DWG/DXF to PDF using C#
- Set Canvas Size in DWG/DXF to PDF using C#
- Perform Auto Scaling in CAD to PDF in C#
- Modify Background and Drawing Color in PDF using C#
- Convert Specific Layers of CAD to PDF using C#
C# CAD to PDF Converter – Free Download
Aspose.CAD for .NET is a powerful CAD 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 CAD 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
DWG or DXF to PDF C# Conversion
The following are the steps to convert a DWG/DXF file to PDF format using Aspose.CAD for .NET API.
- Load the AutoCAD DWG/DXF file using the Image class.
- Create an object of PdfOptions class.
- Save AutoCAD drawing as PDF using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert DWG to PDF using C#.
C# DWG/DXF to PDF – Set Canvas Size
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 CAD to PDF conversion.
- Load the AutoCAD DWG/DXF file using the Image class.
- Create an instance of CadRasterizationOptions class.
- Set CadRasterizationOptions.PageWidth and CadRasterizationOptions.PageHeight properties.
- Create an object of PdfOptions class.
- Set PdfOptions.VectorRasterizationOptions property with CadRasterizationOptions object.
- Convert DWG or DXF to PDF using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert DXF to PDF using C#.
C# CAD to PDF – Auto Scaling
The CAD 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.
- Load the DWG/DXF file using the Image class.
- Create an instance of CadRasterizationOptions class.
- Set CadRasterizationOptions.AutomaticLayoutsScaling to true.
- Create an object of PdfOptions class and initialize PdfOptions.VectorRasterizationOptions property with CadRasterizationOptions object.
- Convert CAD drawing to PDF using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert CAD drawing to PDF with auto-scaling using C#.
Modify Background and Drawing Color in Converted PDF
Aspose.CAD for .NET also lets you modify the default color scheme of the CAD drawings in the converted PDF document. The following are the steps to specify the background and drawing colors.
- Load the DWG/DXF file using the Image class.
- Create an instance of CadRasterizationOptions class.
- Set background color using CadRasterizationOptions.BackgroundColor property.
- Set drawing color using CadRasterizationOptions.DrawColor property.
- Create an object of PdfOptions class and initialize PdfOptions.VectorRasterizationOptions property with CadRasterizationOptions object.
- Convert DWG/DXF to PDF using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert DWG/DXF drawing to PDF with customized background and drawing colors.
Convert Specific Layers of CAD 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 CAD’s DWG or DXF files to PDF using C#. Furthermore, you have learned how to customize the CAD to PDF conversion in various scenarios using Aspose.CAD for .NET API. You can explore more about the API using the documentation.