Insert a new embedded file.
(args)
| 366 | |
| 367 | |
| 368 | def 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 | |
| 402 | def embedded_upd(args): |
nothing calls this directly
no test coverage detected
searching dependent graphs…