We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to rotate a single line of text in my pdf?

I'm currently trying to rotate a single line of text in my pdf. This is proving harder than expected.
Using .Graphics.TransformRotate(45) on the PdfPage isn't really an option since I'm using it in a for loop.

Here's an example of what I'm trying to do:

For Each value As values
Dim originalState As PdfGraphicsState = currentPage.Graphics.Save()
currentPage.Graphics.RotateTransform(45)
currentPage.Graphics.DrawString(...)
currentPage.Graphics.Restore(originalState)
Next

Now this requires some complex logic for the x and y values in the DrawString, so I'm hoping I can somehow only rotate the string I'm drawing there. If needed I can always store it in a PdfTextElement. But even on the element I haven't found a way to fix this.

4 Replies

KC Karthikeyan Chandrasekar Syncfusion Team May 8, 2013 05:37 AM UTC

Hi Gert,

Thank you for your interest in Syncfusion Products.

 

While using RotateTransform, it will transform the whole coordinate system to the angle mentioned.

So the default coordinates will change accordingly.

Using some mathematical calculations I have tried calculating the new coordinates.

   Dim xNew As Double = x * Math.Cos(angle) - y * Math.Sin(angle)

   Dim yNew As Double = x * Math.Sin(angle) + y * Math.Cos(angle)

 

I also attached a sample for your reference.

TextRotationVB.zip

Please let us know if you have any concern.

 

 

Thanks,

Karthikeyan.C

 



GV Gert Van Meerbergen May 8, 2013 08:22 AM UTC

Hi Karthikeyan

Unfortunately your solution does not work for me. I have added a zip with 2 images: what we want to achieve (wanted.png) and what we currently have (current.png).

As you can see on the image, we want to have a rotated text (45 degrees) with a different x-axis value and aligned on the y-axis.


result_cee416c1.zip


KC Karthikeyan Chandrasekar Syncfusion Team May 13, 2013 04:22 AM UTC

Hi Gert,

Thank you for your update.

 

I have modified the sample according to your new image attached.

Please refer the sample, you may adjust the values to get the text in the proper destination in your document.

TextRotationVB.zip

 

Please let us know if you have any concern.

 

Thanks,

Karthikeyan.C

 



LC Luca Cavicchioli August 28, 2014 07:27 AM UTC

I'm also interested in the answer and I'd like to take a look at the saples proposed but when I'm trying to download them I always receive the error message:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
[...]

Please fix the problem I'm also trying to print rotated string but what I'm getting is an empty PDF.


Loader.
Live Chat Icon For mobile
Up arrow icon