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

Function embedded_add

src/__main__.py:368–399  ·  view source on GitHub ↗

Insert a new embedded file.

(args)

Source from the content-addressed store, hash-verified

366
367
368def embedded_add(args):
369 """Insert a new embedded file."""
370 doc = open_file(args.input, args.password, pdf=True)
371 if not doc.can_save_incrementally() and (
372 args.output is None or args.output == args.input
373 ):
374 sys.exit("cannot save PDF incrementally")
375
376 try:
377 doc.embfile_del(args.name)
378 sys.exit(f"entry '{args.name}' already exists")
379 except Exception:
380 pass
381
382 if not os.path.exists(args.path) or not os.path.isfile(args.path):
383 sys.exit(f"no such file '{args.path}'")
384 with open(args.path, "rb") as f:
385 stream = f.read()
386 filename = args.path
387 ufilename = filename
388 if not args.desc:
389 desc = filename
390 else:
391 desc = args.desc
392 doc.embfile_add(
393 args.name, stream, filename=filename, ufilename=ufilename, desc=desc
394 )
395 if not args.output or args.output == args.input:
396 doc.saveIncr()
397 else:
398 doc.save(args.output, garbage=3)
399 doc.close()
400
401
402def embedded_upd(args):

Callers

nothing calls this directly

Calls 7

embfile_delMethod · 0.80
embfile_addMethod · 0.80
saveIncrMethod · 0.80
open_fileFunction · 0.70
saveMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…