Solved

Set font name and size using Itextsharp

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Directions API to Map URL -C#? 3 38
Import Data from Multiple Text Files in Excel 12 62
How to duplicate form in Visual Studio 2015 2 62
System.net.Sockets Error 5 28
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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