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

  • SEARCH
  • Home
  • 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 8209873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:52:48+00:00 2026-06-07T09:52:48+00:00

I am trying to read in a PDF template with iTextSharp, and then automate

  • 0

I am trying to read in a PDF template with iTextSharp, and then automate filling in the forms. The template was created with LiveCycle Developer. I do not know what is wrong with the following code, but it is not changing the form values.

Could someone please tell me what I am doing wrong? It is difficult to find good documentation for the C# version of iText.

private void button_fill_Click(object sender, EventArgs e)
{
     OpenFileDialog ofd = new OpenFileDialog();
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         using (MemoryStream ms = new MemoryStream())
         {
             PdfReader pdfReader = new PdfReader(ofd.FileName);
             PdfStamper pdfStamp = new PdfStamper(pdfReader, ms);
             AcroFields fields = pdfStamp.AcroFields;
             foreach (KeyValuePair<string, AcroFields.Item> f in fields.Fields)
             {
                 // this message is never displayed
                 MessageBox.Show("key: " + f.Key);  
             }

             //textfields
             // this one is working, and showing the value saved in the template
             MessageBox.Show("FakeDatabase_Table1_Company: " + fields.GetField("FakeDatabase_Table1_Company")); 
             // this part returns a false value, and not changing the field
             MessageBox.Show("Set: " + fields.SetField("FakeDatabase_Table1_Company", "Testing")); 

             try
             {
                 fields.SetField("FakeDatabase_Table1_Company", "Coca-Cola");
             }
             catch (Exception e2) { MessageBox.Show(e2.Message); }

             pdfReader.Close();
             pdfStamp.FormFlattening = true;
             pdfStamp.FreeTextFlattening = true;
             pdfStamp.Writer.CloseStream = false;
             pdfStamp.Close();
             Process.Start(ofd.FileName);
        }
    }
}

The try/catch never outputs anything.. nor does it set anything

  • 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-07T09:52:50+00:00Added an answer on June 7, 2026 at 9:52 am

    It turns out the code was fine. The problem was that the pdf was dynamic. My code is now almost working since I changed the pdf to be static. I can now read in the AcroFields, which is what was giving me the issue. It is not actually saving the form with the filled in values yet, but here is what I have so far.

    public void loadPDF(String path)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    PdfReader pdfReader = new PdfReader(path);
                    PdfStamper pdfStamp = new PdfStamper(pdfReader, ms);
                    AcroFields fields = pdfStamp.AcroFields;
                    List<String> Keys = new List<string>();
                    Boolean empty = true;
                    foreach (var field in fields.Fields)
                    {
                        empty = false;
                        Keys.Add(field.Key);
                    }
                    if (empty) MessageBox.Show("The template does not have any form fields in it.");
                    foreach (String k in Keys)
                    {
                        fields.SetField(k, "Testing");
                    }
    
                    pdfReader.Close();
                    pdfStamp.FormFlattening = true;
                    pdfStamp.FreeTextFlattening = true;
                    pdfStamp.Writer.CloseStream = false;
                    pdfStamp.Close();
                    Process.Start(path);
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use iTextSharp to read/modify PDF metadata. I figured out how
I am trying to read multiple files (can be of any format i.e. pdf,
I'm trying to basically understand how a simple PDF is created and turned into
i am trying to read a html file and convert it to pdf using
I'm trying to read a pdf file and get all hyperlinks from this file.
I'm trying to insert and read qrcode's from PDF files. To create/read qr codes
I am trying to download multiple PDF files as one zip file and then
I am trying to extract all the images from a pdf using itextsharp but
I'm trying to read in a file to my perl script and then set
I would like know whether we can highlight text (colors) of already created PDF

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.