2

I'm not having any luck with pyPDF2 or PDFMiner. The tools always return _______________ for the textboxes even if they are filled in. Does anyone have any idea on how to extract the text within the textbox fields?

2

1 Answer 1

0

You need to extract text fields, not a text. So you need something like this:

import sys
import six
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdftypes import resolve1

fp = open("c:\\tmp\\test.pdf", "rb")

parser = PDFParser(fp)
doc = PDFDocument(parser)
fields = resolve1(doc.catalog["AcroForm"])["Fields"]
for i in fields:
    field = resolve1(i)
    name, value = field.get("T"), field.get("V")
    print ("{0}:{1}".format(name,value))
Sign up to request clarification or add additional context in comments.

1 Comment

it didnt work for me and made KeyError: 'AcroForm' error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.