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.

Thu Jun 06, 2019 9:57 am

Hello

I am using freespire pdf to locate text in a pdf document and then to apply a highlight. I am using FindText and ApplyHighlight to achieve this. I have now been asked to highlight the text by changing the font (eg bold, underline, colour) rather than a highlight box, but this does not appear to be anywhere near as simple as a highlight.

Can this be done in a fairly straightforward manner?

Thank you.

PdfNovice
 
Posts: 2
Joined: Thu Jun 06, 2019 9:47 am

Fri Jun 07, 2019 5:26 am

Hello,

Thanks for your inquiry.
I am sorry that at present our Spire.Pdf doesn't support to modify the font style of text found using FindText.
We will inform you when it is supported in the future.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Fri Jun 07, 2019 7:33 am

Thank you for your response.

PdfNovice
 
Posts: 2
Joined: Thu Jun 06, 2019 9:47 am

Fri Jun 07, 2019 9:39 am

Hi,

You're welcome.
Welcome to write to us if you need any assistance.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 24, 2024 3:37 am

Hi,

Thank you for your patience.

I'm glad to inform you that our Spire.PDF has supported retrieving font formatting of found text. Note: Only supports retrieving bold, faux bold (font style set to fill and stroke), italic, and color; does not support retrieving underline.

Welcome to download and test [Spire.PDF Pack(Hot Fix) Version:10.4.7].
Our website link:https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
NuGet link: https://www.nuget.org/packages/Spire.PDF

Code: Select all
  PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(inputFile);
            PdfPageBase page = pdf.Pages[0];
            PdfTextFinder finds = new PdfTextFinder(page);
            finds.Options.Parameter = TextFindParameter.None;
            List<PdfTextFragment> result = finds.Find("hello");
            StringBuilder str = new StringBuilder();
            foreach (PdfTextFragment find in result)
            {
                string text = find.LineText;
                string FontName = find.TextStates[0].FontName;
                float FontSize = find.TextStates[0].FontSize;
                string FontFamily = find.TextStates[0].FontFamily;
                bool IsBold = find.TextStates[0].IsBold;
                bool IsSimulateBold = find.TextStates[0].IsSimulateBold;
                bool IsItalic = find.TextStates[0].IsItalic;
                Color color = find.TextStates[0].ForegroundColor;
                str.AppendLine(text);
                str.AppendLine("FontName: " + FontName);
                str.AppendLine("FontSize: " + FontSize);
                str.AppendLine("FontFamily: " + FontFamily);
                str.AppendLine("IsBold: " + IsBold);
                str.AppendLine("IsSimulateBold: " + IsSimulateBold);
                str.AppendLine("IsItalic: " + IsItalic);
                str.AppendLine("color: " + color);
                str.AppendLine(" ");
            }
            PdfTextReplacer ptr = new PdfTextReplacer(page);
            ptr.ReplaceAllText("hello", "New");
            File.WriteAllText(outputFile_T, str.ToString());
            pdf.SaveToFile(outputFile);
            pdf.Dispose();


If you have any questions, please let us know.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF