Rank: Newbie Groups: Member
Joined: 5/21/2013 Posts: 1
|
Hi,
Do you have any way to create an index of the amount of generated pages, for example.
Chapter 1 ....................... page 1 Chapter 2 ....................... page 3 Chapter 3 ....................... page 7
The page of each chapter can change as the user-entered text size.
I need to know which page of each chapter this.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, You will need to run the converter twice for this. The first run is for you to get the page number, the second run is for you to create the final output. The code will be something like this:
Code: C#
//Perform the first conversion
PdfDocument doc = new PdfDocument();
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(html_without_page_number, doc);
//You need to have "marker" elements in your HTML for you to get
//the page number. The following code assumes that you have an
//element with ID "chapter1" at the begining of "chapter1"
HtmlElement element = result.HtmlDocument.GetElementById("chapter1");
int page_index_for_chapter1 = element.Location.PageIndex;
//Now reformat your original HTML to have the actual page number
//And run the conversion again
string final_html = FillInPageNumbers(.....);
//Create a new PdfDocument for the final result
doc = new PdfDocument();
HtmlToPdf.ConvertHtml(final_html, doc);
Hope this helps. Please feel free to let us know if you have any more questions. Thanks!
|