Search code examples
pdfitext

Rotate and Scale the existing PDF page using itext 2.1.7


I am trying to rotate a existing PDF page by 90 degrees and also resize the page (i,e scale). I am able to rotate the page by following code

cb.addTemplate(page, 0.0F, 1.0F, -1.0F, 0.0F, currentPageSize.getHeight(), 0.0F);

For reference this is the method:

addTemplate(PdfTemplate template, float a, float b, float c, float d, float e, float f)

I am not able add the scaling (scale PDF by 0.28) along with rotation . Every time I put values in a and d parameters, the pdf page adds slight more rotation instead of scaling.


Solution

  • To scale the transformation matrix, simply multiply all its entries by the factor, i.e. to scale

    0.0F, 1.0F, -1.0F, 0.0F, currentPageSize.getHeight(), 0.0F
    

    by .28 use

    0.0F, 0.28F, -0.28F, 0.0F, 0.28F*currentPageSize.getHeight(), 0.0F