Welcome Guest Search | Active Topics | Sign In | Register

HTML to PDF of unknown length Options
Kevin J
Posted: Thursday, November 17, 2016 1:40:05 AM
Rank: Newbie
Groups: Member

Joined: 11/17/2016
Posts: 2
Hi

We are wanting to evaluate EO.Pdf 2016 for .NET and so far from the documentation it is looking good except for one use case.

We need to convert a HTML doument to PDF to print on a slip printer. So we can provide the width of the page, however the page is a continuous page and we only want it to be the size it needs to be, ie. it could be 5" or 25" in height. Is this possible and how could we do it?

Thank you for your time.

Regards
Kevin
eo_support
Posted: Thursday, November 17, 2016 8:40:34 AM
Rank: Administration
Groups: Administration

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

In theory you can set the page height to whatever value you want it to be:

https://www.essentialobjects.com/doc/pdf/htmltopdf/page_size.aspx

However in practice many viewer application has implementation limits. So if the size exceeds that limit, then they may not be able to render/print the result file correctly.

Thanks!
Kevin J
Posted: Friday, November 18, 2016 12:03:24 AM
Rank: Newbie
Groups: Member

Joined: 11/17/2016
Posts: 2
Hi

So there is no way for ConvertHtmlToPdf function to automatically calculate the page height? It could be quite useful to have a continuous page flag where EO.Pdf would just generate 1 single page from the html document.

Regards
Kevin
eo_support
Posted: Friday, November 18, 2016 7:59:42 AM
Rank: Administration
Groups: Administration

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

You can get the full height with the converter but you will need to run the converter twice. The first time for getting the page height and then the second time to get the final output. There are multiple ways to do it. The following is one way to do it:

Code: C#
//Convert the contents
PdfDocument doc = new PdfDocument();
HtmlToPdfResult result = HtmlToPdf.ConvertUrl(your_url, doc);

//Get the total pixel height from the body element
int totalHeightInPixel = result.HtmlDocument.Body.PageBreakRange.Bottom;


You will need to convert the pixel height to inch:

Code: C#
//Convert pixel height to inch height
double totalHeightInInch = totalHeightInPixel / 72 * result.ZoomLevel


You can then use this height value to set HtmlToPdf.Options.PageSize and run the conversion again to output everything on a single page.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!




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.