-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to group collections of image bounding boxes #386
Conversation
704f5bf
to
2882d4b
Compare
Note that the docs linked above are for a commercial .NET SDK and not applicable to pypdfium2/pdfium. |
""" | ||
Convert a PDFium bounding box (which typically has an origin at the bottom-left) | ||
to a more standard bounding-box format with y=0 at the top. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this method is generally correct, as the PDF spec allows for a pretty arbitrary coordinate system.
Indeed, the origin typically is the bottom left, but IIRC the coordinate system can be laid out between any opposite corners in principle. Also, the coordinate system does not necessarily have to start at 0, it could be any arbitrary value.
Related: pypdfium2-team/pypdfium2#284
Description
Partially addresses #353. This PR is focused on PDFs. Other document types will be addressed in future PRs.
This PR adds support for a new
extract_images_method
option in the PDFium-based extraction workflow, allowing users to choose between a simple “as-is” extraction of image objects (simple
) or a “grouping” approach (group
) that groups related bounding boxes together. It introduces a new parameter,extract_images_params
, for configuring thresholds and additional clustering details.In the previous approach (
simple
), we only extractedPdfImageObject
s, but PDFium provides several additional graphics objects in addition to PdfImageObject. For our purposes, we now also extract:PdfPathObjectFPDF_PAGEOBJ_PATH The PdfPathObject is an arbitrary shape made up of straight lines, rectangles, and cubic Bézier curves. A path may intersect itself and may have disconnected sections and holes.The
PdfFormObjectFPDF_PAGEOBJ_FORM is used to group graphical elements together as a unit for various purposes.As an example, the following has a PdfFormObject. The object inside the red box is a form object that contains several nested component images. If we use the bounding box of the PdfFormObject (instead of naively extracting all the images with depth > 1), we can correctly group together all the components.

In the following example, we have what looks like an image, but it's actually made of many "shapes" (PdfPathObject). We can group them together as one single object.

Checklist