You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to copy a pdf page and insert it into the same document as many times as I need.
This page has fields that were defined on page 1 to span across pages 1 and 2. I want to increase that span to any page that is copied.
I'm currently using this logic to do so:
const copied = pdfDoc.copyPages(originalPdf, [1]);
const newPage = copied[0]
pdfDoc.insertPage(i, newPage) // Where i represents the iteration of how many pages I'm adding
// Copy fields from second page to new page
for (const field of fields) {
// If a field has a "Kids" key, I'm assuming the field spans multiple pages
if (field.acroField.Kids()) {
const kids = f.acroField.Kids();
const widgets = field.acroField.getWidgets();
const clone = widgets[widgets.length - 1].dict.clone(f.acroField.dict.context);
clone.set(PDFName.of('P'), newPage.ref);
const registeredRef = pdf.context.register(clone);
kids.set(kids.array.length, registeredRef);
// The following throws "Expected instance of PDFDict or PDFStream, but got instance of undefined when I run the code a second time"
const f = form.getField(f.getName());
f.acroField.setKids(kids);
// The following works every time, but doesn't seem right to assign an existing field object to another variable and modify properties
const f = field;
f.acroField.setKids(kids);
// If I try to run this, it throws "Expected instance of PDFDict, but got instance of PDFRawStream" when I run it a second time
f.updateAppearances(font)
}
}
pdfDoc.getForm().acroForm.dict.set(PDFName.of('NeedAppearances'), PDFBool.True);
The PDF will save and the values of the fields from the first page span the subsequent pages, however, when I try to flatten it, only the first page flattens.
There's one field on the subsequent pages that is different from all the others that span the other pages. I add it using this logic:
const newField = form.createTextField(field.getName() + '_' + (i + 1)) // Where i represents the iteration of the page the field is being added onto
newField.addToPage(newPage, options)
newField.setFontSize(10)
newField.enableMultiline()
newField.disableReadOnly()
newField.setText(pageTexts[i])
newField.updateAppearances(font)
This weird thing with this is, if I open the PDF in chrome, I can't edit the text that was added to the field. The text field was added and the text was added, but it appears as though the text was drawn behind the text field. I can click in the field and type, but it just types on top of the text that displays. If I open it up in adobe it behaves normally and I can modify the text in the field.
When I flatten the saved PDF, only the first page gets flattened. On all subsequent pages, for the fields that span multiple pages, the text is just gone. On the fields that I added, the text is faded, but I can still click in the field and modify it.
I couldn't find any support on handling fields across multiple pages so I'm sure whatever I'm doing is causing all my grief. I'm hoping someone can point me to the right direction.
I apologize that I can't post the PDF that I'm using as it's proprietary, but if you really need an example I can try to create one and take screenshots of what I'm explaining.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to copy a pdf page and insert it into the same document as many times as I need.
This page has fields that were defined on page 1 to span across pages 1 and 2. I want to increase that span to any page that is copied.
I'm currently using this logic to do so:
The PDF will save and the values of the fields from the first page span the subsequent pages, however, when I try to flatten it, only the first page flattens.
There's one field on the subsequent pages that is different from all the others that span the other pages. I add it using this logic:
This weird thing with this is, if I open the PDF in chrome, I can't edit the text that was added to the field. The text field was added and the text was added, but it appears as though the text was drawn behind the text field. I can click in the field and type, but it just types on top of the text that displays. If I open it up in adobe it behaves normally and I can modify the text in the field.
When I flatten the saved PDF, only the first page gets flattened. On all subsequent pages, for the fields that span multiple pages, the text is just gone. On the fields that I added, the text is faded, but I can still click in the field and modify it.
I couldn't find any support on handling fields across multiple pages so I'm sure whatever I'm doing is causing all my grief. I'm hoping someone can point me to the right direction.
I apologize that I can't post the PDF that I'm using as it's proprietary, but if you really need an example I can try to create one and take screenshots of what I'm explaining.
Beta Was this translation helpful? Give feedback.
All reactions