Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Could you please help me in the following scenario.

I have editable pdf form, and want to update the field programmatically (C#) without creating new file. I tried using iTextSharp but its allowing me to read and write file simultaneously.

Do you guys have any idea how i can achieve this. Any help will be much appreciated.

Thanks in advance.

What I have tried:

C#
string Scr = @"D:\temp\notifications\ReadFrom\pdfSource.pdf";
            string Dst = @"D:\temp\notifications\WriteTo\PdfDestination.pdf";


            try
            {

                PdfReader reader = new PdfReader(Scr);  //Source File
                using (FileStream ms = new FileStream(Dst, FileMode.OpenOrCreate, FileAccess.ReadWrite))  // Destination File Location
                {
                    PdfStamper st = new PdfStamper(reader, ms);
                    AcroFields fds = st.AcroFields;
                    var keys = fds.Fields.Keys;

                    
                    foreach (string item in keys)
                    {
                        if (item.Contains(FieldName)) // && item.GetValue(FieldName) != DBValue
                        {
                            fds.SetField(item, UserEnteredFieldValue);
                            //int i = fds.GetRevision(item);
                        }
                    }
                    
                    st.FormFlattening = true;
                    st.Writer.CloseStream = false;
                    st.Close();
                }
            }
            catch (Exception ex)
            { }
Posted
Updated 20-Oct-16 1:38am

1 solution

You can try This[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900