最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there an NPM Module for PDF metadata? - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Jul 23, 2018 at 23:11 Scriptim asked Dec 28, 2016 at 20:25 ScriptimScriptim 1,8322 gold badges23 silver badges38 bronze badges 4
  • stackoverflow./questions/30945445/… – Sumeet Kumar Yadav Commented Dec 28, 2016 at 20:34
  • Have you tried something ? – TGrif Commented Dec 28, 2016 at 21:06
  • @Sumeet that doesn't seem to answer my question – Scriptim Commented Dec 28, 2016 at 21:08
  • @TGrif Well, I've been searching for an appropriate library for a few days, but I can't find one. – Scriptim Commented Dec 28, 2016 at 21:09
Add a ment  | 

3 Answers 3

Reset to default 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.

Can use https://www.npmjs./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/docs/api/classes/pdfdocument

getAuthor
getCreationDate
getCreator
getForm
getKeywords
getModificationDate
getPage
getPageCount
getPageIndices
getPages
getProducer
getSubject
getTitle

You can install the exiftool mand 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 mand line utility from your program:

'use strict';

const exec = require('util').promisify(require('child_process').exec);

const execute = async mand => {
  const {stdout, stderr} = await exec(mand);

  console.log((stderr || stdout).trim());
};

(async () => {
  await execute('exiftool -title="Example PDF" -author="John Doe" /var/www/example./public_html/example.pdf');
})();
发布评论

评论列表(0)

  1. 暂无评论