« Return to Thread: TextField and cell events : font size

TextField and cell events : font size

by Maxime Labat :: Rate this Message:

Reply to Author | View in Thread

Hello,

I'm currently generating some TextFields using the TextField class and am using cell events to put these textfields at an appropriate position.

However I have some trouble setting the font size.

My problem is, I try to set the textfields text using the Text property. My text is stored in the PDF - but does not display properly :



As you can see, the text uses a kind of "scaling" that I believe is normal, considering I embed the textfield in a cell event. I'm looking for a way to disable this.
The font and fontsizes are correctly set as, when I click in a textfield, the font size and style are correct, and, curiously, there are 2 different behaviours :
- if the textfield text is modified, the font size and style remain correct
- if it is not modified, the text is scaled to the size of the cell again.

Here is a code preview (I deliberately removed some parts not involved) :

using itext = iTextSharp.text;

itext.pdf.PdfPTable aTable;
aTable = new itext.pdf.PdfPTable(1);
aTable.WidthPercentage = 100;
itext.Rectangle rectangle = new itext.Rectangle(0, 0, 100, 30);
itext.pdf.TextField textField = new itext.pdf.TextField(writer, rectangle, this.FormCtrl_Id + "celltextbox");
itext.Font fieldFont = itext.FontFactory.GetFont("Courier", 10);
textField.Font = fieldFont.BaseFont;
itext.pdf.PdfPCell celltextbox = new itext.pdf.PdfPCell();
celltextbox.MinimumHeight = this.Rows * 10;
textField.FontSize = 10;
if (this.Rows > 1)
    textField.Options = itext.pdf.TextField.MULTILINE;
textField.Alignment = itext.Element.ALIGN_TOP;
textField.Text = FreeFieldValue; //(FreeFieldValue contains the text to show, for example "azdazd")
celltextbox.BorderWidth = 1;
           
itext.pdf.events.FieldPositioningEvents events = new itext.pdf.events.FieldPositioningEvents(writer, textField.GetTextField());
celltextbox.CellEvent = events;

aTable.AddCell(celltextbox);

Thanks for the help...

Maxime LABAT

 « Return to Thread: TextField and cell events : font size

LightInTheBox - Buy quality products at wholesale price!