I am using pdfstamper to add the watermark to an existing pdf. When i keep the flag setRotateContent(true), the watermark comes at the right position but when i keep it false, watermark is misplaced. I cant share the code due to some restrictions.
I am sharing the cases.
With setRotateContent(false)
With setRotateContent(true)
So my question is how exactly does the setRotateContent() works. I have tried the Api page as well. But all the examples are with setRotateContent(false).
As a bit of background you need to know that each PDF page contains an attribute Rotate which is specified as "The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. Default value: 0."
If you want to add something to a page which has a non-trivial Rotate value (i.e. a multiple of 360), therefore, there are two distinct situations:
While the former is trivial, you simply use the given coordinates and orientation, the latter requires you to read the Rotate value and calculate it into your coordinates and angles.
iText here tries to help you and, for
setRotateContent(true)
, first adds a transformation to overcontent and undercontent, allowing you to simply go ahead choose coordinates and angles as if no page rotation was involved.Seemingly the latter situation has been perceived to occur more often than the former. Thus, the default
RotateContent
value istrue
. In the former situation, therefore, you actually have to switch it off usingsetRotateContent(false)
.As the question is how that works exactly: This is the method executed to initialize the undercontent and overcontent
ByteBuffer
representation:(
PdfStamperImp
)with
(
PdfContents
)PS: While the
RotateContent
attribute controls whether or not these transformations are added to the overcontent and undercontent or not, there is a similar mechanism for annotations which cannot be disabled by that attribute, cf. this answer.