Center a rotated logo stamp

Hi,


As per my previous post I am trying to put a logo on each page of a PDF. I want the logo to be rotated (to a user configurable degree) and centered on the page.

Now I can get the page width and height, and I can get the text width and height from the FormattedText object. So centering the text is easy when it has not been rotated.

Of course when I rotate the text the width and height of the text are of no use to me, I need the width and height of the bounding box which I'm struggling with.

So my questions are:

  1. Is there an easy way to center rotated text when using a stamp.
  2. If not can you provide me with a calculation that will enable be to set the origin correctly.

This needs to work for any angle of rotation.

Thanks again,

Nick.

P.S This is the last problem I need to solve and then you've got another sale....


Another question is, what is the point of rotation? Is it the centre of the text rectangle?

Hi Nick,

Thank you very much for your interest in Aspose.

Regarding your first question, I think following article can help you out:

Adding watermarks on different sized pages in a PDF

The only difference is that, when the pages are of same size then you don't need to loop through the pages individually.

Also, the center of rotation would be the center of the stamp object.

If you have any questions or concerns, please do let us know.

Regards,

Shahzad,

Thank you for that, the information about the centre of rotation was helpful.

Unfortunately the link does not solve my problem. Let me explain further:

  • I am creating a stamp and using Stamp.BindLogo to set some FormattedText to stamp on the PDF.
  • I want the user to be able to choose an angle of rotation for that text which I set using Stamp.Rotation.
  • I want the text to be centred regardless of the rotation.
  • In order to do that I need to be able to calculate the origin for my stamp correctly and set it using Stamp.SetOrigin

So for example if the user chooses to rotate the text 180 degrees the bottom left corner of the rectangle is now actually the top right (as we’ve rotated it and it’s now upside down).

So for any given angle between 0 - 360 degrees how do I calculate the coordinates to use in Stamp.SetOrigin so that the text is always centred ?

Thanks again,
Nick


Hi Nick,

I'm sorry that it didn't work for you.

As I have got a little more details regarding the situation, please spare us some time so we could look into the requirement. I'll update you the earliest possible.

We really appreciate your patience.

Regards,

Shahzad,

Don’t worry I think I have worked it out. I had to apply a rotation transformation to the origin point. Might be a handy thing to include in the product though to save people digging out their “maths for dummys” books.

Thanks
Nick.

Is there a solution for this problem with the new version of Aspose.Pdf.Kit? I also can't center a rotated logo in my pdf ...

Thanks

Hi Maxime,

Can you please elaborate your requirement a little bit with the help of some sample, so we would be able to help you out accordingly?

We’re sorry for the inconvenience.
Regards,


I can supply you with some code to do this. Might cost you some free software though :wink: