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 Jun 16, 2021 11:37 am

Hi,

I am trying to find and replace a text in PDF used the sample code as it is.

But the output file the old text is replaced by a blank text. I am using the free version now.

Please help.

Thank you

AmisHealth
 
Posts: 8
Joined: Fri Apr 21, 2017 5:59 am

Thu Jun 17, 2021 3:30 am

Hello,

Thanks for your inquiry.

I simulated a PDF file and tested the following code several times, but I did not reproduce your issue.
Code: Select all
            String input = @"SearchReplaceTemplate.pdf";
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);

            PdfPageBase page = doc.Pages[0];
            PdfTextFindCollection collection = page.FindText("Spire.PDF for .NET", TextFindParameter.IgnoreCase);
            String newText = "Spire.PDF API";
            PdfTextFind find = collection.Finds[0];
            PdfBrush brush = new PdfSolidBrush(Color.DarkBlue);
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 15f, FontStyle.Bold));
            RectangleF rec = find.Bounds;
            page.Canvas.DrawRectangle(PdfBrushes.White, rec);
            page.Canvas.DrawString(newText, font, brush, rec);
            String result = "ReplaceFirstSearchedText_out.pdf";

            doc.SaveToFile(result);


To help us reproduce your issue and help you solve it, please provide your input file, your complete code. You could send them to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Jun 21, 2021 11:02 am

Hello,

Has your issue been resolved? If not, could you please provide your input file and your complete code to us for further investigation?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF