adonis-pdf
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "adonis-pdf", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Create PDF files within Adonis using pdfmake", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,6 +18,12 @@ # adonis-pdf | ||
## Usage | ||
`PDF.create()` accepts two parameters: | ||
* `definition`: Object representing the PDF content/styles etc | ||
* `stream`: A Readable or Writeable Stream the PDF will be piped to | ||
## Example | ||
```js | ||
'use strict' | ||
const Pdf = use('Pdf') | ||
const PDF = use('PDF') | ||
@@ -27,13 +33,19 @@ class MyController { | ||
async generatePdf ({ response }) { | ||
const pdf = new PDF({ | ||
// custom config (this will override config/pdf.js ) | ||
}) | ||
const doc = Pdf.create({ | ||
const definition = { | ||
content: [ | ||
{ text: 'test' } | ||
] | ||
}) | ||
{ | ||
text: 'test', | ||
style: 'header' | ||
} | ||
], | ||
styles: { | ||
header: { | ||
fontSize: 22, | ||
bold: true | ||
} | ||
} | ||
} | ||
doc.pipe(response.response) | ||
doc.end() | ||
PDF.create(definition, response.response) | ||
@@ -40,0 +52,0 @@ return response |
@@ -45,3 +45,3 @@ 'use strict' | ||
if (typeof content === 'object') { | ||
this.document = this.printer.createPdfKitDocument(content) | ||
this.document = this.printer.createPdfKitDocument({ content: content }) | ||
this.document.pipe(stream) | ||
@@ -48,0 +48,0 @@ this.document.end() |
2113161
55