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