views:

350

answers:

1

How do i resize an existing pdf to another format. I don't want to crop the pdf, it must be zoomed-out. (for printing issues)

When i try this it doesn't work because the pdf is cropped instead of zoomed

document.SetPageSize(new Rectangle(558.40f, 790.83f)); // 558.40f == 197mm
A: 

Most likely because PDF doesn't zoom based on the page size. When you set page size, and by this I'm referring to the page element MediaBox, you're defining the physical size of the rendering area. All content on the page is drawn to the same scale regardless of the rendering area.

In order to change this, you need to intercept the content stream and prepend a matrix operation to do the scale that you want. I don't know if you can do this in iTextSharp, but the actual PDF operator is m, and if you insert this:

sx sy 0 0 0 0 m

where sx and sy are floating numbers representing the scale in X and Y that you want to apply. In your case, you're changing X from 210 to 197, which is a .938 scale in X. Y goes from 297 to 279, so that's a scale of .939, so you would want to insert:

.938 .939 0 0 0 0 m

into the content stream to affect that change in addition to changing the MediaBox.

plinth
hm, do you have some more info where to alter the stream? i'm no byte[] pdf expert:)
MichaelD