|
Rank: Newbie Groups: Member
Joined: 1/16/2019 Posts: 8
|
Hello, EO.PDF: 19.0.69 we use tables in our HTML reports and have issues with rendering of page breaks within tables in converted PDF documents. What can be the problem? Corresponding code for HTML converting
Code: C#
using System.Drawing;
using System.IO;
using EO.Pdf;
namespace EOPdf.Html2PDF.Test
{
internal class PdfGenerator
{
private const int PagePaddingTop = 28;
private const int PagePaddingBottom = 24;
private const int PagePaddingLeft = 17;
private const int PagePaddingRight = 17;
static PdfGenerator()
{
}
internal static HtmlToPdfResult HtmlToPdfResult(string reportText, string cl0Page, string pageHeader)
{
// Define PDF Header
//Set margins to 0.5 inch on all sides
var options = new HtmlToPdfOptions
{
HeaderHtmlFormat = pageHeader,
FooterHtmlFormat = "<div style=\"text-align:right;\">" + cl0Page + " {page_number} / {total_pages}</div>",
AutoBookmark = true,
// Activate option to repeat header row for data tables.
RepeatTableHeaderAndFooter = true,
//ZoomLevel = 1.0f,
//AutoFitX = HtmlToPdfAutoFitMode.ShrinkToFit,
AfterRenderPage = PdfGenerator_AfterRenderPage,
PageSize = PdfPageSizes.A4,
OutputArea = new RectangleF(MmToInch(PagePaddingLeft), MmToInch(PagePaddingTop), PdfPageSizes.A4.Width - MmToInch(PagePaddingRight + PagePaddingLeft), PdfPageSizes.A4.Height - MmToInch(PagePaddingTop + PagePaddingBottom))
};
// remove header and footer at front-page
var doc = new PdfDocument();
var result = EO.Pdf.HtmlToPdf.ConvertHtml(reportText, doc, options);
return result;
}
private static float MmToInch(int mm)
{
return 0.03937007874015748f * mm;
}
/// <summary>
/// This function is called after every pdf-page is created.
/// </summary>
private static void PdfGenerator_AfterRenderPage(object sender, PdfPageEventArgs args)
{
if (args.Page.Index == 0)
{
// hide header
// create a div element that will cover up the default header
const string areaWhiteout = "<div style='background-color:#fff; width:850px; height:155px;'></div>";
// set the new output area to be over the header
var options = new HtmlToPdfOptions { OutputArea = new RectangleF(0, 0, 8.5f, 1) };
// write the white div block over the header
EO.Pdf.HtmlToPdf.ConvertHtml(areaWhiteout, args.Page.Document.Pages[0], options);
}
}
}
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, We can't tell much just by looking at your code without your actual test file. We did fix a problem with paging in our latest build (19.0.97), which we just posted today. So you may want to download the new build and see if it resolves the problem for you. If the new build still does not resolve the problem for you, you can try to create a test project and send the test project to us. See here for more details: https://www.essentialobjects.com/forum/test_project.aspxOnce we have the test project we will be happy to investigate further. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2019 Posts: 8
|
Hi,
Thank you for your feedback. I've tried the newest version 19.0.97 with same result. I'll send you a test project to reproduce the paging issues.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, We have looked into the test project you sent to us. I am not sure if I understand your question correctly. However page break inside the table is normal. There is no rule that says page break can not occur inside a table (otherwise how will large tables that's longer than one page be rendered?). If you wish to prevent page break inside a table, you can explicitly apply table { page-break-inside: avoid } CSS rule in your HTML. See here for more details: https://www.essentialobjects.com/doc/pdf/htmltopdf/paging.aspxPlease let us know if this resolves the issue for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2019 Posts: 8
|
Hi,
the problem is not a page break within tables itself but the rendering issues of the page breaks. Please review the rendering of page breaks which I note in my email. You will see some rendering issues. How can we avoid the rendering issues?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Can you explain what rendering issues? Your email only contains information like "* Resul1.pdf Issues ** Page break 5 - 6" without explaining what is wrong.
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2019 Posts: 8
|
Hi,
i've sent you an email with screenshots. hope it helps.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, We have received the screenshots. The issues you see is normal. There are various ways for you to alleviate the problem but you can not elimiate them. The root of the problem is how the paging process works. To understand how paging works, imagine that the whole output is first printed on a single piece of very very long paper. After that output is produced, the paging process will attempt to "cut" this single piece of very long paper into multiple pages. This process works very well for regular output but several issues become apparent especially with tables with border lines. The most visible issue is that paging process does not produce additional output. This means table lines will NOT be duplicated. Consider the following example: row 1
row 2 Assume there is a page break between row 1 and row 2. This means the horizontal line between row 1 and row 2 will either be on the first page or the second page. It will not be on both (because the paging process does not duplicate output contents). This means either the last row on the previous page or the first row on the next page will be "open". This is one of the main issue you see. The easiest way for you to avoid such issue is to keep the whole table on a single page. You can easily add the following CSS rule in your HTML to achieve this:
Code: CSS
table
{
page-break-inside: avoid;
}
In case you have large tables that is not possible to fit on a single page. You can try to use this instead:
Code: CSS
tr
{
page-break-inside: avoid;
}
This will attempt to keep a single row on the same page thus avoid page break from occurring in the middle of a row, which is some of the problems in your case. Hope this helps. Please feel free to let us know if you still have any more questions. Thanks!
|
|