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 Sep 01, 2022 4:08 pm

I got a PDF wich is always generated with Spire html to pdf convert. An example is attached. Now I´m writing a "Bookmark Setter" to create bookmarks in all pdf´s we have created the last years. Thix App works almost great, but some things I will make even better.
I can Iterate through the first lines to get the "chapters" and "subchapters" in order (after the headline):
Signal Path 1
- Measurement 1
Signal Path 2
- Measurement 2
- Measurement 3
- Measurement 4

Thats easy.
After that I can find each text-sequence in the content of the pdf and set a bookmark, works fine.
But in some cases I have to find a particulary result or graphic name, to lead the bookmark direct to the result or graphic, not only to the headline of the measurement.
The problem is, the names of these results are dynamicly and I have no chance to read it out first.
These names are in my example:
Result or Graphic 1
Result or Graphic 2
Result or Graphic 3
Result 4

All of these targets are backcolored with the same grey.
And now my quesiton:
Can I find a property background color in the PdfTextFragment List?
I split a page by \n\l in to lines and iterate throug each line or search a text fragment in the whole page.

like this:
Code: Select all
PdfTextFinder pdfTextFinder = new PdfTextFinder(pdfDoc.Pages[seite]);
                pdfTextFinder.Options = pTFO;
                pdfTExtFragment foundList =  pdfTextFinder.Find(findWord);
..
  if(foundList[0].LineText.Trim() == "XYZ")    ===>   && foundList[0].BackgroundColor = Grey
...



And what I want is, to get the background Color of the Segment to select the difference to the other lines.
like this: ===> && foundList[0].BackgroundColor = Grey (or .HighLite = Grey)


The source code from the original html text looks like:

Code: Select all
<span style="position:absolute;top:0.6597221in;left:0.01388884in;width:6.472222in;height:0.1597222in;font-family:Arial;font-size:10pt;color:#000000;vertical-align:top;background-color:LightGrey;"><nobr>NoiseRMS&nbsp;90k&nbsp;:&nbsp;Signal&nbsp;Path&nbsp;Setup</nobr></span>


I dont know, how spire the background translate, maybe into highlite?
Is there a background color poroerty for a text fragemnt or is this only the highlite style in PDF?

wrothenberg
 
Posts: 7
Joined: Tue Aug 02, 2022 7:55 am

Fri Sep 02, 2022 7:27 am

Hello,

Thanks for your inquiry.
Sorry Spire.Pdf can’t implement the function of finding text based on background color, therefore, Spire.Pdf can’t achieve the requirement you mentioned.
If you have any other issue, just feel free to contact us.

Sincerely
Abel
E-iceblue
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF