Trying to upload and read a PDF file

I am trying to upload and process a pdf-file, in “normal” python environment i use:

using

from pdfreader import SimplePDFViewer
    with open(input_file['file_pdf'], 'rb') as f:
        df,page = functions.read_pdf(f)

which works fine.

For the Viktor app, is so far have:

    @staticmethod
    def read_PDF(params, **kwargs):
        print(params.filePDF.filename)
        with params.filePDF.file.open() as f:
            df,page = functions.read_pdf(file_pdf = f)
        return df,page

But the encoding seems to be off. is there i can use the “normal”

with open(input_file['file_pdf'], 'rb') as f:

or is there another option?

Hi @wluites ,

The VIKTOR platform also allows you to read binary: file.open_binary

Can you perhaps try this function?

    @staticmethod
    def read_PDF(params, **kwargs):
        print(params.filePDF.filename)
        with params.filePDF.file.open_binary() as f:
            df,page = functions.read_pdf(file_pdf = f)
        return df,page

Please let us know whether this solves your problem!

This indeed solves the problem, I found the solution when searching the API documentation.

1 Like