Text boxes disappear when embedding PDFs
What were you trying to do?
Embed the pages of a PDF into a new, blank PDF.
File being embedded: https://researchtorevenue.files.wordpress.com/2015/04/1r41ai10801601_fong.pdf (saved locally as embed-multi.pdf)
Output file: test-embed-multi-output.pdf
How did you attempt to do it?
import fs from 'fs';
import { PDFDocument, PDFForm, StandardFonts, PDFFont, PageSizes } from 'pdf-lib';
const pdfDoc = await PDFDocument.create();
// Embed PDF pages:
let embedsource = fs.readFileSync('./embed-multi.pdf');
let embedPDF = await PDFDocument.load(embedsource);
for (let i = 0; i < embedPDF.getPageCount(); i++)
{
console.log("Embedding page", i);
let embedded = await pdfDoc.embedPage(embedPDF.getPage(i));
let pg = pdfDoc.addPage(PageSizes.Letter);
pg.drawPage(embedded);
}
fs.writeFileSync('test-embed-multi-output.pdf', await pdfDoc.save());
What actually happened?
The document was embedded, but all Text Boxes in the original embed document were lost.
Screenshot of original embed-multi.pdf: http://is.am/5bwt
Screenshot of test-embed-multi-output.pdf: http://is.am/5bwu
The floating text boxes were gone on the output PDF.
What did you expect to happen?
I expected the embedded document to look identical to the original document being embedded, without losing any components.
How can we reproduce the issue?
Run the code sample attached above.
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
Did you found any workaround for this issue?