2

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?

Dave
  • 439
  • 1
  • 4
  • 17

1 Answers1

0

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);
    }
}
Chris Haas
  • 53,986
  • 12
  • 141
  • 274