Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result for PDFDocument#getProducer #1571

Open
2 tasks done
madtrick opened this issue Dec 13, 2023 · 0 comments
Open
2 tasks done

Incorrect result for PDFDocument#getProducer #1571

madtrick opened this issue Dec 13, 2023 · 0 comments

Comments

@madtrick
Copy link

What were you trying to do?

I'm reading the document producer after setting a custom value for it.

How did you attempt to do it?

First:

pdf.setProducer('html2read2pdf')

Then, in a different place, after loading the file from disk:

pdf.getProducer()

What actually happened?

If I load the document and read its Producer metadata property the value I get is pdf-lib (https://github.com/Hopding/pdf-lib) instead of the one I set with PDFDocument#setProducer

However if I open the resulting PDF with a viewer like Mac Preview or PDF Expert I see the expected custom value

image
image

What did you expect to happen?

I see the Producer I set

How can we reproduce the issue?

import { readFile, writeFile } from 'fs/promises'
import { PDFDocument } from 'pdf-lib'
import { resolve } from 'path'

async function main(): Promise<void> {
  const bytes = await readFile(
    resolve(__dirname, './sample.pdf'),
  )
  const pdf = await PDFDocument.load(bytes)
  pdf.setProducer('html2read2pdf/v1')

  await writeFile(
    resolve(__dirname, './document-with-metadata.pdf'),
    await pdf.save(),
  )

  const pdf2 = await PDFDocument.load(
    await readFile(resolve(__dirname, './document-with-metadata.pdf')),
  )

  console.log(pdf2.getProducer())
}

void main()

sample.pdf

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant