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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Rotate a single line of text in PDF with DrawString

Thread ID:





117178 Aug 28,2014 09:09 AM UTC Sep 2,2014 04:45 AM UTC WinForms 1
Tags: PDF
Luca Cavicchioli
Asked On August 28, 2014 09:09 AM UTC

Hello, I need to rotate a single line of text, of a specified angle, while I'm composing a PDF document, by reading fields from a database.
A code snippet that explains what I want to achieve is something like this:

// Rows contains a collection of objects that represents all the element of the final PDF file
foreach (var row in rows)
    // Considering only the string objects (the only with a rotation angle)
    if(row.Type == "S")
        DrawString(row.X, row.Y, row.Text, row.RotationAngle, [...]);
    else if(row.Type == "P")
        [...Do other stuff...]    

// For simplicity, all the stuff for create font and format are omitted
private void DrawString(float posX, float posY, string text, int rotationAngle, [...])
     var font = new PdfTrueTypeFont([...]);
     var format = new PdfStringFormat { Alignment = PdfTextAlignment.Left, WordWrap = PdfWordWrapType.Word };

    _page.Graphics.DrawString(text, font, PdfBrushes.Black, new PointF(X, Y), format);

// And what about the rotation angle???
// If 90 is passed as RotationAngle I'like to have ONLY this string rotated by 90 degrees.


For completeness, if I have these data:
X = 10, Y = 10, Text = "Straight", RotationAngle = 0
X = 20, Y = 10, Text = "Rotated", RotationAngle = 90
X = 30, Y = 10, Text = "Already Straight", TotationAngle = 0
I would like to have a PDF that looks like the picture attached

Attachment: Sample_e396ddda.zip

Praveenkumar H [Syncfusion]
Replied On September 2, 2014 04:45 AM UTC

Hi Luca,

Thank you for using syncfusion products,

We can rotate the text as follow.

 //save the current graphics states
            PdfGraphicsState state = page.Graphics.Save();

            //Translate the coordinate system’s to where you want draw the text position
            //Rotate the coordinate system’s
            //Draw the string at the origin
            page.Graphics.DrawString(text, bigFont, PdfBrushes.DarkBlue, new PointF(0, 0));

            //Restore the graphics state

Wee have attached sample project for your reference.

Please let us know if you need further assistance.

With Regards,


Attachment: VerticalText_5cfdca5f.zip


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon