Heinz4711 wrote:Hello,
In a PDF I can find and highlight selected text like so:
- Code: Select all
foreach (PdfPageBase page in pdf.Pages)
{
result = page.FindText("Youth").Finds;
foreach (PdfTextFind find in result)
{
find.ApplyHighLight();
}
}
But how can I find what font and fontsize is used in the selected text (in this example for text "Youth" ) ?
So something like "find.Font" which will give me "Arial 12" or simlar ?
Thank you
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,
Abel
E-iceblue support team