Hi
I have following to do:
- generate a PDF form a HTML document
- Build a Toc with Page numbers to certain Chapters the document consists of
- Of course I do not know the page numbers at the beginning
The strategy to acheive this is the following:
- First pass
- Build in HTML a temporary TOC with unique markers (like TOC_ agsgej45) instead of the actual page number
- Build in HTML with unique markers (like PAG_agsgej45) instead of the chapter title.
- Convert HTML to PDF with method HtmlToPdf.ConvertUrl()
- Second pass
- Analyze generated PDF page by page to find on which page a marker ist located with the methods
Find (
see below)
- replace in HTML (TOC Page number and Chapter text with appropriate information
- generate again PDF from HTML, but now with correct page numbers and text
Now here is my problem:
In older versions of EO.Pdf (and in Classic mode in new version 16.0.91.0) my methods are always finding the searchText). Unfortunatly with the new engine blink/Chromium this is not the case anymore.
Have you any explanation and alternative to search and find my searchText (= markers) in the PDF?Thanks for your answer
aDue IT GmbH
Pierre Honsberger
Zulligerstr. 48
CH-3063 Ittigen
www.adue-it.com - pgh@adue-it.comThe Find method in C# I developped:
private bool Find(PdfDocument doc, string searchText)
{
int pageNumber = 0;
bool found = false;
foreach (PdfPage page in doc.Pages)
{
pageNumber++;
PdfContentCollection coll = page.Contents;
found = Find(coll, searchText);
if (found)
{
break;
}
}
// Do something with pageNumber!!!
return found;
}
private bool Find(PdfContentCollection coll, string searchText)
{
bool found = false;
if (coll.Count > 0)
{
foreach (var item in coll)
{
PdfTextContent ptc = item as PdfTextContent;
if (ptc != null)
{
if (ptc.Text == searchText)
{
found = true;
break;
}
}
found = Find(item.Contents, searchText);
if (found)
{
break;
}
}
}
return found;
}