Update contents or metadata of an embedded file.
(args)
| 400 | |
| 401 | |
| 402 | def 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 | |
| 452 | def embedded_list(args): |
nothing calls this directly
no test coverage detected
searching dependent graphs…