Skip to content

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
Discussion options

You must be logged in to vote

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")

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@gbaryiames
Comment options

Answer selected by gbaryiames
Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants