A simple commandline HTML to PDF converter using node and puppeteer
git clone https://github.com/sten-schmidt/html2pdf.git
cd .\html2pdf\
npm install
node .\html2pdf.js --help
node html2pdf.js --html=<HtmlFile> --pdf=<PdfFile> <optional parameters>
URL to a webressource or path to a local HTML file. URL must start with 'http'. A path to a local file is automatically converted into file:/// syntax.
The file path to save the PDF to. If 'pdf' is a relative path, then it is resolved relative to current working directory.
URL to a webressource or path to a local CSS file. Additional CSS styles will applyed before pdf generation. URL must start with 'http'. A path to a local file is automatically converted into file:/// syntax.
Paper orientation. default false.
Paper format, possible values are Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6. If set, takes priority over width or height options. Defaults to 'A4'.
Paper width, accepts values labeled with units, possible units: px, in, cm, mm.
Paper height, accepts values labeled with units, possible units: px, in, cm, mm.
Top margin, accepts values labeled with units, possible units: px, in, cm, mm.
Right margin, accepts values labeled with units, possible units: px, in, cm, mm.
Bottom margin, accepts values labeled with units, possible units: px, in, cm, mm.
Left margin, accepts values labeled with units, possible units: px, in, cm, mm.
Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
Print background graphics. default false.
Scale of the webpage rendering. default 1
Changes the CSS media type of the page to 'screen', default is 'print'.
Display header and footer. default false.
HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: 'date' formatted print date, 'title' document title, 'url document location, 'pageNumber' current page number, 'totalPages' total pages in the document.
HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them: 'date' formatted print date, 'title' document title, 'url document location, 'pageNumber' current page number, 'totalPages' total pages in the document.
Set loglevel, possible loglevels are: debug, info, error, fatal, off. Default is info.
Set name and path to the logfile. Default is html2pdf.log.
- In case of success: 0
- In case of error: 1