Skip to content
Advertisement

Download pdf in memory python

I want to open a pdf in my Python program. So far that works.

JavaScript

Right now I open the pdf from my local disk, but I want it to fetch the pdf from the internet, instead of opening it from my local drive. Note that I don’t wish to save the existing_pdf, once I fetched it from the internet I will manipulate it and then save it.

I think I need BytesIO + urllib2, but I cannot figure it out, can somebody help me?

So lets say I want to create the variable: existing_pdf with content http://tug.ctan.org/tex-archive/macros/latex/contrib/logpap/example.pdf in it, but I don’t wish to download that file first to the disk and then open it. I want to download it ‘in memory’ and create the variable existing_pdf, which I can later modify in my program.

EDIT:

JavaScript

It simply hangs and never finishes PdfFileReader(pdf_file)

JavaScript

Advertisement

Answer

Did you try the requests package?

JavaScript

This worked for me:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement