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,
)
| 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: |