Can drawings extracted from a PDF be saved as images? #1442
-
Is it possible to extract drawings from a PDF and save them as images? Do drawings in a PDF have xref values? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 18 replies
-
Yes, indirectly: Use the drawing's rectangle as
No, they only exist as code snippets inside a page's |
Beta Was this translation helpful? Give feedback.
-
The sequence in which bboxes are encountered in the (list of) |
Beta Was this translation helpful? Give feedback.
-
Everything works just fine. >>> import fitz
>>> doc=fitz.open("1.pdf")
>>> for page in doc:
shape=page.new_shape()
page.clean_contents()
for w in page.widgets():
shape.draw_rect(w.rect)
shape.finish(fill=(1,0,0))
shape.commit()
>>> doc.ez_save("1-y.pdf")
>>> Then used some viewer to check the button boxes. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot. This really helps. |
Beta Was this translation helpful? Give feedback.
-
You have to convert coordinates given in the contents stream to MuPDF coordinates yourself and then try to match them with coordinates in the |
Beta Was this translation helpful? Give feedback.
Yes, indirectly: Use the drawing's rectangle as
clip
parameter and make a pixmap from it:pix = page.get_pixmap(clip=path["rect"])
.No, they only exist as code snippets inside a page's
/Contents
object.