MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / insert_pdf

Method insert_pdf

src/__init__.py:5388–5505  ·  view source on GitHub ↗

Insert a page range from another PDF. Args: docsrc: PDF to copy from. Must be different object, but may be same file. from_page: (int) first source page to copy, 0-based, default 0. to_page: (int) last source page to copy, 0-based, default last page.

(
            self,
            docsrc,
            *,
            from_page=-1,
            to_page=-1,
            start_at=-1,
            rotate=-1,
            links=1,
            annots=1,
            widgets=1,
            join_duplicates=0,
            show_progress=0,
            final=1,
            _gmap=None,
            )

Source from the content-addressed store, hash-verified

5386 return rc
5387
5388 def insert_pdf(
5389 self,
5390 docsrc,
5391 *,
5392 from_page=-1,
5393 to_page=-1,
5394 start_at=-1,
5395 rotate=-1,
5396 links=1,
5397 annots=1,
5398 widgets=1,
5399 join_duplicates=0,
5400 show_progress=0,
5401 final=1,
5402 _gmap=None,
5403 ):
5404 """Insert a page range from another PDF.
5405
5406 Args:
5407 docsrc: PDF to copy from. Must be different object, but may be same file.
5408 from_page: (int) first source page to copy, 0-based, default 0.
5409 to_page: (int) last source page to copy, 0-based, default last page.
5410 start_at: (int) from_page will become this page number in target.
5411 rotate: (int) rotate copied pages, default -1 is no change.
5412 links: (int/bool) whether to also copy links.
5413 annots: (int/bool) whether to also copy annotations.
5414 widgets: (int/bool) whether to also copy form fields.
5415 join_duplicates: (int/bool) join or rename duplicate widget names.
5416 show_progress: (int) progress message interval, 0 is no messages.
5417 final: (bool) indicates last insertion from this source PDF.
5418 _gmap: internal use only
5419
5420 Copy sequence reversed if from_page > to_page."""
5421
5422 # Insert pages from a source PDF into this PDF.
5423 # For reconstructing the links (_do_links method), we must save the
5424 # insertion point (start_at) if it was specified as -1.
5425 #log( 'insert_pdf(): start')
5426 if self.is_closed or self.is_encrypted:
5427 raise ValueError("document closed or encrypted")
5428 if self._graft_id == docsrc._graft_id:
5429 raise ValueError("source and target cannot be same object")
5430 sa = start_at
5431 if sa < 0:
5432 sa = self.page_count
5433 outCount = self.page_count
5434 srcCount = docsrc.page_count
5435
5436 # local copies of page numbers
5437 fp = from_page
5438 tp = to_page
5439 sa = start_at
5440
5441 # normalize page numbers
5442 fp = max(fp, 0) # -1 = first page
5443 fp = min(fp, srcCount - 1) # but do not exceed last page
5444
5445 if tp < 0:

Callers 15

insert_fileMethod · 0.95
_test_insert_adobeFunction · 0.95
cleanFunction · 0.80
doc_joinFunction · 0.80
cleanFunction · 0.80
doc_joinFunction · 0.80
test_2634Function · 0.80
test_4614Function · 0.80
merge_pdfFunction · 0.80
test_insertFunction · 0.80
_2861_2871_merge_pdfFunction · 0.80

Calls 9

_reset_page_refsMethod · 0.95
_do_linksMethod · 0.95
_do_widgetsMethod · 0.95
GraftmapClass · 0.85
_as_pdf_documentFunction · 0.85
ENSURE_OPERATIONFunction · 0.85
JM_merge_rangeFunction · 0.85
messageFunction · 0.70
getMethod · 0.45

Tested by 13

_test_insert_adobeFunction · 0.76
test_2634Function · 0.64
test_4614Function · 0.64
merge_pdfFunction · 0.64
test_insertFunction · 0.64
_2861_2871_merge_pdfFunction · 0.64
test_3789Function · 0.64
test_widget_insertFunction · 0.64
test_merge_checks1Function · 0.64
test_merge_checks2Function · 0.64
test_4412Function · 0.64