Skip to content
Advertisement

Inexpensive ways to add seek to a filetype object

PdfFileReader reads the content from a pdf file to create an object.

I am querying the pdf from a cdn via urllib.urlopen(), this provides me a file like object, which has no seek. PdfFileReader, however uses seek.

What is the simple way to create a PdfFileReader object from a pdf downloaded via url.

Now, what can I do to avoid writing to disk and reading it again via file().

Thanks in advance.

Advertisement

Answer

There isn’t really an inexpensive, ready-to-use way to do this. The simplest way is to read all data and put it into a StringIO object. That does, however, require you read everything first, which may or may not be what you want.

If you want something that only reads as necessary, and then stores what was read (or perhaps just a portion of what was read) then you will have to write it yourself. You may want to see the source for the StringIO module (or the io module, in Python 2.6) for some examples.

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