コード例 #1
0
ファイル: pdf_modifier.py プロジェクト: hrb23m/pydifier
    def execute(self):
        pdf = Pdf()

        try:
            pdf.load(self.config.getInputFilePath())
            for effector in self.effectorChain:
                pdf = effector.apply(pdf)

            pdf.save(self.config.getOutputFilePath())
        finally:
            pdf.close()
コード例 #2
0
args = parser.parse_args()

pdf = Pdf().load(args.pdf)

if args.compare:
    other = Pdf().load(args.compare)
    for k, v in pdf.objects.items():
        if k not in other.objects:
            print('===== {} ===== missing from other'.format(k))
        if other.objects[k] != v:
            print(('===== {} =====\n'
                   '{}\n'
                   '\n'
                   '===== other =====\n'
                   '{}').format(k, v, other.objects[k]))
    for k in other.objects.keys():
        if k not in pdf.objects:
            print('===== {} ===== missing'.format(k))
if args.templatify_forms:
    if args.templatify_forms_uniquifier:
        pdf.uniquifier = args.templatify_forms_uniquifier
    pdf.templatify_forms_padding = args.templatify_forms_padding
    pdf.templatify_forms_custom_padding = eval(
        args.templatify_forms_custom_padding)
    pdf.templatify_forms(
        whitelist=[int(i) for i in args.templatify_forms_whitelist.split()],
        remove_dv=args.templatify_forms_remove_dv,
    )
if args.save:
    pdf.save(args.save)
コード例 #3
0
ファイル: anedit.py プロジェクト: igsor/hillie
def anedit(path, target, options):
    """Edit notes from highlights in PDF files.

    All is printed to standard input or standard error.

    Options:
    * options.valid_types   PDF annotation types to process
    * options.use_title     Print filename/document title instead of filename
    * options.filter_keys   Only print stated keys.
    * options.remove_key    Don't print key tags
    * options.verbose       Print varnings

    """
    # FIXME: Who guarantees this method is only executed on valid files?
    # Also check for pusher, hillieo, hilliep, ...

    # wordlist for normalization
    wordlist = Dictionary()

    # open document
    document = Pdf(path, options, pgm=sys.argv[0])

    # fetch notes
    notes = []
    for n_annot, item in enumerate(document.annotations(options)):
        sugg = annotation_fixes(item.note, wordlist, options.verbose)
        notes.append((item, sugg))

    # Walk through notes
    has_changes = False
    while len(notes) > 0:
        item, sugg = notes.pop(0)

        print ""
        print "\033[94m> {}: page {}, ETA {}\033[0m".format(
            item.page[0], item.page[1], len(notes))
        print "Original: ", item.note
        if item.note != sugg:
            print "Suggested:", sugg
        elif options.diffs:
            continue

        valid_answers = 'nyecisq?'
        prompt = '[{}]: '.format('/'.join(valid_answers.title()))
        ans = 'NEIN'
        while ans not in valid_answers:
            ans = raw_input(prompt) \
                .strip() \
                .lower() \
                .replace('yes', 'y') \
                .replace('no', 'n') \
                .replace('quit', 'q') \
                .replace('ignore', 'i') \
                .replace('ign', 'i') \
                .replace('edit', 'e') \
                .replace('correct', 'c') \
                .replace('skip', 's')

            if ans == '':
                ans = valid_answers[0]  # default is 'n'

            if ans == '?':
                ans = 'NEIN'
                print '''Usage:

    n   no      Stick with the original text (the default)
    y   yes     Accept the suggested text
    e   edit    Edit the original text
    c   change  Edit the suggested text
    i   ignore  Ignore for now (again prompted later)
    s   skip    Save and exit
    q   quit    Abort and exit (changes are lost)

                '''

        if ans == 'y':  # Use suggestion
            has_changes = True
            if item.key is None:
                item.set_content(sugg)
            else:
                item.set_content('<{}>{}</{}>'.format(item.key, sugg,
                                                      item.key))
        elif ans == 'n':  # Use original
            pass
        elif ans in ('e', 'c'):  # Edit manually

            def hook():
                curr = ans == 'e' and item.note or sugg
                curr = curr.replace('\n', '\\n')
                readline.insert_text(curr)
                readline.redisplay()

            readline.set_pre_input_hook(hook)
            sugg = raw_input().strip().replace('\\n', '\n')
            readline.set_pre_input_hook(None)
            notes.insert(0, (item, sugg))
        elif ans == 'i':  # Ignore note for now
            notes.append((item, sugg))
        elif ans == 'q':  # Quit immediately, don't save
            return
        elif ans == 's':  # Skip the rest
            break

    # save changes
    if has_changes:
        document.save(target, options)