I'm building a table of contents, to do that i first render html, then loop through the contents to get locations (page index) for the elements in the table of contents, and then rerender the html with the page indexes passed as a parameter to the html (code below).
Sometimes, the returned element location is off by 1 page (index is 1 too low).
It looks like if an element has been pushed to the top of the next page by break-after / break-before css, the returned index is wrong.
(using version 20.0.81)
Here's the code I'm using:
Code: C#
var pageNumbers = new PdfDocument();
var pageNumbersResult = HtmlToPdf.ConvertUrl(url + "&showPages=np", pageNumbers, options);
var index = "";
var i = 0;
var el = pageNumbersResult.HtmlDocument.GetElementById("h" + i);
while (el != null && i < 200)
{
index += "," + (el.Location.PageIndex + 1);
i++;
el = pageNumbersResult.HtmlDocument.GetElementById("h" + i);
}
if (index.StartsWith(",")) index = index.Substring(1);
var pages = new PdfDocument();
HtmlToPdf.ConvertUrl(url + "&showPages=np&index=" + index, pages, options);
I'm hoping it's just me doing something wrong :)