MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / doc_join

Function doc_join

src/__main__.py:267–285  ·  view source on GitHub ↗

Join pages from several PDF documents.

(args)

Source from the content-addressed store, hash-verified

265
266
267def doc_join(args):
268 """Join pages from several PDF documents."""
269 doc_list = args.input # a list of input PDFs
270 doc = pymupdf.open() # output PDF
271 for src_item in doc_list: # process one input PDF
272 src_list = src_item.split(",")
273 password = src_list[1] if len(src_list) > 1 else None
274 src = open_file(src_list[0], password, pdf=True)
275 pages = ",".join(src_list[2:]) # get 'pages' specifications
276 if pages: # if anything there, retrieve a list of desired pages
277 page_list = get_list(",".join(src_list[2:]), src.page_count + 1)
278 else: # take all pages
279 page_list = range(1, src.page_count + 1)
280 for i in page_list:
281 doc.insert_pdf(src, from_page=i - 1, to_page=i - 1) # copy each source page
282 src.close()
283
284 doc.save(args.output, garbage=4, deflate=True)
285 doc.close()
286
287
288def embedded_copy(args):

Callers

nothing calls this directly

Calls 5

insert_pdfMethod · 0.80
open_fileFunction · 0.70
get_listFunction · 0.70
closeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…