Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:21:14+00:00 2026-06-10T17:21:14+00:00

Given a PDF form with fields already specified, I want to be able to

  • 0

Given a PDF form with fields already specified, I want to be able to put something like this in one of the form fields:

Rodrigo, you are NOT the father!

Using iTextSharp, I can accomplish this (albeit a bit painstakingly) using Rich Text values and passing in XML representing the content with the appropriate bold markup, as per this answer.

However, according to that same answer (and my firsthand experience), you cannot lock+flatten the form (to prevent further editing) after you have done this. Unfortunately, that is also necessary in this case.

The author of the previously-mentioned answer mentions that this can possibly be worked around by “[having Javascript] that resets the field value when the form its opened to force Acrobat/Reader to build the appearance[s] for you.”

How do you add Javascript code to a PDF (preferably via iTextSharp itself, although we may be able to do it on the back-end in the file itself) such that it executes when the form is opened to force the PDF reader to build appearances for you?

Moreover, will this allow us to not have to say GenerateAppearances = false and therefore allow us to lock and flatten the form?

If not, is there something other than iTextSharp that will allow us to make certain words in a form field bold but also lock and flatten the form to prevent future editing once we’re done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:21:16+00:00Added an answer on June 10, 2026 at 5:21 pm

    As I found out there is a way to accomplish this goal, though not via any particularly elegant means (that I know of).

    The way you do it is by using iTextSharp to write a text field directly over the existing form field.

    The main caveat here is that the pdf ceases to become a form, basically, so if you ever need to read the contents of the form fields, you’re hosed.

    On the other hand, if the form fields are basically being used as a simple guide to help tell iTextSharp where to put text on the pdf (and exist for output only), then this might just work.

    using (FileStream filestream = new FileStream(outputpath, FileMode.CreateNew, FileAccess.Write))
    {
        var stamper = new PdfStamper(reader, filestream);
    
        var acroFields = stamper.AcroFields;
    
        string fieldName = "Field Name";
        var fieldPositions = acroFields.GetFieldPositions(fieldName);
    
        var helveticaBold = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14);
        var helveticaRegular = FontFactory.GetFont(FontFactory.HELVETICA, 14);
    
        List<Chunk> chunks = new List<Chunk>();
    
        chunks.Add(new Chunk("Rodrigo, you are ", helveticaRegular));
        chunks.Add(new Chunk("NOT", helveticaBold));
        chunks.Add(new Chunk(" the father!", helveticaRegular));
    
        Phrase currentPhrase = new Phrase();
    
        foreach (Chunk chunk in chunks)
        {
            currentPhrase.Add(chunk);
        }
    
        foreach (var currentPosition in fieldPositions)
        {
            PdfContentByte currentCanvas = stamper.GetOverContent(currentPosition.page);
    
            ColumnText currentColumnText = new ColumnText(currentCanvas);
    
            currentColumnText.SetSimpleColumn(currentPhrase, currentPosition.position.Left,
                                              currentPosition.position.Bottom, currentPosition.position.Right,
                                              currentPosition.position.Top, 13, Element.ALIGN_LEFT);
            currentColumnText.Go();
        }
    
        stamper.FormFlattening = true;
        stamper.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert given text to existing pdf at X,Y location provided. I
Given a PDF, how can one get the layout mode of a PDF (or
I have a PDF form that has 450 fields in it and I'm going
I want to crop pdf by given coordinates using c#. How can I do
I give user the option of uploading a file like this <form action=# onsubmit=return
If I convert the given html to pdf with wkhtmltopdf the chart data will
Sometimes pdf might have a transparent background. And In my application I have given
I am indexing a pdf file using this php script. The curl give me
Given that the web application doesn't have su privileges, I'd like to execute a
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.