Welcome Guest Search | Active Topics | Sign In | Register

PDF: displaying subtotals per page Options
RvanOlst
Posted: Wednesday, October 16, 2013 10:11:47 AM
Rank: Newbie
Groups: Member

Joined: 4/27/2013
Posts: 5
Dear EO,

I'd like to use HtmlToPdf to produce an invoice which can contain many entries and therefore be several pages long. To accommodate the user, I'd like to include a page subtotal at the bottom of each page. However, I can't find a way how to achieve that.

I've look at your samples and documentation, but I don't know how to determine where a page break will occur (or has occurred). Is there a way to determine that, and based on that information either pre-process my HTML document or post-process my PDF page/document? If not, is there another way to achieve subtotals per page?

With kind regards,

Robin van Olst
eo_support
Posted: Wednesday, October 16, 2013 12:02:54 PM
Rank: Administration
Groups: Administration

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

It is possible to do that but it would require some code on your side. You can determine where a page break HAS occurred, but there is no way for you determine where a page break will occur until it has occurred. The determine where a page break has occurred, you would use the HtmlToPdfResult object returned by ConvertHtml method, then use one of the GetElementXXX methods to get an HtmlElement object:

http://www.essentialobjects.com/doc/4/eo.pdf.htmldocument.getelementbyid.aspx
http://www.essentialobjects.com/doc/4/eo.pdf.htmldocument.getelementsbyclassname_overloads.aspx
http://www.essentialobjects.com/doc/4/eo.pdf.htmldocument.getelementsbyname_overloads.aspx
http://www.essentialobjects.com/doc/4/eo.pdf.htmldocument.getelementsbytagname_overloads.aspx

From the returned HtmlElement object, you can find out the page index:

http://www.essentialobjects.com/doc/4/eo.pdf.htmlelement.location.aspx

Basic on that information you will find out where the page break has occurred. However there are several problems:

1. You have to enumerate all elements to find out where the page break occurred, which may have performance implications;
2. Once you add the subtotal row, the page layout changes and page break location for all following pages may change;

To avoid the second problem, you can set HtmlToPdf.Options.OutputArea to explicitly reserve some spaces at the bottom of the each page so that when you add the subtotal row without affect the page layout. If you use this method, you will need to run the main content without the sutotal information first, then get the page break location (based on which you will calculate your subtotal), then call ACM interface to HTML to PDF interface again to add the subtotal information to each page.

Hope this helps.

Thanks!

RvanOlst
Posted: Thursday, October 17, 2013 4:06:31 AM
Rank: Newbie
Groups: Member

Joined: 4/27/2013
Posts: 5
Hello EO,

Thank you for your extensive response, it is very helpful! I'm glad to know that it is possible to achieve this.

Regarding the second problem you mentioned: I was thinking of using a table to display all the data and using the table footer to display the subtotal. This table footer can be displayed on every page the table is drawn on, as demonstrated in your demo "Repeating Table Header and Footer". The advantage is that I won't have to deal with an extra row causing layout changes or having to add a custom OutputArea. I figured I could simply set the InnerText of the relevant table footer cell on that page. Is this possible, or do you forsee any problems with this solution? (Apologies for not actually trying it, but I'm currently not able to do so.)

With kind regards,

Robin van Olst
eo_support
Posted: Thursday, October 17, 2013 9:47:55 AM
Rank: Administration
Groups: Administration

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

Yes. Using repeating table header/footer feature is a good idea from layout point of view.

However I do not think you can set InnerText of the "relevant footer cell". The reason is there is no "relevant footer cell". There is only one footer and the same footer is repeated on every page. As such if you set InnerText for the footer cell, the same value would appear on all page. So in order to have different values, you still have to do the multi-pass approach.

Thanks!
RvanOlst
Posted: Thursday, October 17, 2013 10:25:16 AM
Rank: Newbie
Groups: Member

Joined: 4/27/2013
Posts: 5
Hello EO,

Thank you for the information! In the case I will have further questions regarding this subject later on, I'll make sure to post back here.

With kind regards,

Robin van Olst


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.