0.0.1 • Published 4 years ago
@tshio/pdf-client v0.0.1
RAD PDF Client
Non-blocking RAD PDF client for Node.js.
This is a 100% JavaScript library, with TypeScript definition, with the Promise API.
Table of Contents
Installing
$ npm install @tshio/pdf-client
or
$ yarn add @tshio/pdf-client
Loading and configuration module
// CommonJS
const { PdfClient } = require('@tshio/pdf-client');
// ES Module
import { PdfClient } from '@tshio/pdf-client';
const options = {
host: "localhost",
port: "50080",
}
const pdfClient = new PdfClient(options);
Getting started
Create pdf
pdfClient.pdf.create({
from: "http://www.example.com",
type: "uri",
pdfOptions: {},
}).then({ url, fileId, expiryAt } => {
// ...
});
Download pdf
pdfClient.pdf.download({
fileId: "9aeb4fc5-d95c-4130-8d0e-f876e3a29565"
}).then( pdf => {
// save pdf to file
const stream = fs.createWriteStream('./example.pdf');
stream.on('finish', () => {
console.log('PDF file created');
});
stream.write(pdf);
});
API
schedulerClient.pdf.create({ from, type, pdfOptions? }) => Promise<{ url, expiryAt }>
Create pdf from url
Returns an object
{
fileId: string;
url: string;
expiryAt: Date;
}
or throw HttpError
Parameters
Name | Type | Description | Default |
---|---|---|---|
from | string | uri or html string | |
type | string | Source type, allowed values: uri , html | |
pdfOptions | object | optional PDF options | |
pdfOptions.scale | number | optional Scale of the webpage rendering. | 1 |
pdfOptions.displayHeaderFooter | boolean | optional Display header and footer. | false |
pdfOptions.headerTemplate | string | optional HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:date formatted print datetitle document titleurl document locationpageNumber current page numbertotalPages total pages in the document | |
pdfOptions.footerTemplate | string | optional HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them:date formatted print datetitle document titleurl document locationpageNumber current page numbertotalPages total pages in the document | |
pdfOptions.printBackground | boolean | optional Print background graphics. | false |
pdfOptions.landscape | boolean | optional Paper orientation. | false |
pdfOptions.pageRanges | string | optional Paper ranges to print, e.g., '1-5, 8, 11-13'. | '' which means print all pages. |
pdfOptions.format | string | optional Paper format. If set, takes priority over width or height options.Allowed values: "Letter", "Legal", "Tabloid", "Ledger", "A0", "A1", "A2", "A3", "A4", "A5", "A6" | Letter |
pdfOptions.width | number | optional Paper width. | |
pdfOptions.height | number | optional Paper height. | |
pdfOptions.margin | objetct | optional Paper margins, defaults to none. | |
pdfOptions.top | number | optional Top margin. | |
pdfOptions.right | number | optional Right margin. | |
pdfOptions.bottom | number | optional Bottom margin. | |
pdfOptions.left | number | optional Left margin. |
schedulerClient.pdf.download({ fileId }) => Promise
Download PDF file
Returns string of pdf file content or throw HttpError
Parameters
Name | Type | Description | Default |
---|---|---|---|
fileId | string | File ID for download pdf file |
License
This project is licensed under the terms of the MIT license.
About us:
The Software House
0.0.1
4 years ago