Copy form from one pdf to another #3702
Unanswered
cmyers009
asked this question in
Looking for help
Replies: 1 comment 2 replies
-
I would not rely on this working ever. Radio buttons usually come in groups with a mechanism that automatically switches off all other radio buttons in the group when one button is switched on. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes a pdf is a form pdf which has widgets.
I want to be able to copy the widgets from one PDF to another.
I am able to do this successfully for certain types of widgets (type 1, 2, 3, 4, and most of the time 7) but my method does not work for radio groups (type 5)
Why does it not work for these? Is there something I can change to make this work?
Is there any risks with my current implementation, if I was to support types 1, 2, and 7 but not support type 5.
Lastly, I found that sometimes PDF forms of type '7' (text) may have images embedded in the text. Copying the form text field over this way does not seem to work, and the image gets deleted.
radios_input.pdf
radios_output.pdf
Here is an example of a PDF that works (does not contain type 5)
Widget_example_2.pdf
ValueError: bad xref Traceback (most recent call last): File "c:\users\XXX\desktop\test_pdf\copy_widgets.py", line 32, in copy_pdf_with_forms dst_widget = dst_page.add_widget(src_widget) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\XXX\anaconda3\Lib\site-packages\pymupdf\__init__.py", line 8448, in add_widget widget.update() File "C:\Users\XXX\anaconda3\Lib\site-packages\pymupdf\__init__.py", line 7142, in update self._validate() File "C:\Users\XXX\anaconda3\Lib\site-packages\pymupdf\__init__.py", line 7056, in _validate self._checker() # any field_type specific checks ^^^^^^^^^^^^^^^ File "C:\Users\XXX\anaconda3\Lib\site-packages\pymupdf\__init__.py", line 6947, in _checker kids_type, kids_value = doc.xref_get_key(self.xref, "Parent/Kids") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\XXX\anaconda3\Lib\site-packages\pymupdf\__init__.py", line 5787, in xref_get_key raise ValueError( MSG_BAD_XREF) ValueError: bad xref
Beta Was this translation helpful? Give feedback.
All reactions