3

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.

Scriptim
  • 1,743
  • 2
  • 20
  • 37

3 Answers3

4

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.

TGrif
  • 5,725
  • 9
  • 31
  • 52
1

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');
})();
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
  • Thank you, however I think node-exiftool, as suggested in @TGrif's answer, which wraps exiftool is much more convenient. – Scriptim Jul 23 '18 at 23:12
0

Can use https://www.npmjs.com/package/pdf-lib

import { PDFDocument } from 'pdf-lib';
const arrayBuffer = await readFile(file);
const pdf = await PDFDocument.load(arrayBuffer);
const pageCount = pdf.getPagesCount();

You have following fucntions to get the meta data from the PDF file. Ref: https://pdf-lib.js.org/docs/api/classes/pdfdocument

getAuthor
getCreationDate
getCreator
getForm
getKeywords
getModificationDate
getPage
getPageCount
getPageIndices
getPages
getProducer
getSubject
getTitle
Adarsh Madrecha
  • 6,364
  • 11
  • 69
  • 117