Extracting drawing to a new pdf #2296
Replies: 5 comments
-
Having trouble to understand what of the old PDF you don't want in your new one. Just the text? |
Beta Was this translation helpful? Give feedback.
-
Many thanks for a very quick response. Was not expecting that. Sorry if my question was not well explained.
In the above code snippet if
|
Beta Was this translation helpful? Give feedback.
-
What you can do is restricting the part of the source page rectangle that should be visible in the target page: This reduces your problem to determnining the |
Beta Was this translation helpful? Give feedback.
-
Let me convert this issue to a "Discussions" item. Will be easier to handle there. |
Beta Was this translation helpful? Give feedback.
-
To output each drawing (vector graphic) on the pages of a source PDF to a new page of some target PDF, you can thus do the following: src = fitz.open("source.pdf")
out = fitz.open() # output PDF having one drawing per page
for src_page in src:
paths = src_page.get_drawings() # vector graphics on source
for path in paths:
rect = path["rect"] # rect covering the drawing
tar_page = out.new_page(width=rect.width, height=rect.height)
tar_page.show_pdf_page(tar_page.rect, src, src_page.number, clip=rect)
out.cose("paths.pdf") |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
I have a PDF document containing different paths (drawings). Can I extract each existing path in a new PDF document without using Shape?
The extracted drawings should be exactly the same as in the original PDF. With all the layers (OCG), colors, embedded / attached images e.t.c. Therefore, it will be wise not to create a new Shape object (I tried to do that but it loses the colors).
Describe the solution you'd like
Something along the lines:
Describe alternatives you've considered
I tried looping over the paths and creating shapes as demonstrated in many examples but I get only the outlines of the paths.
**Additional contex
Below is the screenshot of the pdf and when extracted the expected output is 2 separate files each with one drawing.
t**
Beta Was this translation helpful? Give feedback.
All reactions