ClassFormatError: Invalid method Code length 85551 in class file pdfminer/glyphlist$py

722 views Asked by At

I am running an acceptance test from Command Line, which internally calls pdfminer python script method for conversion of Pdf into Text. I have provided the PDF2TextLibrary which has the code to convert Pdf into text using pdfminer library.

But while I run the test i get the error :

ClassFormatError: Invalid method Code length 85551 in class file pdfminer/glyphlist$py
2

There are 2 answers

0
Vills On

The issue was resolved by dividing the file into smaller chunks. And the reason was that Java implementation has limit of 64KB for a class file. So in my case the class was evaluating to a size of 446KB.

0
Pekka On

I don't think you need to have a class if you are using only one function. You can save code and make it easier to read:

pdf2text.py

from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO


def convert_pdf_to_txt(path):
    rsrcmgr = PDFResourceManager()
    retstr = StringIO()
    codec = 'utf-8'
    laparams = LAParams()
    device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
    fp = file(path, 'rb')
    interpreter = PDFPageInterpreter(rsrcmgr, device)
    password = ""
    maxpages = 0
    caching = True
    pagenos=set()
    for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True):
        interpreter.process_page(page)
    fp.close()
    device.close()
    textstr = retstr.getvalue()
    retstr.close()
    return textstr

And this is how I use it:

*** Settings ***
Library   pdf2text

*** Test Cases ***
pdfconvert
    ${pdftext}=    Convert Pdf To txt    <path_to_pdf>

>