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

Method convert_to_pdf

src/__init__.py:4293–4314  ·  view source on GitHub ↗

Convert document to a PDF, selecting page range and optional rotation. Output bytes object.

(self, from_page=0, to_page=-1, rotate=0)

Source from the content-addressed store, hash-verified

4291 self.this = None
4292
4293 def convert_to_pdf(self, from_page=0, to_page=-1, rotate=0):
4294 """Convert document to a PDF, selecting page range and optional rotation. Output bytes object."""
4295 if self.is_closed or self.is_encrypted:
4296 raise ValueError("document closed or encrypted")
4297 fz_doc = self.this
4298 fp = from_page
4299 tp = to_page
4300 srcCount = mupdf.fz_count_pages(fz_doc)
4301 if fp < 0:
4302 fp = 0
4303 if fp > srcCount - 1:
4304 fp = srcCount - 1
4305 if tp < 0:
4306 tp = srcCount - 1
4307 if tp > srcCount - 1:
4308 tp = srcCount - 1
4309 len0 = len(JM_mupdf_warnings_store)
4310 doc = JM_convert_to_pdf(fz_doc, fp, tp, rotate)
4311 len1 = len(JM_mupdf_warnings_store)
4312 for i in range(len0, len1):
4313 message(f'{JM_mupdf_warnings_store[i]}')
4314 return doc
4315
4316 def copy_page(self, pno: int, to: int =-1):
4317 """Copy a page within a PDF document.

Callers 5

__init__Method · 0.95
insert_fileMethod · 0.95
test_insertFunction · 0.80
test_2369Function · 0.80

Calls 2

JM_convert_to_pdfFunction · 0.85
messageFunction · 0.70

Tested by 3

test_insertFunction · 0.64
test_2369Function · 0.64