Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support deep copies for PageObject (Duplicated Pages Overwrite Original Page’s Data) #3171

Open
Labels
@kamranbadirov

Description

@kamranbadirov

Description

When duplicating a page from a PdfReader using copy.deepcopy and adding it to a PdfWriter with writer.add_page, the duplicated page unexpectedly modifies the original page it was duplicated from.

For example, given Page1 with form fields FirstName and LastName initially set to "John" and "Smith":
1.Page2 is created as a duplicate and set to "Boris" and "Norris".
2.In the generated PDF, all instances of FirstName and LastName (including Page1 and Page2) incorrectly contain "Boris" and "Norris", instead of retaining their respective values.

This suggests that the form field references are not properly isolated between the original and duplicated pages.


Environment

$ python -m platformmacOS-14.7.4-arm64-arm-64bit$ python -c"import pypdf;print(pypdf._debug_versions)"pypdf==5.3.0, crypt_provider=('local_crypt_fallback','0.0.0'), PIL=none

Code + PDF

This is a minimal, complete example that shows the issue:

frompypdfimportPdfReader,PdfWriterfromcopyimportdeepcopypdf_path="template.pdf"# Replace with your PDF file pathreader=PdfReader(pdf_path)writer=PdfWriter(clone_from=reader)writer.update_page_form_field_values(writer.pages[0], {"FirstName":"John","LastName":"Smith"})# Add a duplicated pageduplicated_page=writer.add_page(deepcopy(reader.pages[0]))writer.update_page_form_field_values(duplicated_page,  {"FirstName":"Boris","LastName":"Norris"})withopen("output.pdf","wb")asoutput_file:writer.write(output_file)

Expected Behavior

Each duplicated page should maintain its own independent form field values:
•Page1 → "John" / "Smith"
•Page2 → "Boris" / "Norris"


Actual Behavior

All instances of FirstName and LastName fields across pages end up displaying "Boris" and "Norris", indicating that form field values are not isolated between duplicated pages.


Attachments
•Template PDF:template.pdf
•Generated PDF with Issue:output.pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp