Replace text in PDF

Technical support for Spire.PDF

Moderator: iceblue support

Replace text in PDF

Postby spoof3r » Wed Aug 31, 2016 6:01 pm

Hello,

I'm still trying to evaluate whether or not this product will satisfy our requirements. We love the text searching, but need to determine whether or not there is a way for us to replace text. Currently it does not seem as though this is possible?
spoof3r
 
Posts: 4
Joined: Sat Aug 13, 2016 4:23 am

Re: Replace text in PDF

Postby Betsy » Thu Sep 01, 2016 2:43 am

Dear spoof3r,

Thanks for your inquiry.
Here is sample code for your reference:
Code: Select all
            PdfDocument doc = new PdfDocument(FilePath + "sample.pdf");
            PdfPageBase page =  doc.Pages[0];
            Dictionary<string, string> dictionary = new Dictionary<string,string>();
            dictionary.Add("123", "Rep");
            FintTextInPDFAndReplaceIt(doc, dictionary);
            doc.SaveToFile("result.pdf");
        }
        public static void FintTextInPDFAndReplaceIt(PdfDocument documents, Dictionary<string, string> dictionary)
        {
            PdfTextFind[] result = null;
            foreach (var word in dictionary)
            {
                foreach (PdfPageBase page in documents.Pages)
                {
                    result = page.FindText(word.Key).Finds;
                    foreach (PdfTextFind find in result)
                    {   
                        //replace word in pdf                   
                        find.ApplyRecoverString(word.Value, System.Drawing.Color.White,true);
                    }
                }
            }
        }

Hope this can help you. If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Re: Replace text in PDF

Postby spoof3r » Sat Sep 03, 2016 8:00 pm

Unfortunately this does not work - it simply overlays ontop of the field which is not what I need. I need the text to cause the entire text to shift around. For example, if I replace the word "this" with "this is a lot of text", the replacement causes other text to be overlapped and run off the page. I need it as if I were editing a Word document - as I type, all the text in the rest of the document is arranged to fit the text I am adding.

Is this not supported? Using Spire.Office is not an option for me because it is too expensive even with discounts. I need a single package that can edit the PDF and achieve what I'm looking for.
spoof3r
 
Posts: 4
Joined: Sat Aug 13, 2016 4:23 am

Re: Replace text in PDF

Postby Betsy » Mon Sep 05, 2016 2:36 am

Dear spoof3r,

Sorry for late reply as weekend.
I am afraid that it is not possible to do that. Sorry for inconvenience.
About price issue, please contact our sales team( Sales@e-iceblue.com).

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Re: Replace text in PDF

Postby yyp » Mon Jul 03, 2017 12:38 am

Are there any updates to this?
yyp
 
Posts: 8
Joined: Thu Jun 15, 2017 10:54 pm

Re: Replace text in PDF

Postby Betsy.jiang » Mon Jul 03, 2017 3:03 am

Dear yyp,

Thanks for your inquiry.
Sorry that there is no update. At present there is only way to replace the text simply, and you could see the code I posted on previous thread, that cover old text and then draw the new string. If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1425
Joined: Tue Sep 06, 2016 8:30 am


Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 0 guests

cron