I have used the superimpose example to superimpose one pdf onto another. I am running into some trouble when trying to superimpose a page from a source file with a rotation of 90 degrees onto the destination page which has 0 rotation but is landscape (it's wider than it is tall).
When i first tried to stamp the content as in the example, it got the content rotated -90 as in the left example in the image below. When I tried to set the rotation of the destination page, the source content was placed in the right orientation but the destination page had turn (right example in the image below).
var sourcePageRotation = sourcePage.GetRotation();
destinationPage.SetRotation(sourcePageRotation);
How can I manipulate either the source or destination page to change the rotation value without actually changing the way it displays?
(As you referenced a Java example, I'll also refer to iText for Java.)
In the SuperImpose
example the pages to superimpose are added using
canvas.addXObject(page, 0, 0);
but there are other PdfCanvas.addXObject
overloads, too, in particular
public PdfCanvas addXObject(PdfXObject xObject, float a, float b, float c, float d, float e, float f)
The 6 float
s represent an affine transformation applied to the XObject, e.g. a rotation. Thus, you can rotate the imported page XObject from the source document to match the orientation of the destination document page, e.g. replace
canvas.addXObject(page, 0, 0);
by
canvas.addXObject(page, 0, 1, -1, 0, page.getHeight(), 0);
or, if that makes the page contents stand upside down, by
canvas.addXObject(page, 0, -1, 1, 0, 0, page.getWidth());
Just like the example you referenced I here assume the lower left corner of the pages involved are the respective coordinate system origin. If that assumption is wrong, one needs to adapt the last two float
parameters respectively in the replacements above.
Thankyou for this @mkl, I actually already got there by finding your answer to a similar question using the
AffineTransform
function! I might add an answer of my own too as i had to write my own function to transform the annotation links on the same page, and I will link your answer in my question.