pdf-lib
pdf-lib copied to clipboard
Incorrect result for PDFDocument#getProducer
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
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()
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
- [X] I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response