Replies: 1 comment 1 reply
-
The vector graphics extraction that includes clips and groups follows the logic as explained in the documentation here. The There is no effort to somehow compute non-rectangular clip areas: The items in the clip may define pretty much arbitrary shapes like rhombuses, triangles, circle segments, etc. Evaluating this is one of the tasks of any PDF viewer. Whatever a clips shape is: the only thing that can be deducted directly is that it will be contained in the scissor. There is a high chance that regular (= stroke or fill) paths have items that are at least partly outside the parent's clip scissor. After all, achieving this is the purpose in the life of a cip. Please be aware, that all information in The sequence numbers are ascending because they originate from counting the encounters of fill and stroke paths. Any gaps are caused by other commands: text, images etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Q: How can I apply accurate clipping regions to Pixmaps that are not Rects?
My question is essentially a duplicate of: #1312
Which got me in to the wonderful world of
bboxlog
andseqno
, but it was still not providing angled (non-rectangular) clips, or at least, I struggled with applying them.So, given that my question will center more around the newer (v1.22.0+)
get_drawings(extended=True)
, I thought a new discussion was merited.Here's my best attempt so far at applying the hard clipping masks to the images, but I am highly hopeful there is a more reasonable solution. I don't believe Pixmap's have these kinds of functions so I am using Pillow for the compositing.
What I am really looking for is
Pixmap.clip(Shape)
or similar.Steps:
Page.get_drawings(extended=True)
to get clips.Shape
and save as Pixmap.Page.get_image_info(xrefs=True)
or equivalent to get image.A couple nested questions from the above steps:
2. Attempt to accurately link clips with their respective images.
In my testing,
clips
do not haveseqno
, and theirbbox
/scissor
will not 100% match the imagebbox
.However, the
items
of the clip path match the immediately preceding path, which has aseqno
and can then be applied to the image atseqno + 1
.Is this reliable? 🤔
Example:
5. Apply black clip Pixmap as alpha composite of original image Pixmap.
This does not seem like the best approach at all, but it's returning an image that at least has the correct portion of the image cropped out.
Original Image:

Clipped Image (note, I have not applied the

transform
to the image yet):Not quite right yet.
Please tear the approach apart and let me know where better solutions may be available!
Thank you.
Sample file:
samplefile.pdf
Beta Was this translation helpful? Give feedback.
All reactions