0.4.2 • Published 5 years ago

ackee-svg-converter v0.4.2

Weekly downloads
8
License
ISC
Repository
gitlab
Last release
5 years ago

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

0.4.3-beta

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.11

5 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago