Client/server side PDF printing in pure JavaScript

Related tags

Files pdfmake
Overview

pdfmake Node.js CI GitHub npm Bower Packagist CDNJS

PDF document generation library for server-side and client-side in pure JavaScript.

Check out the playground and examples.

This is unstable master branch for version 0.2.x, for stable version 0.1.x see branch 0.1.

Features

  • line-wrapping,
  • text-alignments (left, right, centered, justified),
  • numbered and bulleted lists,
  • tables and columns
    • auto/fixed/star-sized widths,
    • col-spans and row-spans,
    • headers automatically repeated in case of a page-break,
  • images and vector graphics,
  • convenient styling and style inheritance,
  • page headers and footers:
    • static or dynamic content,
    • access to current page number and page count,
  • background-layer,
  • page dimensions and orientations,
  • margins,
  • custom page breaks,
  • font embedding,
  • support for complex, multi-level (nested) structures,
  • table of contents,
  • helper methods for opening/printing/downloading the generated PDF,
  • setting of PDF metadata (e.g. author, subject).

Documentation

Documentation URL: https://pdfmake.github.io/docs/

Building from sources

using npm:

git clone https://github.com/bpampuch/pdfmake.git
cd pdfmake
npm install
npm run build

using yarn:

git clone https://github.com/bpampuch/pdfmake.git
cd pdfmake
yarn
yarn run build

License

MIT

Authors

pdfmake is based on a truly amazing library pdfkit (credits to @devongovett).

Thanks to all contributors.

