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

Method _embfile_add

src/__init__.py:3605–3634  ·  view source on GitHub ↗
(self, name, buffer_, filename=None, ufilename=None, desc=None)

Source from the content-addressed store, hash-verified

3603 return idx
3604
3605 def _embfile_add(self, name, buffer_, filename=None, ufilename=None, desc=None):
3606 pdf = _as_pdf_document(self)
3607 data = JM_BufferFromBytes(buffer_)
3608 if not data.m_internal:
3609 raise TypeError( MSG_BAD_BUFFER)
3610
3611 names = mupdf.pdf_dict_getl(
3612 mupdf.pdf_trailer(pdf),
3613 PDF_NAME('Root'),
3614 PDF_NAME('Names'),
3615 PDF_NAME('EmbeddedFiles'),
3616 PDF_NAME('Names'),
3617 )
3618 if not mupdf.pdf_is_array(names):
3619 root = mupdf.pdf_dict_get(mupdf.pdf_trailer(pdf), PDF_NAME('Root'))
3620 names = mupdf.pdf_new_array(pdf, 6) # an even number!
3621 mupdf.pdf_dict_putl(
3622 root,
3623 names,
3624 PDF_NAME('Names'),
3625 PDF_NAME('EmbeddedFiles'),
3626 PDF_NAME('Names'),
3627 )
3628 fileentry = JM_embed_file(pdf, data, filename, ufilename, desc, 1)
3629 xref = mupdf.pdf_to_num(
3630 mupdf.pdf_dict_getl(fileentry, PDF_NAME('EF'), PDF_NAME('F'))
3631 )
3632 mupdf.pdf_array_push(names, mupdf.pdf_new_text_string(name))
3633 mupdf.pdf_array_push(names, fileentry)
3634 return xref
3635
3636 def _embfile_del(self, idx):
3637 pdf = _as_pdf_document(self)

Callers 1

embfile_addMethod · 0.95

Calls 5

_as_pdf_documentFunction · 0.85
JM_BufferFromBytesFunction · 0.85
PDF_NAMEFunction · 0.85
JM_embed_fileFunction · 0.85
pdf_trailerMethod · 0.80

Tested by

no test coverage detected