Solved

Set font name and size using Itextsharp

Posted on 2014-01-27
5
3,526 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
[X]
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
5 Comments
 
LVL 30

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 30

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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