Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

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

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: 802
Joined: Mon Jan 19, 2015 6:14 am

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

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: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Jul 03, 2017 12:38 am

Are there any updates to this?

yyp
 
Posts: 14
Joined: Thu Jun 15, 2017 10:54 pm

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: 3099
Joined: Tue Sep 06, 2016 8:30 am

Sun Jan 13, 2019 4:40 pm

Hi !
I evaluate Spire.PDF. I met exactly this problem. I wonder if this has been fixed after 3 years?

traderaboy
 
Posts: 1
Joined: Thu Nov 29, 2018 12:04 pm

Mon Jan 14, 2019 5:57 am

Hi traderaboy,

Thanks for your inquiry.
As I said before, there is no direct way to replace the text in PDF. Yet there is a workaround, that is covering the text and then drawing the new string. Please have a try.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF