https://github.com/dpobel/metalsmith-pdfize
Metalsmith plugin to export files to PDF
https://github.com/dpobel/metalsmith-pdfize
chrome-headless metalsmith metalsmith-plugin pdf
Last synced: 6 months ago
JSON representation
Metalsmith plugin to export files to PDF
- Host: GitHub
- URL: https://github.com/dpobel/metalsmith-pdfize
- Owner: dpobel
- License: mit
- Created: 2017-09-26T13:33:40.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T07:08:58.000Z (7 months ago)
- Last Synced: 2025-04-15T02:44:43.440Z (6 months ago)
- Topics: chrome-headless, metalsmith, metalsmith-plugin, pdf
- Language: JavaScript
- Size: 1.61 MB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# metalsmith-pdfize
A Metalsmith plugin to export files to PDF.
Internally, it uses Chrome in headless mode with
[Puppeteer](https://www.npmjs.com/package/puppeteer) to generate a PDF version
of any file registered in Metalsmith with `print` CSS media.
## Installation
This plugin requires Node.js 20 or later
```
$ npm install metalsmith-pdfize
```## Usage
### JavaScript
```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 [multimatch](https://www.npmjs.com/package/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](https://pptr.dev/api/puppeteer.pdfoptions)
for available options.
3. `launchOptions` an object that is passed to puppeteer `Puppeteer#launch()`
function to control headless Chrome behaviour. See [Puppeteer
documentation](https://pptr.dev/api/puppeteer.browserlaunchargumentoptions)
for available options. The `headless` 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 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](https://github.com/dpobel/metalsmith-pdfize/issues/4),
[metalsmith-renamer](https://www.npmjs.com/package/metalsmith-renamer) can be
used if you need to rename generated PDF.### CLI
```json
{
"plugin": {
"metalsmith-pdfize": {
"pattern": ["page/cv/*", "another/page/*html"],
"printOptions": {
"printBackground": true,
"format": "A4"
}
}
}
}
```## License
MIT