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

Function JM_insert_contents

src/__init__.py:20318–20345  ·  view source on GitHub ↗

Insert a buffer as a new separate /Contents object of a page. 1. Create a new stream object from buffer 'newcont' 2. If /Contents already is an array, then just prepend or append this object 3. Else, create new array and put old content obj and this object into it. If the pag

(pdf, pageref, newcont, overlay)

Source from the content-addressed store, hash-verified

20316
20317
20318def JM_insert_contents(pdf, pageref, newcont, overlay):
20319 '''
20320 Insert a buffer as a new separate /Contents object of a page.
20321 1. Create a new stream object from buffer 'newcont'
20322 2. If /Contents already is an array, then just prepend or append this object
20323 3. Else, create new array and put old content obj and this object into it.
20324 If the page had no /Contents before, just create a 1-item array.
20325 '''
20326 contents = mupdf.pdf_dict_get(pageref, PDF_NAME('Contents'))
20327 newconts = mupdf.pdf_add_stream(pdf, newcont, mupdf.PdfObj(), 0)
20328 xref = mupdf.pdf_to_num(newconts)
20329 if mupdf.pdf_is_array(contents):
20330 if overlay: # append new object
20331 mupdf.pdf_array_push(contents, newconts)
20332 else: # prepend new object
20333 mupdf.pdf_array_insert(contents, newconts, 0)
20334 else:
20335 carr = mupdf.pdf_new_array(pdf, 5)
20336 if overlay:
20337 if contents.m_internal:
20338 mupdf.pdf_array_push(carr, contents)
20339 mupdf.pdf_array_push(carr, newconts)
20340 else:
20341 mupdf.pdf_array_push(carr, newconts)
20342 if contents.m_internal:
20343 mupdf.pdf_array_push(carr, contents)
20344 mupdf.pdf_dict_put(pageref, PDF_NAME('Contents'), carr)
20345 return xref
20346
20347
20348def JM_insert_font(pdf, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering):

Callers 3

_insert_imageMethod · 0.85
_show_pdf_pageMethod · 0.85
_insert_contentsMethod · 0.85

Calls 1

PDF_NAMEFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…