I have a function that gets a page from a PDF file via pyPdf2 and should convert the first page to a png (or jpg) with Pillow (PIL Fork) That results in an error: OSError: cannot identify image file <_io.BytesIO object at 0x0000023440F3A8E0> I found some threads with a similar issue, (PIL open() method …
Tag: pypdf
How to install PyPdf2 in PyCharm (Windows-64 bits)
I want to install PyPdf2 in PyCharm for Windows (64 bits) I have tried to go to SettingsProjectProject Interpreter, Then pressing the “+” sign, but It did not found PyPdf2. I already Installed it to the normal python2.7 by going to the extracted path of PyPdf2 then I run (python.exe setup.py insta…
Error in the coding of the characters in reading a PDF
I need to read this PDF. I am using the following code: However, the encoding is incorrect, it prints: But I expected How to solve it? I’m using Python 3 Answer The PyPDF2 extractTest method returns UniCode. So you many need to just explicitly encode it. For example, explicitly encoding the Unicode into…
Why does pyPdf2.PdfFileReader() require a file object as an input?
csv.reader() doesn’t require a file object, nor does open(). Does pyPdf2.PdfFileReader() require a file object because of the complexity of the PDF format, or is there some other reason? Answer It’s just a matter of how the library was written. csv.reader allows any iterable that returns strings (…
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…
Cropping pages of a .pdf file
I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size. After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribut…