Define command configurations.
()
| 835 | |
| 836 | |
| 837 | def main(): |
| 838 | """Define command configurations.""" |
| 839 | parser = argparse.ArgumentParser( |
| 840 | prog="fitz", |
| 841 | description=mycenter("Basic PyMuPDF Functions"), |
| 842 | ) |
| 843 | subps = parser.add_subparsers( |
| 844 | title="Subcommands", help="Enter 'command -h' for subcommand specific help" |
| 845 | ) |
| 846 | |
| 847 | # ------------------------------------------------------------------------- |
| 848 | # 'show' command |
| 849 | # ------------------------------------------------------------------------- |
| 850 | ps_show = subps.add_parser("show", description=mycenter("display PDF information")) |
| 851 | ps_show.add_argument("input", type=str, help="PDF filename") |
| 852 | ps_show.add_argument("-password", help="password") |
| 853 | ps_show.add_argument("-catalog", action="store_true", help="show PDF catalog") |
| 854 | ps_show.add_argument("-trailer", action="store_true", help="show PDF trailer") |
| 855 | ps_show.add_argument("-metadata", action="store_true", help="show PDF metadata") |
| 856 | ps_show.add_argument( |
| 857 | "-xrefs", type=str, help="show selected objects, format: 1,5-7,N" |
| 858 | ) |
| 859 | ps_show.add_argument( |
| 860 | "-pages", type=str, help="show selected pages, format: 1,5-7,50-N" |
| 861 | ) |
| 862 | ps_show.set_defaults(func=show) |
| 863 | |
| 864 | # ------------------------------------------------------------------------- |
| 865 | # 'clean' command |
| 866 | # ------------------------------------------------------------------------- |
| 867 | ps_clean = subps.add_parser( |
| 868 | "clean", description=mycenter("optimize PDF, or create sub-PDF if pages given") |
| 869 | ) |
| 870 | ps_clean.add_argument("input", type=str, help="PDF filename") |
| 871 | ps_clean.add_argument("output", type=str, help="output PDF filename") |
| 872 | ps_clean.add_argument("-password", help="password") |
| 873 | |
| 874 | ps_clean.add_argument( |
| 875 | "-encryption", |
| 876 | help="encryption method", |
| 877 | choices=("keep", "none", "rc4-40", "rc4-128", "aes-128", "aes-256"), |
| 878 | default="none", |
| 879 | ) |
| 880 | |
| 881 | ps_clean.add_argument("-owner", type=str, help="owner password") |
| 882 | ps_clean.add_argument("-user", type=str, help="user password") |
| 883 | |
| 884 | ps_clean.add_argument( |
| 885 | "-garbage", |
| 886 | type=int, |
| 887 | help="garbage collection level", |
| 888 | choices=range(5), |
| 889 | default=0, |
| 890 | ) |
| 891 | |
| 892 | ps_clean.add_argument( |
| 893 | "-compress", |
| 894 | action="store_true", |
no test coverage detected
searching dependent graphs…