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

Method fullcopy_page

src/__init__.py:4686–4740  ·  view source on GitHub ↗

Make a full page duplicate.

(self, pno, to=-1)

Source from the content-addressed store, hash-verified

4684 return location.chapter, location.page
4685
4686 def fullcopy_page(self, pno, to=-1):
4687 """Make a full page duplicate."""
4688 pdf = _as_pdf_document(self)
4689 page_count = mupdf.pdf_count_pages( pdf)
4690 try:
4691 if (not _INRANGE(pno, 0, page_count - 1)
4692 or not _INRANGE(to, -1, page_count - 1)
4693 ):
4694 raise ValueError( MSG_BAD_PAGENO)
4695
4696 page1 = mupdf.pdf_resolve_indirect( mupdf.pdf_lookup_page_obj( pdf, pno))
4697
4698 page2 = mupdf.pdf_deep_copy_obj( page1)
4699 old_annots = mupdf.pdf_dict_get( page2, PDF_NAME('Annots'))
4700
4701 # copy annotations, but remove Popup and IRT types
4702 if old_annots.m_internal:
4703 n = mupdf.pdf_array_len( old_annots)
4704 new_annots = mupdf.pdf_new_array( pdf, n)
4705 for i in range(n):
4706 o = mupdf.pdf_array_get( old_annots, i)
4707 subtype = mupdf.pdf_dict_get( o, PDF_NAME('Subtype'))
4708 if mupdf.pdf_name_eq( subtype, PDF_NAME('Popup')):
4709 continue
4710 if mupdf.pdf_dict_gets( o, "IRT").m_internal:
4711 continue
4712 copy_o = mupdf.pdf_deep_copy_obj( mupdf.pdf_resolve_indirect( o))
4713 xref = mupdf.pdf_create_object( pdf)
4714 mupdf.pdf_update_object( pdf, xref, copy_o)
4715 copy_o = mupdf.pdf_new_indirect( pdf, xref, 0)
4716 mupdf.pdf_dict_del( copy_o, PDF_NAME('Popup'))
4717 mupdf.pdf_dict_del( copy_o, PDF_NAME('P'))
4718 mupdf.pdf_array_push( new_annots, copy_o)
4719 mupdf.pdf_dict_put( page2, PDF_NAME('Annots'), new_annots)
4720
4721 # copy the old contents stream(s)
4722 res = JM_read_contents( page1)
4723
4724 # create new /Contents object for page2
4725 if res and res.m_internal:
4726 #contents = mupdf.pdf_add_stream( pdf, mupdf.fz_new_buffer_from_copied_data( b" ", 1), NULL, 0)
4727 contents = mupdf.pdf_add_stream( pdf, mupdf.fz_new_buffer_from_copied_data( b" "), mupdf.PdfObj(), 0)
4728 JM_update_stream( pdf, contents, res, 1)
4729 mupdf.pdf_dict_put( page2, PDF_NAME('Contents'), contents)
4730
4731 # now insert target page, making sure it is an indirect object
4732 xref = mupdf.pdf_create_object( pdf) # get new xref
4733 mupdf.pdf_update_object( pdf, xref, page2) # store new page
4734
4735 page2 = mupdf.pdf_new_indirect( pdf, xref, 0) # reread object
4736 mupdf.pdf_insert_page( pdf, to, page2) # and store the page
4737 finally:
4738 mupdf.ll_pdf_drop_page_tree( pdf.m_internal)
4739
4740 self._reset_page_refs()
4741
4742 def get_char_widths(
4743 doc: 'Document',

Callers 2

test_deletionFunction · 0.80
test_4043Function · 0.80

Calls 6

_reset_page_refsMethod · 0.95
_as_pdf_documentFunction · 0.85
_INRANGEFunction · 0.85
PDF_NAMEFunction · 0.85
JM_read_contentsFunction · 0.85
JM_update_streamFunction · 0.85

Tested by 2

test_deletionFunction · 0.64
test_4043Function · 0.64