Insert widgets of copied page range into target PDF. Parameter values **must** equal those of method insert_pdf() which must have been previously executed.
(
tar: 'Document',
src: 'Document',
graftmap,
from_page: int = -1,
to_page: int = -1,
start_at: int = -1,
join_duplicates=0,
)
| 3252 | #log( 'utils.do_links() returning.') |
| 3253 | |
| 3254 | def _do_widgets( |
| 3255 | tar: 'Document', |
| 3256 | src: 'Document', |
| 3257 | graftmap, |
| 3258 | from_page: int = -1, |
| 3259 | to_page: int = -1, |
| 3260 | start_at: int = -1, |
| 3261 | join_duplicates=0, |
| 3262 | ) -> None: |
| 3263 | """Insert widgets of copied page range into target PDF. |
| 3264 | |
| 3265 | Parameter values **must** equal those of method insert_pdf() which |
| 3266 | must have been previously executed. |
| 3267 | """ |
| 3268 | if not src.is_form_pdf: # nothing to do: source PDF has no fields |
| 3269 | return |
| 3270 | |
| 3271 | def clean_kid_parents(acro_fields): |
| 3272 | """ Make sure all kids have correct "Parent" pointers.""" |
| 3273 | for i in range(acro_fields.pdf_array_len()): |
| 3274 | parent = acro_fields.pdf_array_get(i) |
| 3275 | kids = parent.pdf_dict_get(PDF_NAME("Kids")) |
| 3276 | for j in range(kids.pdf_array_len()): |
| 3277 | kid = kids.pdf_array_get(j) |
| 3278 | kid.pdf_dict_put(PDF_NAME("Parent"), parent) |
| 3279 | |
| 3280 | def join_widgets(pdf, acro_fields, xref1, xref2, name): |
| 3281 | """Called for each pair of widgets having the same name. |
| 3282 | |
| 3283 | Args: |
| 3284 | pdf: target MuPDF document |
| 3285 | acro_fields: object Root/AcroForm/Fields |
| 3286 | xref1, xref2: widget xrefs having same names |
| 3287 | name: (str) the name |
| 3288 | |
| 3289 | Result: |
| 3290 | Defined or updated widget parent that points to both widgets. |
| 3291 | """ |
| 3292 | |
| 3293 | def re_target(pdf, acro_fields, xref1, kids1, xref2, kids2): |
| 3294 | """Merge widget in xref2 into "Kids" list of widget xref1. |
| 3295 | |
| 3296 | Args: |
| 3297 | xref1, kids1: target widget and its "Kids" array. |
| 3298 | xref2, kids2: source wwidget and its "Kids" array (may be empty). |
| 3299 | """ |
| 3300 | # make indirect objects from widgets |
| 3301 | w1_ind = mupdf.pdf_new_indirect(pdf, xref1, 0) |
| 3302 | w2_ind = mupdf.pdf_new_indirect(pdf, xref2, 0) |
| 3303 | # find source widget in "Fields" array |
| 3304 | idx = acro_fields.pdf_array_find(w2_ind) |
| 3305 | acro_fields.pdf_array_delete(idx) |
| 3306 | |
| 3307 | if not kids2.pdf_is_array(): # source widget has no kids |
| 3308 | widget = mupdf.pdf_load_object(pdf, xref2) |
| 3309 | |
| 3310 | # delete name from widget and insert target as parent |
| 3311 | widget.pdf_dict_del(PDF_NAME("T")) |
no test coverage detected