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.
Actually, the easiest way is similar to your first try. You just needed to add a call to BeginText() and EndText() like this
_cb.SetFontAndSize(BaseFont.CreateFont(), 12f);
_cb.BeginText();
_cb.ShowTextAligned(Element.ALIGN_CENTER, "Hello World", 50, 50, 90);
_cb.EndText();
_cb.Stroke();
I have tried a lot of methods from the web for this rotate issue. But none of them worked. Finally I figured out a simple solution. Maybe we can do it like this. We can draw a table with no borders, and just with one cell. And we add text in the cell, finally rotate the cell. Every is ok then.
table = new PdfPTable(1);
table.TotalWidth = 72;
paragraph = new Paragraph("123");
cell = new PdfPCell(paragraph);
cell.Rotation = 270;
cell.BorderWidth = 0;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, 72, 72, writer.DirectContent);
Besides, the WriteSelectedRows method can position this cell.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With