Extract first page text from Django InMemoryUploadedFile #1844
-
My script works perfectly fine when running from the command line and using The problem is when trying to use the same script in Django using an uploaded file (
Results in:
Changing this line: Results in an empty list when trying to print out the words: Pretty new to this and feel like I am missing something really obvious. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
PyMuPDF cannot read from the internet - which is presumably what you are trying to do here. So To try out the from-memory case do this with any valid document: inpdf = open("some.pdf", "rb")
pdfbytes = inpdf.read()
inpdf.close()
doc=fitz.open("pdf", pdfbytes) |
Beta Was this translation helpful? Give feedback.
-
In case anyone else sees this and misses the thread above. I had to put My final function looks like this:
Not sure how/why the pointer/cursor moves when trying to read the file. Perhaps because I have opened the file already in another part of |
Beta Was this translation helpful? Give feedback.
In case anyone else sees this and misses the thread above. I had to put
uploaded_file.seek(0)
prior to trying to read the file infitz.open(stream=uploaded_file.read(), filetype="pdf")
My final function looks like this: