Welcome Guest Search | Active Topics | Sign In | Register

paginator.Pages greater then pdfDocument.Pages Options
Aaron
Posted: Monday, November 12, 2018 8:26:09 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Hi,

I am using Html 2 Pdf and I am getting a document that renders 33 pages with
- pdfDocument.Pages[0..32] ----- GOOD
- paginator.Pages[0..36] ------ BAD


why does paginator.Pages not match?
Using this to get HtmlElement.Location.PageIndex but gives wrong result.

Details

HtmlToPdfOptions options = new HtmlToPdfOptions();
options.BaseUrl = ConfigurationManager.AppSettings["TemplateBaseUrl"];
options.UsePrintMedia = true;
options.JpegQualityLevel = 100;
options.AutoFitX = HtmlToPdfAutoFitMode.None;
options.AutoFitY = HtmlToPdfAutoFitMode.None;

using (HtmlToPdfSession session = HtmlToPdfSession.Create(options))
{
Paginator paginator = null;
HtmlToPdfResult pdfResult = null;

//-----------------------------------------------------------------
// render document
//-----------------------------------------------------------------
session.LoadHtml(draftHtml);
paginator = session.CreatePaginator();
pdfResult = session.RenderAsPDF(paginator);

...
eo_support
Posted: Monday, November 12, 2018 3:30:33 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

There is a "post process" step after the paging step that removes blank pages. So if some of the pages in the 36 pages in the paginator objects does not contain any contents and is small enough, then it will be removed and results in PdfDocument.Pages to contain less number of pages.

Thanks!
Aaron
Posted: Tuesday, November 13, 2018 3:33:04 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Hi,

Thanks. How can I get the actual page then for a given HtmlElement?

Other
=====
I have 3 pages with a height = 0, so I can be fairly sure that these will be blank pages and so I can filter them out. The next smallest height = 9 and so it is likely that this is the 4th (blank) page, but I can never be sure that a page with a height > 0 is blank or not and so I am getting into the realms of hoping I am filtering out the right pages to match the pdf document. I need to know exactly that I have right page number, as I use it to get hyperlinked page numbers, dynamic header and footer pages etc.

Regards.
eo_support
Posted: Tuesday, November 13, 2018 11:12:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

You can use the HtmlDocument property of the HtmlToPdfResult object to get those information.

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfresult.aspx

This object is only returned after the whole conversion has completed. So all the information there is the "final version".

Thanks
Aaron
Posted: Tuesday, November 13, 2018 11:15:24 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Hi,

To my knowledge there is no way to get from the HtmlElement to a matching part of the HtmlDocument (and get a pageIndex). Please can you elaborate.
eo_support
Posted: Tuesday, November 13, 2018 11:21:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
I am not exactly sure what you meant by getting from the HtmlElement to a matching part of the HtmlDocument. However you CAN get the page index from an HtmlElement's Location property (through HtmlElement.Location.PageIndex).
Aaron
Posted: Tuesday, November 13, 2018 11:26:51 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Hi,

One example is that I am getting all of the footers

e.g. HtmlElement[] footers = paginator.Document.GetElementsByTagName("footer");

I then need to get the Page Index. I was doing this via htmlElement.Location.PageIndex but as my initial post says ... this value is incorrect. It is incorrect because you remove blank pages in the pdfDocument but do not clean up the paginator.pages to match this. So htmlElement.Location.PageIndex is WRONG!
eo_support
Posted: Tuesday, November 13, 2018 11:36:36 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
As we have already mentioned in our previous reply, do NOT use the paginator for ths purpose. Use the HtmlToPdfResult object's instead. So in your original code, instead of using paginator.Document.GetElementsByTagName, you would use pdfResult.HtmlDocument.GetElementsByTagName. Please let us know if that works for you.
Aaron
Posted: Tuesday, November 13, 2018 11:40:07 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
Cheers. I will give that a go and let you know.
Aaron
Posted: Wednesday, November 14, 2018 4:32:07 AM
Rank: Advanced Member
Groups: Member

Joined: 12/13/2017
Posts: 29
SOLVED! Thanks, that worked perfectly.

summary for others
=============
DONT use paginator to get HtmlElement as its Location.PageIndex is INCORRECT
DO use htmlToPdfResult.HtmlDocument to get HtmlElement as its Location.PageIndex is CORRECT

eo_support
Posted: Wednesday, November 14, 2018 9:46:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Thanks for confirming that it works for you. Your summary is not accurate. Both PageIndex values are CORRECT. But they are values at different stages for different purposes. The PageIndex on the Paginator class is for you to examine the intermediate paging result (so that you may choose to adjust/repaging if needed). The PageIndex from the HtmlToPdfResult object on the other hand represents the final result. In your case since you need the final result, not the intermediate result, you would need to get it from the HtmlToPdfResult object, not the Paginator object. This does not mean the Paginator's result is incorrect. It's just for a different purpose.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.