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

Method insert_file

src/__init__.py:5315–5356  ·  view source on GitHub ↗

Insert an arbitrary supported document to an existing PDF. The infile may be given as a filename, a Document or a Pixmap. Other parameters - where applicable - equal those of insert_pdf().

(self,
            infile,
            from_page=-1,
            to_page=-1,
            start_at=-1,
            rotate=-1,
            links=True,
            annots=True,
            show_progress=0,
            final=1,
            )

Source from the content-addressed store, hash-verified

5313 self.metadata['encryption'] = None if self._getMetadata('encryption')=='None' else self._getMetadata('encryption')
5314
5315 def insert_file(self,
5316 infile,
5317 from_page=-1,
5318 to_page=-1,
5319 start_at=-1,
5320 rotate=-1,
5321 links=True,
5322 annots=True,
5323 show_progress=0,
5324 final=1,
5325 ):
5326 '''
5327 Insert an arbitrary supported document to an existing PDF.
5328
5329 The infile may be given as a filename, a Document or a Pixmap. Other
5330 parameters - where applicable - equal those of insert_pdf().
5331 '''
5332 src = None
5333 if isinstance(infile, Pixmap):
5334 if infile.colorspace.n > 3:
5335 infile = Pixmap(csRGB, infile)
5336 src = Document("png", infile.tobytes())
5337 elif isinstance(infile, Document):
5338 src = infile
5339 else:
5340 src = Document(infile)
5341 if not src:
5342 raise ValueError("bad infile parameter")
5343 if not src.is_pdf:
5344 pdfbytes = src.convert_to_pdf()
5345 src = Document("pdf", pdfbytes)
5346 return self.insert_pdf(
5347 src,
5348 from_page=from_page,
5349 to_page=to_page,
5350 start_at=start_at,
5351 rotate=rotate,
5352 links=links,
5353 annots=annots,
5354 show_progress=show_progress,
5355 final=final,
5356 )
5357
5358 def insert_page(
5359 doc: 'Document',

Callers

nothing calls this directly

Calls 5

tobytesMethod · 0.95
convert_to_pdfMethod · 0.95
insert_pdfMethod · 0.95
PixmapClass · 0.85
DocumentClass · 0.85

Tested by

no test coverage detected