Unlock the Power of Direct PDF Editing with WebViewer 10.7

Streamlining Your Workflow: Converting CAD Files to PDFs with the Apryse SDK

By Apryse | 2023 Oct 04

Sanity Image
Read time

7 min

Introduction

Computer-Aided Design (CAD) files are essential for creating and visualizing complex designs, whether they're architectural plans, mechanical schematics, or artistic creations. While CAD software is the ideal tool for creating and editing these files, sharing them with clients, team members, or stakeholders who might not have the same software, or the specialized skills to use the software, can be a hurdle.

Blog image

Figure 1 - Part of an AutoCAD file - shown within the specialized, and complex AutoCAD Web tool.

CAD files, often in formats like DWG, DXF, or RVT, are industry-standard formats for creating and editing technical designs. While CAD software excels at design and editing tasks, sharing CAD files as-is can be impractical due to the files often being too large to share via email or web platforms, and the requirement of dedicated software and specific skills to interpret them. 

Converting CAD files to PDF addresses these challenges effectively. PDF is a universally supported format that maintains the visual integrity of CAD designs while making them accessible to anyone with a PDF viewer. This simplifies collaboration, file sharing, and ensures that intricate details and precise measurements are accurately represented.

This is where Apryse SDK ability to convert CAD files into PDFs becomes invaluable.

In this article we will walk through the CAD To PDF sample and see how easy it is to perform this task with minimal code. We will also look at some of the features of the generated PDF when viewed within the Apryse WebViewer. This includes the ability to enable or disable layers, measure items within the drawing, and to zoom into very intricate parts of the drawing to a level of detail that is not available in other viewers.

CAD Conversion Made Simple with Apryse SDK

The Apryse SDK is well known for its ability to convert to and from Office documents but its abilities are much broader. Designed with developers and businesses in mind, the Apryse SDK also offers a comprehensive solution for integrating CAD-to-PDF conversion directly into your applications or workflows.

Key Features:

  • Wide Range of Supported Formats: The Apryse SDK supports a diverse range of CAD formats, including DWG, DXF, RVT and more. This flexibility ensures that your conversion needs are met, regardless of the software used to create the original design.
  • High-Quality PDF Output: The SDK maintains the quality of the original CAD design during the conversion process. This is vital for ensuring that intricate details, precise measurements, and design elements are accurately represented in the PDF output.
  • Effortless Integration: With a developer-friendly interface and clear documentation, integrating the Apryse SDK into your existing applications or workflows is a straightforward process. This means you can seamlessly automate CAD-to-PDF conversions, saving valuable time and resources.
  • Customization Options: The Apryse SDK offers customizable settings, allowing you to tailor the conversion process to your specific requirements. Adjusting page layouts, scaling, and other parameters ensures that the PDF output aligns with your preferences.
  • Scalability and Performance: Whether you're working on a single conversion or batch processing multiple files, the Apryse SDK is built to handle the workload efficiently, ensuring optimal performance even with large and complex CAD files.

Trying the Sample Code

The CAD2PDF sample code that we will be using can either be downloaded from here, or alternatively, the Apryse SDK is shipped with samples that demonstrate a wide range of functionality including CADtoPDF conversion. In either case, however, an add-on module is required, and we will show how to download and install that.

Before we can use the sample, however, we will need to get a Trial license key.

Getting an Apryse SDK Trial Key

If you don't already have an Apryse account, go to https://dev.apryse.com and register a new account. This allows Apryse to grant you a demo license key which will be used with the Apryse SDK to enable demo functionality.

Blog image

Figure 2 - The page for signing up to Apryse to get a Trial key

Log into https://dev.apryse.com with your registered account. The Apryse SDK and the CADToPDF module are available for Windows, Linux and macOS, so select the platform that you are using.

Click on the Reveal button to get your personalized Trial key.

Blog image

Figure 3 - The location for getting your Trial key.

On Windows the SDK is available via NuGet by using dotnet add package PDFTron.NET.x64

It is also available from the download page for Windows or Linux, and that is how we will download it in this sample.

Scroll down to Step4: Get Started and click on the .Net Core SDK (or indeed any other version that you prefer). This will take you to a second page from where you can download either the 32 or 64-bit SDK. The Linux version supports 32 and 64-bit,plus 64-bit ARM.

Blog image

Figure 4 - The Apryse SDK download page. in this case for .Net Core on Windows.

