Metalsmith plugin to export files to PDF.
npm install metalsmith-pdfizeA 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.
This plugin requires Node.js 20 or later
```
$ npm install metalsmith-pdfize
`js
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 multimatchprintOptions
pattern(s) matching files that should be loaded and exported to PDF
2. : an object that is directly passed to puppeteer Page#pdf()launchOptions
function to control headless Chrome behaviour. See Puppeteer
documentation
for available options.
3. an object that is passed to puppeteer Puppeteer#launch()headless
function to control headless Chrome behaviour. See Puppeteer
documentation
for available options. The is set by default to new but it can be overridden if needed.
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 apage/cv/index.html
pattern matches the file , the generated PDF path will bepage/cv/index.html.pdf. metalsmith-pdfize does not support file
renaming,
metalsmith-renamer can be
used if you need to rename generated PDF.
`json``
{
"plugin": {
"metalsmith-pdfize": {
"pattern": ["page/cv/", "another/page/html"],
"printOptions": {
"printBackground": true,
"format": "A4"
}
}
}
}
MIT