Methods
Download the PDF
pdfMake.createPdf(docDefinition).download();
Parameters:
defaultFileName
(optional) - file namecb
(optional) - callback functionoptions
(optional) - advanced options see options chapter
Open the PDF in a new window
pdfMake.createPdf(docDefinition).open();
Parameters:
options
(optional) - advanced options see options chapterwin
(optional) - window (when an asynchronous operation)
Name can be defined only by using metadata title
property (see Document metadata).
Asynchronous example:
$scope.generatePdf = function() {
// create the window before the callback
var win = window.open('', '_blank');
$http.post('/someUrl', data).then(function(response) {
// pass the "win" argument
pdfMake.createPdf(docDefinition).open({}, win);
});
};
Open in same window:
pdfMake.createPdf(docDefinition).open({}, window);
Print the PDF
pdfMake.createPdf(docDefinition).print();
Parameters:
options
(optional) - advanced options see options chapterwin
(optional) - window (when an asynchronous operation)
Asynchronous example:
$scope.generatePdf = function() {
// create the window before the callback
var win = window.open('', '_blank');
$http.post('/someUrl', data).then(function(response) {
// pass the "win" argument
pdfMake.createPdf(docDefinition).print({}, win);
});
};
Print in same window:
pdfMake.createPdf(docDefinition).print({}, window);
Put the PDF into your own page as URL data
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getDataUrl((dataUrl) => {
const targetElement = document.querySelector('#iframeContainer');
const iframe = document.createElement('iframe');
iframe.src = dataUrl;
targetElement.appendChild(iframe);
});
Parameters:
cb
- callback functionoptions
(optional) - advanced options see options chapter
Get the PDF as base64 data
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBase64((data) => {
alert(data);
});
Parameters:
cb
- callback functionoptions
(optional) - advanced options see options chapter
Get the PDF as buffer
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBuffer((buffer) => {
// ...
});
Parameters:
cb
- callback functionoptions
(optional) - advanced options see options chapter
Get the PDF as Blob
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBlob((blob) => {
// ...
});
Parameters:
cb
- callback functionoptions
(optional) - advanced options see options chapter
Get PDFKit document object as stream
Asynchronous call
Minimal version: 0.1.66
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getStream((document) => {
// ...
});
Parameters:
cb
- callback function
Synchronous call
Minimal version: 0.1.41
The preferred way is asynchronous call.
Unable to download real font files from url (https:// or http://). Asynchronous call required.
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
var document = pdfDocGenerator.getStream();