From 027b02b3ed83b73020ac4cf241473c8403667963 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Fri, 6 Sep 2024 17:35:43 +0200 Subject: [PATCH] update methods --- .../getting-started/client-side/methods.md | 52 ++++++++--------- content/getting-started/server-side/_index.md | 4 +- .../getting-started/server-side/methods.md | 58 ++++++++++++++++++- 3 files changed, 80 insertions(+), 34 deletions(-) diff --git a/content/getting-started/client-side/methods.md b/content/getting-started/client-side/methods.md index a8a20c3..91fe4b0 100644 --- a/content/getting-started/client-side/methods.md +++ b/content/getting-started/client-side/methods.md @@ -5,27 +5,37 @@ weight = 11 alwaysopen = true +++ +#### Base usage + +This call will generate a PDF document, methods to get document are described below. + +```js +pdfMake.createPdf(docDefinition); +pdfMake.createPdf(docDefinition, options); +``` + +Parameters: + +* `docDefinition` - object with document definition, see [chapter](/docs/0.3/document-definition-object/) +* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) + #### Download the PDF ```js pdfMake.createPdf(docDefinition).download(); pdfMake.createPdf(docDefinition).download('file.pdf'); -pdfMake.createPdf(docDefinition, options).download(); ``` Parameters: * `filename` _(optional)_ - PDF document file name (default 'file.pdf') -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) #### Open the PDF in a new window ```js pdfMake.createPdf(docDefinition).open(); pdfMake.createPdf(docDefinition).open(win); -pdfMake.createPdf(docDefinition, options).open(); ``` Parameters: * `win` _(optional)_ - window (when an asynchronous operation) -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) Name can be defined only by using metadata `title` property (see [Document metadata](/docs/0.3/document-definition-object/document-medatadata/)). @@ -50,12 +60,10 @@ pdfMake.createPdf(docDefinition).open(window); ```js pdfMake.createPdf(docDefinition).print(); pdfMake.createPdf(docDefinition).print(win); -pdfMake.createPdf(docDefinition, options).print(); ``` Parameters: * `win` _(optional)_ - window (when an asynchronous operation) -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) Asynchronous example: ```js @@ -74,7 +82,9 @@ Print in same window: pdfMake.createPdf(docDefinition).print(window); ``` -#### Put the PDF into your own page as URL data +#### Get the PDF document as URL data + +Example of put the PDF document into your own page as URL data: ```js pdfMake.createPdf(docDefinition).getDataUrl().then((dataUrl) => { const targetElement = document.querySelector('#iframeContainer'); @@ -84,52 +94,36 @@ pdfMake.createPdf(docDefinition).getDataUrl().then((dataUrl) => { }, err => { console.error(err); }); - -pdfMake.createPdf(docDefinition).getDataUrl() ``` -Parameters: - -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) -#### Get the PDF as base64 data +#### Get the PDF document as base64 data ```js pdfMake.createPdf(docDefinition).getBase64().then((data) => { alert(data) }, err => { console.error(err); }); - -pdfMake.createPdf(docDefinition, options).getBase64() ``` -Parameters: - -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) -#### Get the PDF as buffer +#### Get the PDF document as Blob ```js -pdfMake.createPdf(docDefinition).getBuffer().then((buffer) => { +pdfMake.createPdf(docDefinition).getBlob().then((blob) => { // ... }, err => { console.error(err); }); ``` -Parameters: -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) - -#### Get the PDF as Blob +#### Get the PDF as buffer ```js -pdfMake.createPdf(docDefinition).getBlob().then((blob) => { +pdfMake.createPdf(docDefinition).getBuffer().then((buffer) => { // ... }, err => { console.error(err); }); ``` -Parameters: - -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) -#### Get document object as stream +#### Get the PDF document as stream ```js pdfMake.createPdf(docDefinition).getStream().then((stream) => { diff --git a/content/getting-started/server-side/_index.md b/content/getting-started/server-side/_index.md index 634f7b7..bb52581 100644 --- a/content/getting-started/server-side/_index.md +++ b/content/getting-started/server-side/_index.md @@ -42,7 +42,7 @@ pdf.write('document.pdf').then(() => { }); ``` -Parameters for `createPdfKitDocument`: +Parameters for `createPdf`: -* `docDefinition` - object with document definition +* `docDefinition` - object with document definition, see [chapter](/docs/0.3/document-definition-object/) * `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) \ No newline at end of file diff --git a/content/getting-started/server-side/methods.md b/content/getting-started/server-side/methods.md index 7dc6183..80844b6 100644 --- a/content/getting-started/server-side/methods.md +++ b/content/getting-started/server-side/methods.md @@ -5,9 +5,23 @@ weight = 12 alwaysopen = true +++ -#### Write +#### Base usage + +This call will generate a PDF document, methods to get document are described below. + ```js -pdfMake.createPdf(docDefinition).write(filename).then(() => { +pdfmake.createPdf(docDefinition); +pdfmake.createPdf(docDefinition, options); +``` + +Parameters: + +* `docDefinition` - object with document definition, see [chapter](/docs/0.3/document-definition-object/) +* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) + +#### Write the PDF document as file +```js +pdfmake.createPdf(docDefinition).write(filename).then(() => { // finished }, err => { console.error(err); @@ -16,4 +30,42 @@ pdfMake.createPdf(docDefinition).write(filename).then(() => { Parameters: * `filename` - PDF document file name -* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) \ No newline at end of file +* `options` _(optional)_ - advanced options see [options chapter](/docs/0.3/options/) + +#### Get the PDF document as URL data + +```js +pdfmake.createPdf(docDefinition).getDataUrl().then((dataUrl) => { + // ... +}, err => { + console.error(err); +}); +``` + +#### Get the PDF document as base64 data +```js +pdfmake.createPdf(docDefinition).getBase64().then((data) => { + alert(data) +}, err => { + console.error(err); +}); +``` + +#### Get the PDF document as buffer +```js +pdfmake.createPdf(docDefinition).getBuffer().then((buffer) => { + // ... +}, err => { + console.error(err); +}); +``` + +#### Get the PDF document as stream + +```js +pdfmake.createPdf(docDefinition).getStream().then((stream) => { + // ... +}, err => { + console.error(err); +}); +``` \ No newline at end of file