This will download the SDK as a zip (or tarball) file onto your machine.

Extract the SDK into a folder.

Blog image

Figure 5 - the contents of the SDK when extracted on a Windows machine

The SDK contains samples for C#, C++ and Java, and is suitable for all three languages. In this article I will be using C#, but the ideas are the same for the other languages.

Note that the SDK does not include the CADToPDFModule which must be downloaded separately, which we will do next.

Downloading the CADToPDFModule

At the bottom of the download page within the Get Started section you will find an option for Modules

Blog image

Figure 6 - The webpage that allows the CAD module to be downloaded.

Click on Download and wait for the file which again, is a zip (or a tarball) file.

Extract the file over the folder that contains the SDK which you have previously extracted.

If you look inside the folder there should now be a file called CAD_README.md

Blog image

Figure 7 - the Contents of the Apryse SDK folder after the addition of the CAD module.

A folder will also have been added to the Samples/TestFiles. This contains the CAD file used by the example code. If this folder is missing, then something has gone wrong with downloading, and extracting, the SDK and Module. This needs to be solved before continuing.

Blog image

Figure 8 - The contents of the TestFiles folder. If this is missing then the CAD Module installation is not complete.

Using the Sample Code

VSCode is an excellent option for looking at these files due to its efficient file viewing with syntax highlighting and git integration, however you can use whatever IDE you prefer.

Copy the license code that you have previously acquired into the PDFTronLicense class.

Blog image

Figure 9 - The PDFTronLicense class indicating where your license key should be pasted.

Next, let’s look at the file that will do the work – CAD2PDFTest.cs.

Blog image

Figure 10 - A view of the code used to set up the file for conversion.

You can see that the code has hard-coded file names. This is just to simplify setting up the project, so feel free to try it out with different files.

You can run the sample, which converts a specific CAD file to PDF, by navigating to navigate to the folder \PDFNetC64\Samples\CAD2PDFTest\CS then using RunTest.bat from a command prompt.

(Note that if you use a PowerShell terminal then you will need to use .\RunTest.bat, and if you use the Run command within VSCode then the working folder will be different, and you will need to change the relative paths accordingly.)

Blog image

Figure 11 - Typical output of the RunTest.bat file.

Once the processing has completed, there will be a new file in the folder TestFiles\Output

Blog image

Figure 12 - The Samples output folder after running the conversion.

This file can then be viewed in any PDF viewer, and shared with whoever needs to see it.

Blog image

Figure 13 - An overview of the generated PDF.

Blog image

Figure 14 - Detail of part of the PDF, zoomed into 19325%.

The behavior of the viewer is intuitive – it is exactly the same as you would use for any other PDF, so it is easy to zoom into any part of the file.

How Did the Code Work?

For a *.dwg file, the code is extremely simple – a PDFDoc object is created then saved:

  using (PDFDoc pdfdoc = new PDFDoc()){ 

      pdftron.PDF.Convert.FromCAD(pdfdoc, input_path + input_file_name, null); 
      pdfdoc.Save(output_path + output_file_name, SDFDoc.SaveOptions.e_remove_unused); 
} 

What is even better is that the code needed to do this is very similar to the code used to convert to and from Office, Image files etc. so that having learned to use the SDK, many other options are also, and easily, available.

Note: Revit files *.rvt, need a few more lines of code that set the page width and height and the RasterDPI. How to do this is included in the sample code, but the functionality is currently only available for Windows.

Want More Information?

You can find more information on this package at

Conclusion

In a world that demands efficient collaboration and seamless sharing, the Apryse SDK emerges as a game-changer. By enabling hassle-free CAD-to-PDF conversion, it empowers businesses, developers, and designers to focus on their core tasks without worrying about compatibility issues.

Whether you're an architect presenting plans to clients, an engineer sharing mechanical schematics, or an artist showcasing intricate designs, the Apryse SDK ensures that your creativity and innovation are never hindered by technical barriers. Embrace the power of streamlined CAD-to-PDF conversion and elevate your collaborative efforts to new heights.

In addition to converting CAD documents to PDF, Apryse offers many tools for editing and handling both Office Documents and PDFs, including converting PDFs into Office documents.

When you are ready to get started, see the documentation for the SDK to get started quickly. Don’t forget, you can also reach out to us on Discord if you have any issues.

Sanity Image

Apryse

Share this post

email
linkedIn
twitter