Is it possible to transform a PDF page, including all pdf element using a transformation matrix. #3339
Answered
by
JorjMcKie
gbaryiames
asked this question in
Q&A
-
I would like to preform the following on an existing pdf page.
|
Beta Was this translation helpful? Give feedback.
Answered by
JorjMcKie
Apr 4, 2024
Replies: 2 comments 2 replies
-
This should do the job: doc=fitz.open("v110-changes.pdf")
page=doc[0]
mb = page.mediabox
diff=105 # how much wider
mb
Rect(0.0, 0.0, 595.3200073242188, 841.9199829101562)
mb.x1 += diff # increase width
mb # show
Rect(0.0, 0.0, 700.3200073242188, 841.9199829101562)
page.set_mediabox(mb) # update MediaBox
m=fitz.Matrix(1,0,0,1,diff,0) # make a shift matrix
s = "%g %g %g %g %g %g cm " % tuple(m) # convert to PDF format
fitz.TOOLS._insert_contents(page,s.encode(),overlay=False) # prepend page's content
doc.ez_save("x.pdf") |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gbaryiames
-
Is that not equivalent to just moving the left hand edge of the page left? i.e. do the page expansion by reducing x0 rather than increasing x1? No need to fiddle with the operator stream at all. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should do the job: