|
Rank: Newbie Groups: Member
Joined: 12/13/2013 Posts: 3
|
Hey, We use the EO.PDF Corporate license. I am having a problem when an element has page-break-inside: avoid and the height of this element is greater than 1 page height the element gets bumped to next page. In this use case it creates unnecessary/ugly space. I have "modules" of varying height having page-break-inside: avoid is needed for those cases. Any suggestions? Thanks. Test Html: http://jsfiddle.net/vvmdf/Creating PDF using EO.PDF v5.0.49.2:
Code: C#
var html = new StreamReader(@"G:\break_example.html").ReadToEnd();
HtmlToPdf.ConvertHtml(html, @"G:\break_example.pdf", new HtmlToPdfOptions()
{
PageSize = PdfPageSizes.Letter,
OutputArea = new RectangleF(0.25f, 0.25f, PdfPageSizes.Letter.Width - (2f * 0.25f), PdfPageSizes.Letter.Height - (2f * 0.25f))
});
PDF output:
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Try to set your HTML file's body element's margin and padding to 0 and see if that helps. What happens is, by default the body element has an margin and padding. So the available space for the first page is paper height - (body margin + body padding), where as the second page's available space is the full paper height. Because the converter sees the second page has more available space, it would move contents to the second page in an attempt to make it to "fit better".
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/13/2013 Posts: 3
|
eo_support wrote:Hi,
Try to set your HTML file's body element's margin and padding to 0 and see if that helps. What happens is, by default the body element has an margin and padding. So the available space for the first page is paper height - (body margin + body padding), where as the second page's available space is the full paper height. Because the converter sees the second page has more available space, it would move contents to the second page in an attempt to make it to "fit better".
Thanks! Thanks, for the reply. I've tried what you suggested and it didn't seem to affect the PDF. Updated HTML example: http://jsfiddle.net/vvmdf/1/Image of PDF: (I changed the background color of <body> to red to better show its space.) and for reference this is how Chrome print handles the page breaks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
This is normal and what you see is the correct behavior. In your case, the goal of the paging process is to try to honor page-break-inside:avoid as much as possible. When it is not possible to honor page-break-inside:avoid because of the block is too big, the pager try to fit as much as possible. In your case, it would fit more on the second page than on the first page because the first page already has the "page-header" that has already took some available space. If you remove the "page-header" section, the contents would be placed on the first page.
If you would like to keep contents on the first page and keep the page-header at the same time, you can remove your page-header from your HTML, then use additional code to render the page-header ---- for example, by calling HtmlToPdf.ConvertHtml on the first page after the main conversion is done.
Hope this helps. Please feel free to let us know if you have any more questions.
Thanks!
|
|