Puppeteer does not come with built-in functionality to edit or write metadata to a PDF.
Instead, you can install the exiftool
command line utility to edit the metadata of PDFs generated with Puppeteer:
sudo apt install libimage-exiftool-perl
Then you can use the Node.js child_process.exec()
function to call the command line utility from your program after the PDF has been generated:
'use strict';
const puppeteer = require('puppeteer');
const exec = require('util').promisify(require('child_process').exec);
const execute = async command => {
const {stdout, stderr} = await exec(command);
console.log((stderr || stdout).trim());
};
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com/');
await page.pdf({
path: 'example.pdf',
});
await execute('exiftool -title="Example PDF" -author="John Doe" /var/www/example.com/public_html/example.pdf');
await browser.close();
})();