Search code examples
c#itext

Rotate text / Vertical text in itextsharp


I need vertical text or just a way to rotate a ColumnText in ITextSharp.

(It needs to be absolute position)

Until now i have tried a lot of diffrent solution, but with no luck.

Here is a couple of tries:

1.

_cb.SetFontAndSize(BaseFont.CreateFont(), 12f);
_cb.ShowTextAligned(Element.ALIGN_CENTER, "Hello World", 50, 50, 90);

2.

var vt =  new VerticalText(_cb);
vt.SetVerticalLayout(50, 50, 400, 8, 30);            
vt.AddText(new Chunk("asdasd",_sf.ChildBackPageTextOneFont()));
vt.Go();

3.

System.Drawing.Drawing2D.Matrix foo = new System.Drawing.Drawing2D.Matrix();
foo.Rotate(90);
_cb.ConcatCTM(foo);

I have also tried to draw it with System.Drawing.Graphics, but the quality is VERY poor.

Any solution? Thanks.


Solution

  • Found the answer:

    Use something like this:

    Imports System.Drawing, System.Drawing.Drawing2D
    Dim transf as new Matrix
    transf.RotateAt(30,New PointF(100,100), MatrixOrder.Append)
    writer.DirectContent.Transform(transf)
    
    transf.Invert()
    writer.DirectContent.Transform(transf)
    

    Rotate the canvas, write some text, rotate it back.