Skip to content

Commit

Permalink
update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Sep 6, 2024
1 parent 0edf054 commit 027b02b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 34 deletions.
52 changes: 23 additions & 29 deletions content/getting-started/client-side/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)).

Expand All @@ -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
Expand All @@ -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');
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions content/getting-started/server-side/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
58 changes: 55 additions & 3 deletions content/getting-started/server-side/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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/)
* `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);
});
```

0 comments on commit 027b02b

Please sign in to comment.