ongoworks:pdf

v1.1.1Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

ongoworks:pdf

A Meteor package that allows you to save a Meteor template as a PDF on the client. This package is simply a nice wrapper around jsPDF.

Note: jsPDF HTML-to-PDF support is still experimental. Don't expect magic here.

Installation

$ meteor add ongoworks:pdf

Usage

The saveAsPDF method will save/download to the browser's downloads folder (or prompt with Save As dialog, depending on browser settings).

1Blaze.saveAsPDF(Template.report, {
2  filename: "report.pdf", // optional, default is "document.pdf"
3  data: myData, // optional, render the template with this data context
4  x: 0, // optional, left starting position on resulting PDF, default is 4 units
5  y: 0, // optional, top starting position on resulting PDF, default is 4 units
6  orientation: "landscape", // optional, "landscape" or "portrait" (default)
7  unit: "in", // optional, unit for coordinates, one of "pt", "mm" (default), "cm", or "in"
8  format: "letter" // optional, see Page Formats, default is "a4"
9});

Other Output Types

There are many other output types supported as well. All of these accept the same options as saveAsPDF.

1// API
2Blaze.outputAsPDF(templateOrView, type, [options], callback);
3
4// Examples
5
6// ArrayBuffer
7Blaze.outputAsPDF(Template.report, 'arraybuffer', function (arrayBuffer) {
8
9});
10
11// Blob
12Blaze.outputAsPDF(Template.report, 'blob', function (blob) {
13
14});
15
16// Object URL
17Blaze.outputAsPDF(Template.report, 'bloburi', function (objectUrl) {
18
19});
20
21// DataURI string
22Blaze.outputAsPDF(Template.report, 'datauristring', function (dataUriString) {
23
24});
25
26// Opens the document in the current window/tab
27Blaze.outputAsPDF(Template.report, 'datauri');
28
29// Opens the document in a new window/tab
30Blaze.outputAsPDF(Template.report, 'dataurlnewwindow');

Page Formats

The format option may be any of the following format strings, which map to standard page sizes:

"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10",
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10",
"c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10",
"dl", "letter", "government-letter", "legal", "junior-legal",
"ledger", "tabloid", "credit-card"

Contributing

You are welcome to submit pull requests if you have ideas for fixing or improving the API.