Comments
  • 2x text -> 40x slowdown!

    2x text -> 40x slowdown!

    So this is odd -- I've got a project where I'm generating text PDFs, nothing too fancy. I've hit some sort of threshold, though -- I went from making a ~20-page document to making a ~40-page document, and the PDF-generating time spiked from ~3 seconds to ~2 minutes.

    I've got a repository up (with obfuscated text files, whee NDAs) here. You can click to generate the "slow" or "fast" documents, with basic instrumenting telling you how long each one takes.

    Have I hit some sort of known performance landmine here? Does pdfMake just take a lot longer once you get above a particular input-object size? Either way, is there a way to optimize around this?

    performance 
    opened by hujhax 66
  • Support SVG nodes

    Support SVG nodes

    It works similar to images except you cannot use the images library or file paths.

    Example usage:

    content: [
        {
            svg: '<svg viewBox="0 0 500 500"><circle cx="250" cy="250" r="100" stroke="black" stroke-width="3" fill="red" /></svg>',
            width: 100
        },
        {
            svg: '<svg viewBox="0 0 500 500"><circle cx="250" cy="250" r="100" stroke="black" stroke-width="3" fill="red" /></svg>',
            fit: [500, 250]
        }
    ]
    

    It uses SVGtoPDFKit under the hood and it should be possible to pass options to it in the document definition (untested though as I did not need it)

        {
            svg: '<svg>...</svg>',
            options: { ... SVGtoPDFKit options ... }
        }
    

    See https://github.com/alafr/SVG-to-PDFKit#parameters for available options

    opened by cyrixmorten 54
  • Use custom font (via vfs_fonts.js)

    Use custom font (via vfs_fonts.js)

    It seems that the vfs_fonts.js file contains the binary font data of the Roboto font but somehow encoded (data URI / base64 ?). could you explain how to generate the required JS file for other fonts (and: is the LICENSE.txt required ?)

    btw: great work - thanks, seems quite promising !

    kind regards, matthias

    question answered 
    opened by matthias-001 46
  • Uncaught File 'Roboto-Medium.ttf' not found in virtual file system

    Uncaught File 'Roboto-Medium.ttf' not found in virtual file system

    Hi, i'm having an issue with pdfmake. I import pdfmake.min.js and vfs_fonts.js but i can't create a pdf file in my page cause it throws that error:

    Uncaught File 'Roboto-Medium.ttf' not found in virtual file system

    I dont understand how can i solve it. Please i need help with this.

    I forgot, im using windows 7

    waiting for information 
    opened by RodrigoInosh 39
  • Other languages in pdfmake

    Other languages in pdfmake

    Is it possible to add other language support other than English (UTF-8) in pdfmake library? something like,

    var dd = {
        content: [
            'ಕನ್ನಡ',              //Kannada
            'മലയാളം'       //Malayalam
        ]
    }
    
    opened by mpsbhat 34
  • How to wrap the text inside the table cell

    How to wrap the text inside the table cell

    Hello, When the cell content exceeds the column width, it is either getting truncated or the remaining content is overlapping into the next cell, How do we wrap the cell content

    feature request table 
    opened by ghost 34
  • PDF make takes 50seconds to print document with one image and 75 tables

    PDF make takes 50seconds to print document with one image and 75 tables

    Hi @bpampuch I am facing issue in generating document through PDFmake. I tried switching to new version i.e 0.1.22 but still its way slow. Can I get any resolution or answer to this issue? Thanks in advance

    performance 
    opened by Dannybrown2710 33
  • Invalid offset/length when creating typed array - pdfmake.js (24651,9) on Edge Windows 10

    Invalid offset/length when creating typed array - pdfmake.js (24651,9) on Edge Windows 10

    After constructing my array to create a pdf all is ok on others browsers but on edge I got this error, pdfMake.createPdf(dd).download('planning.pdf'); image

    opened by amnedge 30
  • "No unicode cmap for font" happened when i using client version.

    I use chinese fonts in my project. When i using server version, it work perfectly. But when i using client version, it always alert me "No unicode cmap for font". This is font i used : https://mega.co.nz/#!WddCwIjR!XVwz3BH8brUc0znBSNQ_vb_NG9iHXtW0ghlkEWz9lo8 This is vfs_fonts.js i builed : https://mega.co.nz/#!DN9DmSYD!Nd10rPBBfTZ9OFpw7MEQm5A_wrqcQhpECH0z3RLHy-k This is code i used :

            var fontDescriptors = { 
                times: {
                    normal: 'times.ttf',
                    bold: 'timesbd.ttf',
                    italics: 'timesi.ttf',
                    bolditalics: 'timesbi.ttf'
                } , 
                wqy: {
                    normal: 'wqy.ttf',
                    bold: 'wqy.ttf',
                    italics: 'wqy.ttf',
                    bolditalics: 'wqy.ttf'
                }
    
            };
            pdfMake.fonts = fontDescriptors;
            var docDefinition = { content: 'wqy中文wqy',
            defaultStyle: {
                font: 'wqy'
            }};
    
                   pdfMake.createPdf(docDefinition).open('test.pdf');
    

    G3548817

    bug 
    opened by darkautism 26
  • Save PDF to variable

    Save PDF to variable

    Is it possible to save the created PDF to a local variable for use elsewhere, to send as an attachment for example, or encode as base64 - rather than print, download, or open.

    opened by bayhall 24
  • Superscript and subscript

    Superscript and subscript

    I have a document that uses a lot of superscripted numbers (verse markings for scripture text). If it isn't possible, I could make them smaller and italicized, but the ability to make them superscript would be great.

    feature request 
    opened by revdave33 24
  • Links are not reported correctly in the PDF

    Links are not reported correctly in the PDF

    Links are not reported correctly in the PDF, although the syntax is correct. For instance, inserting

    { text: 'google', link: 'http://www.google.com' }

    results in a text "google" which is not clickable, either in the browser or in Adobe Reader. Links to other pages or destinations also do not work.

    How can I solve it?

    Note that, if I try to add "www.google.com", it is transformed in a link automatically.

    waiting for information 
    opened by andreaproietti 1
  • Invalid image: Error: Incomplete or corrupt PNG file Images dictionary should contain dataURL entries (or local file paths in node.js) on next js production only

    Invalid image: Error: Incomplete or corrupt PNG file Images dictionary should contain dataURL entries (or local file paths in node.js) on next js production only

    I am getting Invalid image: Error: Incomplete or corrupt PNG file Images dictionary should contain dataURL entries (or local file paths in node.js) on next js production only

    waiting for information 
    opened by mdShakilHossainNsu2018 1
  • Data url is not working as expected , Getting below error

    Data url is not working as expected , Getting below error

    Uncaught (in promise) Invalid image: Error: Incomplete or corrupt PNG file Images dictionary should contain dataURL entries (or local file paths in node.js)

    waiting for information 
    opened by Prakash-Growmax 3
  • Creating Rectangle with height as page height - margins

    Creating Rectangle with height as page height - margins

    I am trying to create a PDF document where the first page has a rectangle whose height is the page height excluding the margins. I see that I can get the page height, and the margin after I create a PDFDocument with createPdfKitDocument(). But by this point, I will have already created a document, and I cannot edit it.

    How can I dynamically set the height of a rectangle as the page height - margin.bottom?

    This is what I have so far.

    var printer = new PdfPrinter(fonts);
    var fs = require('fs');
    var docDefinition: TDocumentDefinitions = {
        pageSize: 'LETTER',
        pageOrientation: 'portrait',
        content: [
            {
                canvas: [{
                    type: 'rect',
                    fillOpacity: 1,
                    color: 'blue',
                    x: 0,
                    y: 0,
                    w: 20,
                    h: 720,
                }]
            }
        ]
    };
    
    var options = {
    };
    
    var pdfDoc = printer.createPdfKitDocument(docDefinition, options);
    
    pdfDoc.pipe(fs.createWriteStream('document.pdf'));
    pdfDoc.end();
    
    opened by sshakyaUR 0
  • Barcode Generation Support

    Barcode Generation Support

    We found some description on how to achieve this https://github.com/bpampuch/pdfmake/issues/929 using 3rd party. Is there any plans or someone working on it to add it as standard?

    opened by heldergoncalvesneptunesoftware 0
  • Column Width of * and Auto not constrained by page margins or page size

    Column Width of * and Auto not constrained by page margins or page size

    If I make a table with a column of * or auto shouldn't it be constrained by the margins?

    In this example, there is ample room for the column but it blows past the edge of the page. If I set a width on the 4th column everything works fine, but now I have to know the magic number for how much space is left on the page. Since width of a column doesn't seem to take into account padding and border it's not simple to figure out.

    var dd = {
    	content: [
    		{
    			table: {
    			    widths:[130, 130, 130, '*'],
    				body: [
    					['C 1', 'Column 2', 'Column 3', 'Column 4'],
    					['One', 'Another one here', 'OK?', 'Another one here'],
    					['One', 'Another one here', 'OK?','thisisareallylongstringblah'],
    				]
    			}
    		},
    		{
    		    margin: [0, 50, 0, 0],
    			table: {
    			    widths:[130, 130, 130, 'auto'],
    				body: [
    					['C 1', 'Column 2', 'Column 3', 'Column 4'],
    					['One', 'Another one here', 'OK?', 'Another one here'],
    					['One', 'Another one here', 'OK?','thisisareallylongstringblah'],
    				]
    			}
    		},
    	]
    }
    
    Screen Shot 2022-11-10 at 9 15 40 AM
    opened by dpitre 0
