0xabu / pdfannots

Extracts and formats text annotations from a PDF file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to start opening the new file?

balandongiv opened this issue · comments

commented

Given absolute path of the pdf file is as follow;

C:\abc.pdf

There are three ways to execute the pdfannots.py`

  1. If you're running pdfannots.py from the command prompt, then you do so as, e.g.,

python pdfannots.py C:\abc.pdf

  1. If you want to run it over multiple PDF files, then you do so as, e.g.,

python pdfannots.py C:\abc.pdf D:\xyz.pdf E:\foo.pdf

3.If you are interested to hard coded the pdf path for of ease debugging/understand the whole code using debugging tools

3.a)

def parse_args():
    p = argparse.ArgumentParser(description=__doc__)

    # p.add_argument("input", metavar="INFILE", type=argparse.FileType("rb"),
                   # help="PDF files to process", nargs='+')

    g = p.add_argument_group('Basic options')
    g.add_argument("-p", "--progress", default=False, action="store_true",
                   help="emit progress information")
    g.add_argument("-o", metavar="OUTFILE", type=argparse.FileType("w"), dest="output",
                   default=sys.stdout, help="output file (default is stdout)")
    g.add_argument("-n", "--cols", default=2, type=int, metavar="COLS", dest="cols",
                   help="number of columns per page in the document (default: 2)")

    g = p.add_argument_group('Options controlling output format')
    allsects = ["highlights", "comments", "nits"]
    g.add_argument("-s", "--sections", metavar="SEC", nargs="*",
                   choices=allsects, default=allsects,
                   help=("sections to emit (default: %s)" % ', '.join(allsects)))
    g.add_argument("--no-group", dest="group", default=True, action="store_false",
                   help="emit annotations in order, don't group into sections")
    g.add_argument("--print-filename", dest="printfilename", default=False, action="store_true",
                   help="print the filename when it has annotations")
    g.add_argument("-w", "--wrap", metavar="COLS", type=int,
                   help="wrap text at this many output columns")

    return p.parse_args()



def main():
    args = parse_args()

    global COLUMNS_PER_PAGE
    COLUMNS_PER_PAGE = args.cols

    for file in [r"C:\abc.pdf"]:
         file = open(file, 'rb')
         (annots, outlines) = process_file(file, args.progress)

        pp = PrettyPrinter(outlines, args.wrap)

        if args.printfilename and annots:
            print("# File: '%s'\n" % file.name)

        if args.group:
            pp.printall_grouped(args.sections, annots, args.output)
        else:
            pp.printall(annots, args.output)

    return 0

Credit to the OP from SO