How can I split a page in 4 smaller pages mosaicing? #1725
Unanswered
ErfolgreichCharismatisch
asked this question in
Q&A
Replies: 2 comments 1 reply
-
first you are using PyPDF2 which is an old version, you have to upgrade to the latests pypdf 3.5.1 (you will have to uninstall PyPDF2 and then install pypdf) as a test sample here is a code I've just tested: import pypdf
r = pypdf.PdfReader("crazyones.pdf")
w = pypdf.PdfWriter()
#add the pages 4 times using append to get annots....
w.append(r,[0]);w.append(r,[0]);w.append(r,[0]);w.append(r,[0])
#readjust the mediabox
w.pages[0].mediabox.bottom = r.pages[0].mediabox.top - r.pages[0].mediabox.height/2
w.pages[0].mediabox.right = r.pages[0].mediabox.left + r.pages[0].mediabox.width/2
w.pages[1].mediabox.right = w.pages[0].mediabox.right
w.pages[1].mediabox.top = w.pages[0].mediabox.bottom
w.pages[2].mediabox.left = w.pages[0].mediabox.right
w.pages[2].mediabox.bottom = w.pages[0].mediabox.bottom
w.pages[3].mediabox.left = w.pages[2].mediabox.left
w.pages[3].mediabox.top = w.pages[2].mediabox.bottom
w.write("out.pdf") |
Beta Was this translation helpful? Give feedback.
1 reply
-
The image analysis is a tough work that a viewer is doing. pypdf is not designed for this. The solution I would propose would be to "print" the file using a "pdf printer" driver into a new pdf. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
edit: The following was originally reported as a bug. While it is not, some of the comments might be valuable to the community.
My goal:
An A4 PDF file has two columns. Read it with Python and output a new A5 PDF file where the width of the column corresponds to the width of the A5 page (enlarge/reduce if necessary) and copy the complete content into a new A5 PDF. If you do it right, there will be more pages in the A5 PDF file than in the A4 PDF file. Also take over chapters.
My code:
My goal in pictures:
A4 with columns:

Goal:

The error I got
Beta Was this translation helpful? Give feedback.
All reactions