|
Rank: Member Groups: Member
Joined: 10/10/2011 Posts: 13
|
When using HtmlToPdf.ConvertUrl, text is in a table is cut off. On the bottom of the page the bottom half of the text line is missing and on the next page, the top half of the line is missing. Is there a way to fix this?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
It should automatically avoid cutting off small text unless it is not possible to avoid them (for example, if you have two column of text that are not aligned line by line, then a clear cut may not exist because if you avoid text on the left column it will cut the text on the right column and vice versa). For large text, it will not try to avoid cutting off them. You can also manually avoid any element being cut into multiple pages using "page-break:avoid" CSS style: http://doc.essentialobjects.com/library/4/htmltopdf/paging.aspxIf you do have small text being cut off while a clear cut line exists, then it's a bug. In that case please create a small test app to reproduce the problem. We will be happy to take a look as soon as we have that. Thanks!
|
|
Rank: Member Groups: Member
Joined: 10/10/2011 Posts: 13
|
It is small text. If you run the below code, it will generate a PDF off our site.
Code: C#
private void EssentialObjectsUrl()
{
string url = "http://corememberguide.hostplus.staging.clickdm.com.au/pdf/pdf-fees-and-costs";
var doc = new PdfDocument();
HtmlToPdf.Options.BeforeRenderPage += this.OnBeforeRenderPage;
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
HtmlToPdf.Options.ZoomLevel = .8f;
// Setting header and footer format
//HtmlToPdf.Options.HeaderHtmlFormat = "";
//HtmlToPdf.Options.FooterHtmlFormat = "We're here to help - call 1300 HOST<strong>PLUS</strong> (1300 467 875), 8am - 8pm, Monday to Friday or visit hostplus.com.au";
SizeF pageSize = PdfPageSizes.A4;
float marginLeft = 1.8f;
float marginTop = 1f;
float marginRight = 1.8f;
float marginBottom = 1f;
HtmlToPdf.Options.PageSize = pageSize;
HtmlToPdf.Options.OutputArea = new RectangleF(
marginLeft,
marginTop,
pageSize.Width - marginLeft - marginRight,
pageSize.Height - marginTop - marginBottom);
HtmlToPdfResult result = HtmlToPdf.ConvertUrl(url, doc);
// Now search for all elements with class name set to "sflistTitle"
HtmlElement[] elements = result.HtmlDocument.GetElementsByClassName("sflistTitle");
// Create a bookmark for each of these elements
foreach (HtmlElement element in elements)
{
// Skip invisible elements
if (!element.IsVisible)
{
continue;
}
// Create the bookmark
PdfBookmark bookmark = element.CreateBookmark();
bookmark.Text = bookmark.Text.Trim();
doc.Bookmarks.Add(bookmark);
//To create child bookmarks, create a new
//PdfBookmark object and then add it to the
//parent bookmark's ChildNodes collection
}
// Merge cover page and last page
doc.Save(@"c:\temp\EssentialObjectsUrl.pdf");
}
/// <summary>
/// Adds a background image to the page before any text is added.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The PDF page event args.
/// </param>
private void OnBeforeRenderPage(object sender, PdfPageEventArgs e)
{
SizeF pageSize = PdfPageSizes.A4;
float marginLeft = 0f;
float marginTop = 0f;
float marginRight = 0f;
float marginBottom = 0f;
HtmlToPdf.Options.PageSize = pageSize;
HtmlToPdf.Options.OutputArea = new RectangleF(
marginLeft,
marginTop,
pageSize.Width - marginLeft - marginRight,
pageSize.Height - marginTop - marginBottom);
HtmlToPdf.ConvertHtml(@"<img src=""http://corememberguide.hostplus.staging.clickdm.com.au/PDF/MemberGuide_Template.png"" />", e.Page);
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
We have looked into this problem. The problem is caused by "page-break-inside:avoid" on your li item. When this style is applied, the HTML to PDF converter will not attempt to auto-page contents inside that block. So it will go on until wherever the page ends, thus causing the cut off for you. As soon as you turn "page-break-inside:avoid" off, the text should work for you again.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 10/9/2012 Posts: 4
|
Hello, we're having this problem where the text is cutting off. We use "page-break-inside: auto", but not "avoid". Is there a way around this? Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Quinn wrote:Hello, we're having this problem where the text is cutting off. We use "page-break-inside: auto", but not "avoid". Is there a way around this? Thanks! There are different scenarios where text can be cut off, some of them are inevitable and you must modify your HTML to avoid it. The most common scenarios are: 1. When you have multiple column of texts and they are not aligned line by line (for example, they are not the same font size). In this case no matter where the page break occurs, it would either cut off some text in the left column or some text in the right column. You must change your HTML layout if this is the root cause; 2. If your line height is smaller than text height in CSS, it can cause the text to be cut off. In this case you will need to correct your CSS; If you still can not find out the root cause, please try to isolate the problem into a test file and send the test file to us. See here for more details: https://www.essentialobjects.com/forum/moderate_index.aspxOnce we have that we will be happy to take a look and see what we can find. Thanks!
|
|