Methods

Download the PDF

pdfMake.createPdf(docDefinition).download();
pdfMake.createPdf(docDefinition).download('file.pdf');
pdfMake.createPdf(docDefinition, options).download();

Parameters:

Open the PDF in a new window

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

pdfMake.createPdf(docDefinition).getDataUrl().then((dataUrl) => {
	const targetElement = document.querySelector('#iframeContainer');
	const iframe = document.createElement('iframe');
	iframe.src = dataUrl;
	targetElement.appendChild(iframe);
}, err => {
	console.error(err);
});

pdfMake.createPdf(docDefinition).getDataUrl()

Parameters:

Get the PDF as base64 data

pdfMake.createPdf(docDefinition).getBase64().then((data) => {
	alert(data)
}, err => {
	console.error(err);
});

pdfMake.createPdf(docDefinition, options).getBase64()

Parameters:

Get the PDF as buffer

pdfMake.createPdf(docDefinition).getBuffer().then((buffer) => {
	// ...
}, err => {
	console.error(err);
});

Parameters:

Get the PDF as Blob

pdfMake.createPdf(docDefinition).getBlob().then((blob) => {
	// ...
}, err => {
	console.error(err);
});

Parameters:

Get document object as stream

pdfMake.createPdf(docDefinition).getStream().then((stream) => {
	// ...
}, err => {
	console.error(err);
});