ackee-svg-converter

0.4.2 • Public • Published

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 wget

Install pdftk on Ubuntu/Debian

sudo apt install pdftk

Install pdftk on Mac

link here

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)

  • svg SVG markup to be converted
  • options Options object which might have the following properties:
    • width width of the output image. If no value is specified it is read from svg element's width attribute. If none is present, defaults to 1280
    • height height of the output image. If no value is specified it is read from svg element's height attribute. If none is present, defaults to 720
    • watermark text to be used as a diagonal watermark overlaying the SVG image. If none, no watermark is added
    • customCss custom CSS to be used on the generated page
    • transparentBackground if set to true, background will be transparent. Defaults to false
  • 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 converted
  • options Options object same as in toPdf
  • 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 converted
  • options Options object same as in toPdf
  • returns: <Promise> Promise which resolves to the output PNG image

Converts SVG source to PNG image

Readme

Keywords

none

Package Sidebar

Install

npm i ackee-svg-converter

Weekly Downloads

11

Version

0.4.2

License

ISC

Unpacked Size

13.2 kB

Total Files

7

Last publish

Collaborators

  • pivl
  • hofp37
  • grissius
  • ackeecz
  • horaklukas
  • borecekbaji
  • davidbilik