Solved

Set font name and size using Itextsharp

Posted on 2014-01-27
5
3,186 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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