Moleculer service to generate PDF
npm install moleculer-pdf --save
'use strict';
let { ServiceBroker } = require("moleculer");
let PDFService = require("../../index");
const { promisify } = require("util");
const { writeFile } = require("fs");
const writeFileAsync = promisify(writeFile);
// Create broker
let broker = new ServiceBroker({
logger: console
});
// Load my service
broker.createService(PDFService);
// Start server
broker.start().then(() => {
// Call action
broker
.call("pdf.transform", { html: "<h1>John Doe</h1>" })
.then(buff => writeFileAsync("./pdf.pdf", buff))
.catch(broker.logger.error);
});
Property | Type | Default | Description |
---|---|---|---|
puppeteerArgs |
Object |
{ headless: true } |
Set of configurable options to set on the browser |
options |
Object |
{ format: 'letter' } |
Set of configurable options to set pdf document |
remoteContent |
Boolean |
true |
Content to load on webpage like |
Transform html to pdf document
Property | Type | Default | Description |
---|---|---|---|
html |
String |
required | The html content |
Type: Buffer
- Generated pdf document
Transform html to pdf document
Property | Type | Default | Description |
---|---|---|---|
html |
String |
- | The html content |
Type: Buffer
- Generated pdf document
$ npm test
In development with watching
$ npm run ci
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.
The project is available under the MIT license.
Copyright (c) 2019 moleculer-pdf