Convert DWG File to PDF using Java REST API

This short guide explains how to convert DWG file to PDF using Java REST API. You will exercise the conversion of a DWG file to PDF using Java REST Interface with the help of a Java-based Cloud SDK. A detailed set of instructions, IDE settings, and a sample code is available to understand the complete process.

Prerequisite

Steps to Convert DWG to PDF using Java Low Code API

  1. Instantiate CadApi with your Client ID, Client Secret, and base URL, and keep the instance for making cloud calls
  2. Set inputPath to the DWG you want to convert and outputPath to where the resulting PDF will be saved
  3. Read the input file from disk so you can work with its bytes
  4. Copy the file into a MemoryStream and rewind it to the beginning so it’s ready to send
  5. Wrap the in-memory stream in a PutDrawingPdfRequest to specify that you want a PDF rendition
  6. Call PutDrawingPdf on your CadApi instance to perform the server-side conversion and receive the resulting PDF as a stream
  7. Open or create the file at outputPath to hold the converted PDF
  8. Copy the bytes from the result stream into the output file on disk

These steps summarize the process to convert a DWG file to PDF using Java REST Interface. Instantiate CadApi using your Client ID, Client Secret, and base URL, then prepare a PutDrawingPdfRequest with your DWG file stream. Finally, call PutDrawingPdf on the CadApi instance to convert the drawing to PDF and save the resulting file locally.

Code to Change DWG to PDF using Java REST API

The above code demonstrates the process to transform DWG to PDF using Java Low Code API. You may send the drawing bytes and export options in the body (multipart/form-data + JSON). Use it to control page size, DPI, background, scaling, etc., instead of taking server defaults.

This tutorial has guided us to convert a DWG file to PDF. To transform a DW file to PNG, refer to the article on Convert DWG to PNG using Java REST API.

 English