Comments (4)
@koaning This is actuall a completely different matter. Your error simply means that the Pillow library is not installed (see e.g. #249 (comment) for considerations)
This issue originally was about whether we should check the return of FPDF_BitmapCreate()
to be non-null.
from pypdfium2.
Seems like it's unnecessary - FPDF_BitmapCreate()
should always return LP_struct_fpdf_bitmap_t__
(unless errors occured when creating the bitmap). Moreover, FPDFBitmap_Destroy()
apparently doesn't fail if the argument is None
.
from pypdfium2.
I happen to have a situation where this does occur. Figured I'd share.
tests/test_basics.py:8:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
prodigy_pdf/__init__.py:27: in generate_pdf_pages
"image": page_to_image(page),
prodigy_pdf/__init__.py:13: in page_to_image
pil_image = page.render().to_pil()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <PdfBitmap uuid:5129eced>
def to_pil(self):
"""
Convert the bitmap to a :mod:`PIL` image, using :func:`PIL.Image.frombuffer`.
For ``RGBA``, ``RGBX`` and ``L`` buffers, PIL is supposed to share memory with
the original bitmap buffer, so changes to the buffer should be reflected in the image, and vice versa.
Otherwise, PIL will make a copy of the data.
Returns:
PIL.Image.Image: PIL image (representation or copy of the bitmap buffer).
.. versionchanged:: 4.16 Set ``image.readonly = False`` so that changes to the image are also reflected in the buffer.
"""
# https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.frombuffer
# https://pillow.readthedocs.io/en/stable/handbook/writing-your-own-image-plugin.html#the-raw-decoder
dest_mode = pdfium_i.BitmapTypeToStrReverse[self.format]
> image = PIL.Image.frombuffer(
dest_mode, # target color format
(self.width, self.height), # size
self.buffer, # buffer
"raw", # decoder
self.mode, # input color format
self.stride, # bytes per line
1, # orientation (top->bottom)
)
E AttributeError: 'NoneType' object has no attribute 'Image'
This is using pypdfium2==4.20.0
from pypdfium2.
Concerning the original issue, I now think I was wrong by then. For the C functions, it is generally good practice to check the return for an error code (in this case NULL/None), even if it does not usually happen in reality. CC #208.
Note, operations on NULL are dangerous in C. However, pdfium functions generally make sure the input is non-null and return error otherwise. But again, I believe it may be good practice to also do this as a caller.
from pypdfium2.
Related Issues (20)
- conda: consider reading pdfium-binaries version from system?
- Installation failures within a Docker container, problem with ctypesgen? HOT 3
- Parsing special characters leading to inconsistency among different machines HOT 6
- musl binary size concerns
- pdfium fails to load in PHP on Almalinux 8.9 (PartitionAlloc check failure) HOT 8
- Buffer size mismatch when calling `get_text_range` HOT 14
- page.set_rotation() Over Rotating Some Pages
- page.render function returns an unexpected image HOT 7
- PdfDocument.get_page is non-thread-safe HOT 1
- Got different result of "pdfium_page.render()" on MacOS and Linux HOT 1
- Extracting text with special characters HOT 7
- expose more details in PdfiumError HOT 3
- Weird "PDFium: Data format error" when using pypdfium2 in Celery task. HOT 11
- The render func does not render form fields. HOT 4
- pypdfium2 on S390x (ubuntu22.04) HOT 6
- After get_text_bounded, cannot MOVE file HOT 2
- Install with reference bindings broken
- Extract form-filling values from a PDF document that supports Acroform HOT 1
- 当,pdf某一页异常的时候,renderer 到那一页后就会一直卡顿 HOT 2
- Adapt setup code to `bdist_wheel` relocation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pypdfium2.