This short guide explains how to convert DWG file to PDF using Python REST API. You will exercise the conversion of a DWG file to PDF using Python REST Interface with the help of a Python-based Cloud SDK. A detailed set of instructions, IDE settings, and a sample code is available to understand the complete process.
Prerequisite
- Create an account and get API credentials for changing a DWG file to PDF
- Download Aspose.Cad Cloud SDK for Python to transform DWG to PDF
- Set up a Python project with the above SDK
Steps to Convert DWG to PDF using Python Low Code API
- Instantiate CadApi with your Client ID, Client Secret, and base URL, and keep the instance for making cloud calls
- Set inputPath to the DWG you want to convert and outputPath to where the resulting PDF will be saved
- Read the input file from disk so you can work with its bytes
- Copy the file into a MemoryStream and rewind it to the beginning so it’s ready to send
- Wrap the in-memory stream in a PutDrawingPdfRequest to specify that you want a PDF rendition
- Call PutDrawingPdf on your CadApi instance to perform the server-side conversion and receive the resulting PDF as a stream
- Open or create the file at outputPath to hold the converted PDF
- 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 Python 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 Python REST API
The above code demonstrates the process to transform DWG to PDF using Python 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 Python REST API.