UNPKG

mr-pdf

Version:

Generate pdf from document

38 lines (37 loc) 1.95 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk = require("chalk"); const program = require("commander"); const utils_1 = require("./utils"); const commander_options_1 = require("./commander-options"); program .name('mr-pdf') .requiredOption('--initialDocURLs <urls>', 'set urls to start generating PDF from', commander_options_1.commaSeparatedList) .option('--excludeURLs <urls>', 'urls to be excluded in PDF', commander_options_1.commaSeparatedList) .requiredOption('--contentSelector <selector>', 'used to find the part of main content') .requiredOption('--paginationSelector <selector>', 'used to find next url') .option('--excludeSelectors <selectors>', 'exclude selector ex: .nav', commander_options_1.commaSeparatedList) .option('--cssStyle <cssString>', 'css style to adjust PDF output ex: body{padding-top: 0;}') .option('--outputPDFFilename <filename>', 'name of output PDF file') .option('--pdfMargin <margin>', 'set margin around PDF file', commander_options_1.generatePuppeteerPDFMargin) .option('--pdfFormat <format>', 'pdf format ex: A3, A4...') .option('--coverTitle <title>', 'title for PDF cover') .option('--coverImage <src>', 'image for PDF cover. *.svg file not working!') .option('--disableTOC', 'disable table of contents') .option('--coverSub <subtitle>', 'subtitle for PDF cover') .option('--waitForRender <timeout>', 'wait for document render') .option('--headerTemplate <html>', 'html template for page header') .option('--footerTemplate <html>', 'html template for page footer') .action((options) => { utils_1.generatePDF(options) .then(() => { console.log(chalk.green('Finish generating PDF!')); process.exit(0); }) .catch((err) => { console.error(chalk.red(err.stack)); process.exit(1); }); }); program.parse(process.argv);