iTextSharp - Adding a vertical textbox

╄→гoц情女王★ 提交于 2020-01-15 04:53:14

问题


Does anyone know if it's possible to add a vertical textbox to a PDF document using itextsharp.

I have tried rotating the page first

PdfDictionary pDict = reader.GetPageN(1);
pDict.Put(PdfName.ROTATE, new PdfNumber(90));
AddTextBox(stamper, ...........)
// Rotate back

but this just adds the textbox horizontally, do I need to get another instance of stamper after the rotation?


回答1:


When you create the TextField set its Rotation property:

PdfReader reader = new PdfReader(file1);
using (FileStream fs = new FileStream(file2, FileMode.Create, FileAccess.Write, FileShare.None))
{
    using (PdfStamper stamper = new PdfStamper(reader, fs))
    {
        TextField tf = new TextField(stamper.Writer, new iTextSharp.text.Rectangle(0, 0, 100, 300), "Vertical");
        //Change the orientation of the text
        tf.Rotation = 90;
        stamper.AddAnnotation(tf.GetTextField(), 1);
    }
}


来源:https://stackoverflow.com/questions/8414019/itextsharp-adding-a-vertical-textbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!