在itextsharp中旋转文本/垂直文本

Lut*_*cka 9 c# itextsharp

我需要垂直文本或只是在ITextSharp中旋转ColumnText的方法.

(它需要绝对的位置)

直到现在我已经尝试了很多不同的解决方案,但没有运气.

这是几次尝试:

1.

_cb.SetFontAndSize(BaseFont.CreateFont(), 12f);
_cb.ShowTextAligned(Element.ALIGN_CENTER, "Hello World", 50, 50, 90);
Run Code Online (Sandbox Code Playgroud)

2.

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

3.

System.Drawing.Drawing2D.Matrix foo = new System.Drawing.Drawing2D.Matrix();
foo.Rotate(90);
_cb.ConcatCTM(foo);
Run Code Online (Sandbox Code Playgroud)

我也尝试用System.Drawing.Graphics绘制它,但质量非常差.

有解决方案吗 谢谢.

Sun*_*bin 11

我已经尝试了很多来自网络的旋转问题的方法.但它们都没有奏效.最后我想出了一个简单的解决方案.也许我们可以这样做.我们可以绘制一个没有边框的表格,只有一个单元格.我们在单元格中添加文本,最后旋转单元格.一切都好.

        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);
Run Code Online (Sandbox Code Playgroud)

此外,WriteSelectedRows方法可以定位此单元格.


Ste*_*scu 5

实际上最简单的方法与你的第一次尝试相似.你只需要像这样添加对BeginText()EndText()的调用

_cb.SetFontAndSize(BaseFont.CreateFont(), 12f);
_cb.BeginText();
_cb.ShowTextAligned(Element.ALIGN_CENTER, "Hello World", 50, 50, 90);
_cb.EndText();
_cb.Stroke();
Run Code Online (Sandbox Code Playgroud)

这是ShowTextAligned的文档


Lut*_*cka 4

找到了答案:

使用这样的东西:

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)
Run Code Online (Sandbox Code Playgroud)

旋转画布,写一些文字,然后将其旋转回来。