|
-
Jun 18th, 2019, 02:52 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Scaling a pdf
Hi
I've been tasked with reformatting a multi-page pdf from A4 to 2 x up on A3 with a border.
Using itextsharp I can create an A3-sized pdf and stamp the A4 pages to the left and right of the page.
What I can't seem to find a way to do is re-size the A4 pdf to something a bit less in order to centralise the left/right 'panes' of the A3 sheet and therefore create a border.
Does anyone know how to scale a pdf to (say) 98% of it's size?
Everything I've been able to research either leads to cropping it, which isn't what I want at all, or converting to an image first, whch I also want to avoid.
Thanks!
-
Jun 18th, 2019, 03:41 AM
#2
Thread Starter
Addicted Member
Re: Scaling a pdf
OK, it looks like I can do this via the use of AddTemplate when I stamp the page, which is great. I didn't realise there was an option to scale there.
Unfortunately I'm having difficulty understanding how the parameters work.
At the moment I have:
Code:
cb = writer.DirectContent()
cb.AddTemplate(page, x, y)
I know I just add the scales as singles, but how do I effectively create a 98% output?
-
Jun 18th, 2019, 04:04 AM
#3
Re: Scaling a pdf
I just did a search using "pdf addtemplate" and the very first link looked like it would be useful.
I would assume you get the current scale, as that poster did, then multiply that scale by .98, and use the result in a AffineTransform call, and pass the resulting transform to your addTemplate call.
I don't know if you would use two transforms, with a 90 or 270 rotation and different x,y offsets instead of stamping the pages to the left and right as you currently are. I guess that is up to you to play with.
-
Jun 18th, 2019, 04:14 AM
#4
Thread Starter
Addicted Member
Re: Scaling a pdf
I did look at that page but it didn't make much sense to me. However after a bit of trial and error this seems to work:
Code:
cb.AddTemplate(page, 0.98, 0, 0, 0.98, x, y)
Thanks!
-
Jun 18th, 2019, 04:41 AM
#5
Re: Scaling a pdf
Yes, that should work.
The first parameter after page, should scale the X (normally defaulted to 1) (i.e. a percentage of X is applied to X) and the fourth parameter should scale the Y (a percentage of Y is applied to Y).
The second parameter would apply a percentage of X to the Y value, and the third parameter would apply a percentage of Y to the X value.
That is why to rotate 90 and 270, you are using 1 and -1 combinations, to have 100% of X applied to the Y axis and 100% of Y assigned to the X axis.
The -1 would just flip the direction of the corresponding axis, so the coordinates go the reverse direction to match the direction it needs to go for the rotation.
In the case of 180 degree rotation, you just need to flip the X coordinates and the Y coordinates (i.e. scale both by -1, i.e. the first and fourth parameters).
Perhaps with this additional information, and some more thought, it might make a little more sense.
-
Jun 18th, 2019, 04:50 AM
#6
Thread Starter
Addicted Member
Re: Scaling a pdf
 Originally Posted by passel
Yes, that should work.
The first parameter after page, should scale the X (normally defaulted to 1) (i.e. a percentage of X is applied to X) and the fourth parameter should scale the Y (a percentage of Y is applied to Y).
The second parameter would apply a percentage of X to the Y value, and the third parameter would apply a percentage of Y to the X value.
That is why to rotate 90 and 270, you are using 1 and -1 combinations, to have 100% of X applied to the Y axis and 100% of Y assigned to the X axis.
The -1 would just flip the direction of the corresponding axis, so the coordinates go the reverse direction to match the direction it needs to go for the rotation.
In the case of 180 degree rotation, you just need to flip the X coordinates and the Y coordinates (i.e. scale both by -1, i.e. the first and fourth parameters).
Perhaps with this additional information, and some more thought, it might make a little more sense.
Everything I need to do at the moment seems to be urgent, but I will review this for future work as it's bound to come up at some point.
Many thanks for taking the time to help me with this.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|