Skip to content

getCreationDate & getModificationDate #1477

Answered by akomm
akomm asked this question in Q&A
Discussion options

You must be logged in to vote

I figured out the /CreationDate and /ModDate end up in the indirectObjects list. I assume because they don't get associated with the trailer -> Info.

Currently I workaround it:

import {
  PDFDict,
  PDFDocument,
  PDFHexString,
  PDFName,
  PDFObject,
  PDFString
} from "pdf-lib"

function getDates(doc: PDFDocument) {
  const cdate = doc.getCreationDate()
  const mdate = cdate && doc.getModificationDate()

  if (cdate) {
    return {cdate, mdate}
  }

  // see https://github.com/Hopding/pdf-lib/discussions/1477
  const alt = (() => {
    function tryParseDate(obj?: PDFObject) {
      if (obj instanceof PDFString || obj instanceof PDFHexString) {
        return obj.decodeDate()
      }
    }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by akomm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant