Convert PDF to SVG with Python REST API

This short guide explains how to convert PDF to SVG with Python REST API. You will learn to transform the file format from PDF to SVG with Python REST Interface using a Cloud-based SDK. An explanation will be provided to download the resultant file and view the result from the local disk.

Prerequisite

Steps to Export PDF to SVG with Python Low Code API

  1. Initialize the PdfApi object using the ApiClient with your Client ID and secret
  2. Using the PdfApi object, call the upload_file() method to upload the source PDF file into the Cloud storage
  3. Print the upload API response that contains a list of errors and uploaded information
  4. Call the put_pdf_in_storage_to_svg() to transform PDF to SVG
  5. If the conversion status is OK, call the download_file() method to download the zipped file
  6. Get the local system path where API has downloaded the zipped file and unzip it to view the result

The above steps describe the PDF to SVG conversion with Python RESTful Service. Create the ApiClient object with client ID and secret, upload the source PDF file to the Cloud storage, call the put_pdf_in_storage_to_svg() method to change the PDF in the Cloud Storage to SVG, and use the download_file() method to download the resultant SVG file. Unzip the ZIP file and observe the resultant SVG files.

Code to Change PDF to SVG with Python-based API

import asposepdfcloud
from asposepdfcloud import PdfApi
from asposepdfcloud.rest import ApiException
api_client = asposepdfcloud.ApiClient("Client ID", "Secret")
pdfApi = PdfApi(api_client)
file_name = "Sample.pdf"
try:
upload_response = pdfApi.upload_file(file_name ,file_name)
print("Upload Response:")
print(upload_response)
conversion_response = pdfApi.put_pdf_in_storage_to_svg(file_name, "output.zip")
print("Conversion Response:")
print(conversion_response)
if conversion_response.status == "OK":
download_response = pdfApi.download_file("output.zip")
print("Download Response:")
print(download_response)
except ApiException as ex:
print("Exception Details:")
print (ex)

This code has converted the file format from PDF to SVG with Python Low Code API. The output file is saved in the Cloud storage as a ZIP file, and the same is downloaded on the local disk. If the PDF file is larger and contains multiple pages, each page is converted to a separate SVG file and all the SVG files are added to the resultant ZIP file.

This guide has taught us the process of changing the PDF file to SVG. To create an empty PDF file, refer to the article on Create PDF in Python using REST API.

 English