Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the meanings of itextpdf pdfcontentbyte addtemplate's parameters

Tags:

itext

I am using itextpdf to merge some pdfs to a single one. What are the meanings of itextpdf pdfcontentbyte addtemplate's parameters,there is no docs to describe them.

like image 231
dingjsh Avatar asked Dec 13 '22 21:12

dingjsh


1 Answers

public void addTemplate(PdfTemplate template,
    double a, double b, double c, double d, double e, double f)

The six values a, b, c, d, e, and f are elements of a matrix that has three rows and three columns.

enter image description here

You can use this matrix to express a transformation in a two-dimentional system.

enter image description here

Carrying out this multiplication results in this:

x' = a * x + c * y + e
y' = b * x + d * y + f

The third column in the matrix is fixed: you're working in two dimensions, so you don't need to calculate a new z coordinate.

When studying analytical geometry in high school, you've probably learned how to apply transformations to objects. In PDF, we use a slightly different approach: instead of transforming objects, we transform the coordinate system.

The e and the f value can be used for a translation. The a, b, c, and d value can be used for a rotation and/or scaling operation.

enter image description here

By default the Current Transformation Matrix (CTM) is:

enter image description here

With the addTemplate() method, you can add a Form XObject to a canvas and define a position using e, f, e.g:

canvas.addTemplate(template, 36, 36);

This will add template at coordinate x = 36; y = 36.

By introducing a, b, c, and d, you can also rotate and/or scale the template.

Update: as mentioned in the comments, you might want to use the overloaded methods that accept an AffineTransform parameter if you don't like the Algebra of the transformation matrix.

like image 54
Bruno Lowagie Avatar answered Dec 28 '22 09:12

Bruno Lowagie