-
page duplicate.pdf Hi @gettalong . I need to copy an existing PDF page with AcroForm fields and then rename fields on the copied page, so that new fields may be filled separately from original ones. require 'hexapdf'
pdf = HexaPDF::Document.open('page duplicate.pdf')
page = pdf.pages[0]
(1 .. 2).each do |idx|
# page.value.update(page.copy_inherited_values)
copy_page = page.deep_copy
field = copy_page[:Annots].find { |annot| annot[:Subtype] == :Widget && annot[:T].start_with?('name_') }
field[:T] = "name_#{idx}"
pdf.catalog[:Pages].insert_page(page.index + idx, copy_page)
end
pdf.write('page duplicate result 1.pdf') The resulting PDF contains three pages, with text fields, but when I fill in text field on the first page, fields on second and third page also get filled with the same value, despite that we tried to rename those fields when copying page. How may i fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
So, that's currently not so easy to do. The I will have to think about how to achieve this. |
Beta Was this translation helpful? Give feedback.
-
It woks, thanks! |
Beta Was this translation helpful? Give feedback.
So, the following will do the trick:
Since the importer doesn't currently expose a possibility to forget a certain destination document object, we need to manually delete it. I will maybe add a
HexaPDF::Importer.forget(pdf)
…