0.4.2 • Published 6 years ago
ackee-svg-converter v0.4.2
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 update
apt-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 wgetInstall 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 = require('ackee-svg-converter');
const source = "<svg>....";
const result = svgConvert.toPdf(svg, { width: 800, height: 600 });Example - convert to png
const svgConvert = require('ackee-svg-converter');
const source = "<svg>....";
const result = svgConvert.toPng(svg, { width: 800, height: 600 });API Documentation
ackeeSvgConverter.toPdf(svg, options)
svgSVG markup to be convertedoptionsOptions object which might have the following properties:widthwidth of the output image. If no value is specified it is read fromsvgelement'swidthattribute. If none is present, defaults to1280heightheight of the output image. If no value is specified it is read fromsvgelement'sheightattribute. If none is present, defaults to720watermarktext to be used as a diagonal watermark overlaying the SVG image. If none, no watermark is addedcustomCsscustom CSS to be used on the generated pagetransparentBackgroundif 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 convertedoptionsOptions 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)
svgSVG markup to be convertedoptionsOptions object same as intoPdf- returns: <Promise> Promise which resolves to the output PNG image
Converts SVG source to PNG image