Introduction
You can easily convert PDF files to SVG with Python using the BuildVu microservice. With this tutorial you will be able to use the BuildVu cloud API, which could be either:
- The IDRsolutions trial and cloud-based subscription service
- Or using your own self-hosted BuildVu microservice
Although these services can be accessed using standard HTTP requests, this tutorial uses our open-source Python IDRCloudClient, which offers a straightforward Python wrapper for the REST API.
Why SVGs are better for Python
SVGs can be directly rendered in web frameworks like Flask or Django, allowing seamless integration with frontend technologies and interactive dashboards.
Since SVGs are text-based XML, they are simple to manipulate programmatically with Python scripts, while PDFs require more complex parsing and offer less flexibility for dynamic or interactive web content.
Prerequisites
You can install the IDRCloudClient package via pip by running the following command:
pip install IDRCloudClient
Code Example
Below is a simple code example for converting PDF files to SVG. Details on configuration options and advanced features are provided afterward.
from IDRSolutions import IDRCloudClient
client = IDRCloudClient(‘https://cloud.idrsolutions.com/cloud/’ + IDRCloudClient.BUILDVU)
try:
result = client.convert(
# token=’Token’, # Required only when connecting to the IDRsolutions trial and cloud subscription service
input=IDRCloudClient.UPLOAD,
file=’/path/to/exampleFile.pdf’
)
outputURL = result[‘downloadUrl’]
client.downloadResult(result, ‘path/to/output/dir’)
if outputURL is not None:
print("Download URL: " + outputURL)
except Exception as error:
print(error)
Return result to a callback URL
The BuildVu Microservice allows you to specify a callback URL to receive the conversion status after processing is finished. This approach eliminates the need to keep polling the service to check for completion. Simply include the callback URL in the parameters when calling the convert method, as shown in the following example.
result = client.convert(
# token=’Token’, # Required only when connecting to the IDRsolutions trial and cloud subscription service
input=IDRCloudClient.UPLOAD,
callbackUrl=’http://listener.url’,
file=’/path/to/exampleFile.pdf’
)
Configuration Options
The BuildVu API accepts a stringified JSON object containing key value pair configuration options to customise your conversion. The settings should be provided to the convert method. A full list of the configuration options to convert PDF files to HTML or SVG can be found here.
settings='{"key":"value","key":"value"}’
Upload by URL
In addition to uploading a local file, you can specify a URL for the BuildVu Microservice to fetch and convert. To do this, update the input and file parameters in the convert method as shown below.
input=IDRCloudClient.DOWNLOAD
url=’http://exampleURL/exampleFile.pdf’
Using Authentication
If you have set up your own BuildVu Microservice and it requires authentication for PDF to HTML or SVG conversions, you must supply your username and password with every request. This is done by passing an auth variable to the convert method, as shown below.
auth=(‘username’, ‘password’))
BuildVu allows you to
| View PDF files in a Web app |
| Convert PDF documents to HTML5 |
| Parse PDF documents as HTML |
What is BuildVu?
BuildVu is a commercial SDK for converting PDF files into standalone HTML or SVG.
Why use BuildVu?
BuildVu allows you to integrate PDF into your HTML workflow effortlessly and securely by producing clean HTML that is easy for developers to work with.
What licenses are available?
We have 3 licenses available:
Cloud for conversion using the shared IDRsolutions cloud server, Self hosted server option for your own cloud or on-premise servers, and Enterprise for more demanding requirements.
How to use BuildVu?
Want to learn more about BuildVu and how to use it, we have plenty of tutorials and guides to help you.