Releases(0.3.0-beta.4)
  • 0.3.0-beta.4(Dec 17, 2022)

    Prerelease version. Do not use in a production.

    Installation

    npm install [email protected]
    

    Changelog

    • Minimal supported version Node.js 14 LTS
    • Fixed theoretical vulnerability CVE-2022-46161 (It was never part of version released as npm package or cdnjs or bower or packagist!)

    Documentation

    Documentation for version 0.3: here Migration guide: here

    Source code(tar.gz)
    Source code(zip)
  • 0.2.7(Dec 17, 2022)

  • 0.3.0-beta.3(Oct 9, 2022)

    Prerelease version. Do not use in a production.

    Installation

    npm install [email protected]
    

    Changelog

    • Updated Roboto font (version 3.005)
    • Fixed calculating auto page height
    • Fixed TrueType Collection loading from URL
    • Fixed refetching fonts from URL

    Documentation

    Documentation for version 0.3: here Migration guide: here

    Source code(tar.gz)
    Source code(zip)
  • 0.2.6(Oct 9, 2022)

    • Updated Roboto font (version 3.005)
    • Fixed calculating auto page height
    • Fixed TrueType Collection loading from URL
    • Fixed refetching fonts from URL
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0-beta.2(Apr 1, 2022)

    Prerelease version. Do not use in a production.

    Installation

    npm install [email protected]
    

    Changelog

    • Attachments embedding
    • Support passing headers to request for loading font files and images via URL adresses

    Documentation

    Documentation for version 0.3: here Migration guide: here

    Source code(tar.gz)
    Source code(zip)
  • 0.2.5(Apr 1, 2022)

  • 0.3.0-beta.1(Jan 1, 2022)

    Prerelease version. Do not use in a production.

    Installation

    npm install [email protected]
    

    Changelog

    • Port code base to ES6+
    • Unify interface for node and browser (breaking change)
    • All methods return promise instead of using callback (breaking change)
    • Change including virtual font storage in client-side (breaking change)
    • Change parameters of pageBreakBefore function (breaking change)
    • Support for loading font files and images via URL adresses (https:// or http:// protocol) in Node.js (client and server side now)

    Documentation

    Documentation for version 0.3: here Migration guide: here

    Source code(tar.gz)
    Source code(zip)
  • 0.2.4(Nov 10, 2021)

    • Fixed destination path argument in VFS build script.
    • Fixed error "Object.isExtensible is not a function" (bug is in core-js version 3.19.1).
    Source code(tar.gz)
    Source code(zip)
  • 0.2.3(Nov 6, 2021)

  • 0.2.2(Aug 2, 2021)

  • 0.2.1(Aug 2, 2021)

  • 0.2.0(Jul 5, 2021)

    Source code(tar.gz)
    Source code(zip)
  • 0.1.72(Jul 5, 2021)

  • 0.1.71(Apr 5, 2021)

  • 0.1.70(Jan 16, 2021)

  • 0.1.69(Dec 27, 2020)

    • superscript and subscript support (see https://github.com/bpampuch/pdfmake/pull/2128)
    • support cover for image element (see https://github.com/bpampuch/pdfmake/pull/2148)
    • migrated from uglifyjs to terser minifier. This fix issues with minified version.
    • fix auto page height for table and vectors
    Source code(tar.gz)
    Source code(zip)
  • 0.1.68(Jul 31, 2020)

  • 0.1.67(Jul 26, 2020)

    • fixed include Promise polyfill
    • experimental SVG: rewrited SVG parsing
    • client-side: images file loading via url address (https:// or http:// protocol) in "images" dictionary Example of usage:
    var dd = {
    	content: [
    		{
    			image: 'testImage'
    		}
    	],
    	images: {
    		testImage: 'https://picsum.photos/seed/picsum/200/300',
    	}
    };
    

    This is not supported: ~~{ image: 'https://picsum.photos/seed/picsum/200/300' }~~

    Source code(tar.gz)
    Source code(zip)
  • 0.1.66(Jun 30, 2020)

    • client-side: font files loading via url address (https:// or http:// protocol), (see documentation). Roboto TTF font files are now available via CDN: https://cdnjs.com/libraries/pdfmake
    • client-side: getStream() support callback (see documentation)
    • fixed FDArray parsing in CFF in font
    Source code(tar.gz)
    Source code(zip)
  • 0.1.65(Mar 1, 2020)

    • support of fillOpacity property in tables
    • support of linkToPage and linkToDestination with images
    • pageBreakBefore performance improvement
    • fix support opacity with number 0
    Source code(tar.gz)
    Source code(zip)
  • 0.1.64(Feb 2, 2020)

    • added new values for pageBreak:
      • beforeOdd, afterOdd - break to odd page
      • beforeEven, afterEven - break to even page
    • fixed pageMargins: 0
    • experimental SVG - fixed too bold and too italics text
    Source code(tar.gz)
    Source code(zip)
  • 0.1.63(Dec 11, 2019)

  • 0.1.62(Nov 3, 2019)

    • experimental SVG - default font for unknown fonts is used from defaultStyle element. Or can be defined in svg node via font property
    • experimental SVG - fixed finding fonts
    Source code(tar.gz)
    Source code(zip)
  • 0.1.61(Oct 25, 2019)

  • 0.1.60(Sep 21, 2019)

  • 0.1.59(Sep 7, 2019)

    • experimental SVG nodes is build-in by default now
    • fix svg with decimal numbers
    • fix svg rendering in header and footer
    • fix border borderColor in table
    Source code(tar.gz)
    Source code(zip)
  • 0.1.58(Jul 27, 2019)

  • 0.1.57(Jun 9, 2019)

    • update pdfkit to 0.10.0
    • added feature link to destination via linkToDestination property (see links example)
    • ToC - links to destination support with title and page number
    Source code(tar.gz)
    Source code(zip)
  • 0.1.56(May 4, 2019)

  • 0.1.55(May 1, 2019)

    • update pdfkit to 0.9.1
    • add borderColor for table cell (example borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'] and see table example)
    • cache can be disabled via fontLayoutCache option. Example: printer.createPdfKitDocument(docDefinition, { fontLayoutCache: false }) on server-side and pdfMake.createPdf(docDefinition).download('document.pdf', null, { fontLayoutCache: false }); on client-side
    • normalized readFileSync method parameters in virtual file system same as in node.js
    • improved throwing of exception for opening image
    • fix download() options might be dropped
    • upgrade to webpack 4
    Source code(tar.gz)
    Source code(zip)
Owner
Bartek Pampuch
Bartek Pampuch
File downloading using client-side javascript

download Summary The download() function is used to trigger a file download from JavaScript. It specifies the contents and name of a new file placed i

dandavis 2.1k Dec 31, 2022
PDF Reader in JavaScript

PDF.js PDF.js is a Portable Document Format (PDF) viewer that is built with HTML5. PDF.js is community-driven and supported by Mozilla. Our goal is to

Mozilla 41.1k Jan 8, 2023
A JavaScript PDF generation library for Node and the browser

PDFKit A JavaScript PDF generation library for Node and the browser. Description PDFKit is a PDF document generation library for Node and the browser

null 8.5k Jan 7, 2023
MyDrive is an Open Source cloud file storage server (Similar To Google Drive)

MyDrive is an Open Source cloud file storage server (Similar To Google Drive). Host myDrive on your own server or trusted platform and then access myDrive through your web browser. MyDrive uses mongoDB to store file/folder metadata, and supports multiple databases to store the file chunks, such as Amazon S3, the Filesystem, or just MongoDB. MyDrive is built using Node.js, and Typescript. The service now even supports Docker images!

null 2.8k Dec 30, 2022
Pretty diff to html javascript library (diff2html)

diff2html diff2html generates pretty HTML diffs from git diff or unified diff output. Table of Contents Features Online Example Distributions Usage Di

Rodrigo Fernandes 2.3k Dec 31, 2022
Client-side JavaScript PDF generation for everyone.

A library to generate PDFs in JavaScript. You can catch me on twitter: @MrRio or head over to my company's website for consultancy. jsPDF is now co-ma

James Hall 25.7k Dec 28, 2022
A Javascript library to export svg charts from the DOM and download them as an SVG file, PDF, or raster image (JPEG, PNG) format. Can be done all in client-side.

svg-exportJS An easy-to-use client-side Javascript library to export SVG graphics from web pages and download them as an SVG file, PDF, or raster imag

null 23 Oct 5, 2022
A lazy plugin for printing local network when starting NodeJS server. I made this so you don't have to.

lazy-net A simple, lightweight plugin for printing local network when starting Node.js or Express.js server. I made this so you don't have to. There a

Trần Quang Kha (始) 1 Feb 10, 2022
Fast and minimal JS server-side writer and client-side manager.

unihead Fast and minimal JS <head> server-side writer and client-side manager. Nearly every SSR framework out there relies on server-side components t

Jonas Galvez 24 Sep 4, 2022
Easy server-side and client-side validation for FormData, URLSearchParams and JSON data in your Fresh app 🍋

Fresh Validation ??     Easily validate FormData, URLSearchParams and JSON data in your Fresh app server-side or client-side! Validation Fresh Validat

Steven Yung 20 Dec 23, 2022
PDF.js Read Only is an additional readonly mode for PDF.js

PDF.js Read Only PDF.js Read Only is an additional readonly mode for PDF.js, a Portable Document Format (PDF) viewer that is built with HTML5 which is

Aprillio Latuminggi 19 Dec 22, 2022
I'm trying to create simple program for adding the digital signature to a pdf file with self-signed certificate. I use node-signpdf and pdf-lib library.

pdf-digital-signature-with-node-signpdf-ejs I'm trying to create simple program for adding the digital signature to a pdf file with self-signed certif

null 5 Dec 25, 2022
CLI tool for printing anime quotes in your terminal.

aniquote Why? While i was browsing Unixporn looking to steal someone's dotfiles (im too lazy to rice myself) i saw some anime-related rices and though

kugi 14 Dec 22, 2022
Easy to use, Element Printing Plugin for jQuery

jQuery Print Plugin jQuery.print is a plugin for printing specific parts of a page Usage Include it in your HTML after importing jQuery, like: <scrip

Doers' Guild 817 Nov 25, 2022
🖼 A pure client-side landing page template that you can fork, customize and host freely. Relies on Mailchimp and Google Analytics.

landing-page-boilerplate A pure client-side landing page template that you can freely fork, customize, host and link to your own domain name (e.g. usi

Adrien Joly 129 Dec 24, 2022
A vanilla javascript library to generate Avataaars on the client or server side!

Use the awesome Avataaars Library by Pablo Stanley (avataaars.com) in any javascript application. This Project uses parts of the Dicebear Avatars Libr

Hannes Bosch 26 Dec 4, 2022
Free, open-source client or server-side APIs to "lint" user input.

passbird Free, open-source client or server-side APIs to lint user input. Right now, you can check type for an email address i.e., either of disposabl

Vaibhav Pandey 1 Dec 26, 2021
WebVM is a server-less virtual Linux environment running fully client-side in HTML5/WebAssembly.

WebVM This repository hosts the source code of the https://webvm.io live demo page. WebVM is a server-less virtual Linux environment running fully cli

Leaning Technologies Ltd 1.7k Jan 8, 2023
This is an email scheduler made using MERN stack. This repo contains client, server side is linked in readme

Email Scheduler Client This is an email scheduler client (server in different repository). It is made using react. Overview User can sign-up/sign-in,

Sai Charan 3 Dec 3, 2022
RPC-like client, contract, and server implementation for a pure REST API

ts-rest RPC-like client and server helpers for a magical end to end typed experience Introduction ts-rest provides an RPC-like client side interface o

tREST 215 Dec 30, 2022