SVG to PDF

The svg-to-pdf call converts a SVG file to PDF using Inkscape.

Server setup

To convert SVG files to PDF, you need to install Inkscape on your server:

sudo apt install inkscape

Account configuration

To use the PDF call, the account must have the svg-to-pdf flag set to true:

{"key": "...", "svg-to-pdf": true, "...": null}

JavaScript

Using Backend.js, a SVG file can be converted to PDF as follows:

const backend = new Backend('https://viereck.ch/backend');
const account = backend.account('your-account-id', '44705748... your-account-key');

const svgToken = 'd94d3886...';
const resources = [
	{name: 'logo.png', '#b': '7b8cf18d...'},
	...
	];
account.svgToPdf(svgToken, resources, onDone, onError);

function onDone(token, request) {
	...
}

function onError(errorCode, request) {
	...
}
		

All SVG files and resources must be uploaded beforehand, if necessary.

HTTP/REST Requests

Request
POST /backend/svg-to-pdf
Account: ACCOUNT ID
Timestamp: TIMESTAMP
Signature: SIGNATURE
{"#b": randomHex(32), "resources": [{"#b": "...", "name": "..."}, "..."]}
Response

200 with the blob token of the generated PDF

400 if a file is missing

401 if the account ID or signature is missing or invalid

403 if the account is not allowed to use SVG to PDF

Account ID
Account key
Request

A simple request has the following structure:

{"#b": randomHex(32)}

The token refers to a previously uploaded SVG blob. The file is passed to inkscape, and the resulting PDF file is again stored as a blob.

If the source file refers to external resources, these resources must be uploaded as blobs as well, and specified in the request:

{"#b": randomHex(32), "resources": [{"#b": randomHex(8) + "…", "name": "background.jpeg"}, {"#b": randomHex(8) + "…", "name": "logo.png"}, "..."]}

All resources are staged in a folder alongside the SVG file before calling inkscape.