Methods

Download the PDF

pdfMake.createPdf(docDefinition).download();

Parameters:

Open the PDF in a new window

pdfMake.createPdf(docDefinition).open();

Parameters:

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);
pdfMake.createPdf(docDefinition).print();

Parameters:

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:

Get the PDF as base64 data

const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBase64((data) => {
	alert(data);
});

Parameters:

Get the PDF as buffer

const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBuffer((buffer) => {
	// ...
});

Parameters:

Get the PDF as Blob

const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getBlob((blob) => {
	// ...
});

Parameters:

Get PDFKit document object as stream

Asynchronous call
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
pdfDocGenerator.getStream((document) => {
	// ...
});

Parameters:

Synchronous call
const pdfDocGenerator = pdfMake.createPdf(docDefinition);
var document = pdfDocGenerator.getStream();