tags:

views:

487

answers:

1

I followed the iText samples for vertical text:

http://1t3xt.info/examples/browse/?page=example&id=145

and created this C# version of it:

PdfReader reader = new PdfReader("existing.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileStream("stamped.pdf", FileMode.Create));

// change the content on top of page 1
PdfContentByte cb = stamp.GetOverContent(1);

Rectangle psize = reader.GetPageSize(1);
float width = psize.Width;
float height = psize.Height;

BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
VerticalText vt = new VerticalText(cb);
vt.SetVerticalLayout(width / 2, height / 2, height, 1, 0);
vt.AddText(new Phrase("Test", new Font(bf, 20)));
vt.Go();

stamp.Close();

It is centered on the page, alright, but it is not vertical - but horizontal (actually left aligned horizontally from the center of the page).

Am I doing something wrong here or is iTextSharp misbehaving?

A: 

Try

cb.ShowTextAligned(alignment, text, x, y, rotation);

one name