Simple SVG => PDF converter
Installation
Converter uses Google's Puppeteer library which installs headless Chrome.
For merging PDFs it also needs pdftk
installed.
Install Puppeteer on Debian/Docker's node image
On Debian (and thus also on Docker node
image, which is Debian-based) you will need to manually install the following dependencies:
#!/bin/bash apt-get updateapt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \ ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
Install pdftk on Ubuntu/Debian
sudo apt install pdftk
Install pdftk on Mac
tldr: install this version
Usage
Caution: ackee-svg-converter
uses async/await which is only supported in Node v7.6.0 or greater.
Example - convert to PDF
const svgConvert = ; const source = "<svg>....";const result = svgConvert;
Example - convert to png
const svgConvert = ; const source = "<svg>....";const result = svgConvert;
API Documentation
ackeeSvgConverter.toPdf(svg, options)
svg
SVG markup to be convertedoptions
Options object which might have the following properties:width
width of the output image. If no value is specified it is read fromsvg
element'swidth
attribute. If none is present, defaults to1280
height
height of the output image. If no value is specified it is read fromsvg
element'sheight
attribute. If none is present, defaults to720
watermark
text to be used as a diagonal watermark overlaying the SVG image. If none, no watermark is addedcustomCss
custom CSS to be used on the generated pagetransparentBackground
if set totrue
, background will be transparent. Defaults tofalse
- returns: <Promise> Promise which resolves to the output PDF
Converts SVG source to PDF data.
ackeeSvgConverter.toPdfMultiple(svg, options)
svg
<Array> List of SVG markups to be convertedoptions
Options object same as intoPdf
- returns: <Promise> Promise which resolves to the output PDF
Converts list of SVG sources to PDF data and merges them to one PDF.
ackeeSvgConverter.mergePdfs(pdfs)
pdfs
<Array> List of PDF buffers to be merged- returns: <Promise> Promise which resolves to the output PDF
Converts list of SVG sources to PDF data and merges them to one PDF.
ackeeSvgConverter.toPng(svg, options)
svg
SVG markup to be convertedoptions
Options object same as intoPdf
- returns: <Promise> Promise which resolves to the output PNG image
Converts SVG source to PNG image