| 6442 | return dest_dict |
| 6443 | |
| 6444 | def save( |
| 6445 | self, |
| 6446 | filename, |
| 6447 | garbage=0, |
| 6448 | clean=0, |
| 6449 | deflate=0, |
| 6450 | deflate_images=0, |
| 6451 | deflate_fonts=0, |
| 6452 | incremental=0, |
| 6453 | ascii=0, |
| 6454 | expand=0, |
| 6455 | linear=0, |
| 6456 | no_new_id=0, |
| 6457 | appearance=0, |
| 6458 | pretty=0, |
| 6459 | encryption=1, |
| 6460 | permissions=4095, |
| 6461 | owner_pw=None, |
| 6462 | user_pw=None, |
| 6463 | preserve_metadata=1, |
| 6464 | use_objstms=0, |
| 6465 | compression_effort=0, |
| 6466 | raise_on_repair=False, |
| 6467 | ): |
| 6468 | # From %pythonprepend save |
| 6469 | # |
| 6470 | is_repaired_pre = self.is_repaired |
| 6471 | """Save PDF to file, pathlib.Path or file pointer.""" |
| 6472 | if self.is_closed or self.is_encrypted: |
| 6473 | raise ValueError("document closed or encrypted") |
| 6474 | if type(filename) is str: |
| 6475 | pass |
| 6476 | elif hasattr(filename, "open"): # assume: pathlib.Path |
| 6477 | filename = str(filename) |
| 6478 | elif hasattr(filename, "name"): # assume: file object |
| 6479 | filename = filename.name |
| 6480 | elif not hasattr(filename, "seek"): # assume file object |
| 6481 | raise ValueError("filename must be str, Path or file object") |
| 6482 | if filename == self.name and not incremental: |
| 6483 | raise ValueError("save to original must be incremental") |
| 6484 | if linear and use_objstms: |
| 6485 | raise ValueError("'linear' and 'use_objstms' cannot both be requested") |
| 6486 | if self.page_count < 1: |
| 6487 | raise ValueError("cannot save with zero pages") |
| 6488 | if incremental: |
| 6489 | if self.name != filename or self.stream: |
| 6490 | raise ValueError("incremental needs original file") |
| 6491 | if user_pw and len(user_pw) > 40 or owner_pw and len(owner_pw) > 40: |
| 6492 | raise ValueError("password length must not exceed 40") |
| 6493 | |
| 6494 | pdf = _as_pdf_document(self) |
| 6495 | opts = mupdf.PdfWriteOptions() |
| 6496 | opts.do_incremental = incremental |
| 6497 | opts.do_ascii = ascii |
| 6498 | opts.do_compress = deflate |
| 6499 | opts.do_compress_images = deflate_images |
| 6500 | opts.do_compress_fonts = deflate_fonts |
| 6501 | opts.do_decompress = expand |