0.0.1 • Published 4 years ago

@tshio/pdf-client v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

RAD PDF Client

npm version

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
NameTypeDescriptionDefault
fromstringuri or html string
typestringSource type, allowed values: uri, html
pdfOptionsobjectoptional PDF options
pdfOptions.scalenumberoptional Scale of the webpage rendering.1
pdfOptions.displayHeaderFooterbooleanoptional Display header and footer.false
pdfOptions.headerTemplatestringoptional 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.footerTemplatestringoptional 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.printBackgroundbooleanoptional Print background graphics.false
pdfOptions.landscapebooleanoptional Paper orientation.false
pdfOptions.pageRangesstringoptional Paper ranges to print, e.g., '1-5, 8, 11-13'.'' which means print all pages.
pdfOptions.formatstringoptional 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.widthnumberoptional Paper width.
pdfOptions.heightnumberoptional Paper height.
pdfOptions.marginobjetctoptional Paper margins, defaults to none.
pdfOptions.topnumberoptional Top margin.
pdfOptions.rightnumberoptional Right margin.
pdfOptions.bottomnumberoptional Bottom margin.
pdfOptions.leftnumberoptional Left margin.

Back to API

schedulerClient.pdf.download({ fileId }) => Promise

Download PDF file

Returns string of pdf file content or throw HttpError

Parameters
NameTypeDescriptionDefault
fileIdstringFile ID for download pdf file

Back to API

License

license

This project is licensed under the terms of the MIT license.

About us:

The Software House