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

Function embedded_upd

src/__main__.py:402–449  ·  view source on GitHub ↗

Update contents or metadata of an embedded file.

(args)

Source from the content-addressed store, hash-verified

400
401
402def embedded_upd(args):
403 """Update contents or metadata of an embedded file."""
404 doc = open_file(args.input, args.password, pdf=True)
405 if not doc.can_save_incrementally() and (
406 args.output is None or args.output == args.input
407 ):
408 sys.exit("cannot save PDF incrementally")
409
410 try:
411 doc.embfile_info(args.name)
412 except Exception:
413 sys.exit(f"no such embedded file '{args.name}'")
414
415 if (
416 args.path is not None
417 and os.path.exists(args.path)
418 and os.path.isfile(args.path)
419 ):
420 with open(args.path, "rb") as f:
421 stream = f.read()
422 else:
423 stream = None
424
425 if args.filename:
426 filename = args.filename
427 else:
428 filename = None
429
430 if args.ufilename:
431 ufilename = args.ufilename
432 elif args.filename:
433 ufilename = args.filename
434 else:
435 ufilename = None
436
437 if args.desc:
438 desc = args.desc
439 else:
440 desc = None
441
442 doc.embfile_upd(
443 args.name, stream, filename=filename, ufilename=ufilename, desc=desc
444 )
445 if args.output is None or args.output == args.input:
446 doc.saveIncr()
447 else:
448 doc.save(args.output, garbage=3)
449 doc.close()
450
451
452def embedded_list(args):

Callers

nothing calls this directly

Calls 7

embfile_infoMethod · 0.80
embfile_updMethod · 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…