views:

35

answers:

2

I'm using the iText library for .NET to generate a PDF. I need to output a PDF with an image, which has three text strings positions centered vertically, but absolute Y positions. Each string uses a different font. I've been struggling for hours to find a way to do this, I can get the first line on Ok using SetSimpleColumn(), but further attempts have been fruitless.

Is there a way to do this?

A: 

I have never used either iText or iTextSharp, which I think you're referencing to. Despite, I have used PDF Sharp which offered a MeasureString() method. This method, given a Font and a string is able to measure the string from its XGraphics class which has the information about DPI, etc.

I guess that if you took an eye out to the equivalent class and method with iText, you should be able to do something, if it even exists.

I know it's not much help, but I hope to have given you some idea for a workaround.

Will Marcouiller
I need it to work in Medium Trust, which unfortunately PDFSharp doesn't. :(I just need to position the 3 text sections at specific places, centered horizontally.
Echilon
Right, but have you looked for such a `MeasureString()` or an equivalence with *iText* to allow you to measure the string given the font and the string you want to center? After you got this, the rest is not much of a child play. =)
Will Marcouiller
Yes, but I posted the question as I couldn't find anything.
Echilon
A: 

I eventually got this working with:

int y_offset = 20;
Phrase fullTitle = new Phrase("Some string", myFont);
ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, fullTitle, center, y_offset, 0);
Echilon