Is there an NPM Module for PDF metadata?

2019-07-17 05:26发布

I'm looking for an npm module, that I can use to edit the metatags like Author and Title of PDF files.

Alternatively, an open-license JavaScript library would also be okay.

There's a program called pdftk, which would be suitable if it was an npm module.

2条回答
倾城 Initia
2楼-- · 2019-07-17 06:19

I have not tested this package but node-exiftool seems to provide pdf metadata edition.

Another possibility is to write your own module with use of pdftk (if available) and child_process.
Maybe I will try to make one myself.

查看更多
成全新的幸福
3楼-- · 2019-07-17 06:30

You can install the exiftool command line utility to edit the metadata of PDFs:

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:

'use strict';

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 () => {
  await execute('exiftool -title="Example PDF" -author="John Doe" /var/www/example.com/public_html/example.pdf');
})();
查看更多
登录 后发表回答