Narcissistic, Perfectly Modest

    metalsmith-pdfize

    3.0.0 • Public • Published

    metalsmith-pdfize

    A Metalsmith plugin to export files to PDF.

    Internally, it uses Chrome in headless mode with Puppeteer to generate a PDF version of any file registered in Metalsmith with print CSS media.

    Build status

    Installation

    This plugin requires Node.js 14 or later

    $ npm install metalsmith-pdfize
    

    Usage

    JavaScript

    const metalsmith = require('metalsmith');
    const pdfize = require('pdfize');
    
    metalsmith.use(pdfize({
        pattern: ['page/cv/*', 'another/page/*html'],
        printOptions: {
            printBackground: true,
            format: 'A4',
        },
        launchOptions: {},
    });

    The pdfize function accepts an option object with 3 entries:

    1. pattern: a multimatch pattern(s) matching files that should be loaded and exported to PDF
    2. printOptions: an object that is directly passed to puppeteer Page#pdf() function to control headless Chrome behaviour. See Puppeteer documentation for available options.
    3. launchOptions an object that is directly passed to puppeteer Puppeteer#launch() function to control headless Chrome behaviour. See Puppeteer documentation for available options.

    PDF files are registered into Metalsmith files list. Generated PDF files are named after the file used as source with the .pdf suffix. For instance, if a pattern matches the file page/cv/index.html, the generated PDF path will be page/cv/index.html.pdf. metalsmith-pdfize does not support file renaming, metalsmith-renamer can be used if you need to rename generated PDF.

    CLI

    {
        "plugin": {
            "metalsmith-pdfize": {
                "pattern": ["page/cv/*", "another/page/*html"],
                "printOptions": {
                    "printBackground": true,
                    "format": "A4"
                }
            }
        }
    }

    License

    MIT

    Install

    npm i metalsmith-pdfize

    DownloadsWeekly Downloads

    7

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    20 kB

    Total Files

    13

    Last publish

    Collaborators

    • dpobel