Set font name and size using Itextsharp

Posted on 2014-01-27
Last Modified: 2014-09-30
Is there a way to change Font name using Itextsharp.  I can set fieldname or rename it, but I can't figure it out how to set font name and size.  

Dim field As PdfFormField = PdfFormField.CreateTextField(stamp.Writer, False, False, 50)
                field.SetWidget(New iTextSharp.text.Rectangle(box position), PdfAnnotation.HIGHLIGHT_INVERT)
                field.FieldName = "my fieldname"
                stamp.AddAnnotation(field, 1)
Question by:VBdotnet2005
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 30

Accepted Solution

anarki_jimbel earned 500 total points
ID: 39814012

Author Comment

ID: 39815642
I tried it.  It still won't change fontname in field properties for my textbox.

        pdfStamper.AcroFields.SetFieldProperty("Text1", "textfont",
fieldFontRoman, null);

Author Comment

ID: 39815756
Please see this link

How can I set fontname ?

public void CreateTextBoxMethod2()
    Document _document = new Document();
    PdfReader reader = new PdfReader(Server.MapPath(P_InputStream));
    using (Document document = new Document())
        using (PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath(P_OutputStream), FileMode.Create)))
            PdfContentByte cb = writer.DirectContent;
            PdfFormField _Field1 = PdfFormField.CreateTextField(writer, false, false, 50);
            _Field1.SetWidget(new iTextSharp.text.Rectangle(40, 100, 160, 130),PdfAnnotation.APPEARANCE_NORMAL);
            _Field1.FieldName = "t1";
            cb = writer.DirectContent;
LVL 30

Expert Comment

ID: 39815864
Honestly, I don't know what the problem is. I looked through some posts and people advise to play with field properties like auto resizing etc.

Author Comment

ID: 39815986
I appreciated your help. I have been playing with field properties, but still can't figure it out how to set fontname.

   PdfFormField _Field1 = PdfFormField.CreateTextField(writer, false, false, 50);
            _Field1.SetWidget(new iTextSharp.text.Rectangle(40, 100, 160, 130),PdfAnnotation.APPEARANCE_NORMAL);
            _Field1.FieldName = "t1";

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
array not updating 8 41
Call a function in Javascript 6 51
SSIS - Using VB.NET to parse XML file 11 40
XML and Linq - reading fields in repeating nodes 3 24
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question