Solved

Set font name and size using Itextsharp

Posted on 2014-01-27
5
3,044 Views
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.SetFieldFlags(PdfAnnotation.FLAGS_PRINT)
                field.FieldName = "my fieldname"
                stamp.AddAnnotation(field, 1)
0
Comment
Question by:VBdotnet2005
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 39814012
0
 

Author Comment

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

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

Author Comment

by:VBdotnet2005
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)))
        {
            document.Open();
            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.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
            _Field1.FieldName = "t1";
            writer.AddAnnotation(_Field1);
            cb = writer.DirectContent;
            document.Close();
        }
    }
}
0
 
LVL 29

Expert Comment

by:anarki_jimbel
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.
0
 

Author Comment

by:VBdotnet2005
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.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
            _Field1.FieldName = "t1";
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now