c#, itextsharp, aspx

I have 100 pdf files with a field name called 'firstname'
and I want to load all of them and using itextsharp to change the fieldname to 'myfirstname'

how can I do that in itextsharp with c#?

Thanks
LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITsolutionWizardAuthor Commented:
Any helps?
0
Shaun VermaakTechnical Specialist IVCommented:
Please post sample PDF
0
ITsolutionWizardAuthor Commented:
It is just blank PDF with fields any sample will be fine
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Shaun VermaakTechnical Specialist IVCommented:
Is the PDF scanned or generated?
0
ITsolutionWizardAuthor Commented:
It is PDF with textbox fields. It is not scanned doc
0
ITsolutionWizardAuthor Commented:
Any helps
0
Shaun VermaakTechnical Specialist IVCommented:
Going offline, please have a look at this from http://stackoverflow.com/questions/9635982/altering-pdf-through-itextsharp-to-replace-some-existing-text-with-a-new-text
    String formFile = Server.MapPath("~/") + "source.pdf";
    String newFile = Server.MapPath("~/") + "sink.pdf";
    PdfReader reader = new PdfReader(formFile);
    PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Create));
    AcroFields fields = stamper.AcroFields;
    // set form fields
    fields.SetField("{TO}", "John Doe");
    fields.SetField("{FROM}", "2 Milky Way, London");
    stamper.FormFlattening = true;
    stamper.Close();

Open in new window

0
Daniel Van Der WerkenIndependent ConsultantCommented:
The methodology is to use the RenameField() method. I am doing this in the following method, but what my method does is rename *all* the fields in a page from "name" to "1_name" for a page usage I have.

You will want to modify my code. Note that you can't modify the field while it's in use, so that's why I had to rename after the fact as I do in this method:

       /// <summary>
        ///     Renames the AcroFields of the selected page of a PDF file and returns the
        ///     renamed fields as a byte array.
        /// </summary>
        /// <param name="pdfFile">Any PDF file that has valid AcroFields in it.</param>
        /// <param name="pageNumber">The page from that PDF file to rename the fields of</param>
        /// <param name="instanceNumber">The renamed instance number to use.</param>
        /// <returns>byte[] representing the page with renamed fields. Use in PdfReader(byte[]) constructor.</returns>
        public static byte[] RenameFieldsIn(string pdfFile, int pageNumber, int instanceNumber)
        {
            byte[] returnByteArray = new byte[] { };
            const string RENAME_FIELD = "{0}_{1}";
            Dictionary<string, string> renamedDictionary = new Dictionary<string, string>();
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (PdfReader reader = new PdfReader(pdfFile))
                    {
                        reader.SelectPages(new List<int>() { pageNumber });
                        using (PdfStamper stamper = new PdfStamper(reader, ms))
                        {
                            AcroFields fields = stamper.AcroFields;
                            if (fields != null && fields.Fields != null && fields.Fields.Count > 0)
                            {
                                foreach (string key in fields.Fields.Keys)
                                {
                                    // Need to save these here because you can't modify a collection that's being enumerated in-situ
                                    renamedDictionary.Add(key, string.Format(RENAME_FIELD, key, instanceNumber));
                                }
                            }

                            // Modify the collection now
                            foreach (string key in renamedDictionary.Keys)
                            {
                                fields.RenameField(key, renamedDictionary[key]);
                            }
                        }
                    }
                    returnByteArray = ms.ToArray();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return returnByteArray;
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frankhelkCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Daniel Van Der Werken (https:#a42081718)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.