Welcome Guest Search | Active Topics | Sign In | Register

Preventing a table with cells that are more than a page from starting on a new page Options
NeilJM
Posted: Tuesday, June 19, 2012 6:10:48 AM
Rank: Newbie
Groups: Member

Joined: 9/1/2011
Posts: 4
Hi there,

I have a web page that I am converting to PDF that has multiple sections, each of which has its own heading and then a body of content. I need the headings to appear on each page where the sections span more than one page, so I wrapped the head and body sections in a table, with the heading part in the thead and the content in the tbody.

The problem I am having is that when a section spans more than one page, it will start on a new page. The headings are correctly repeated for each page, but I need the section to start right after the previous one (which is what happens if the following section doesn't span more than a page).

I tried using some of the page-break- options but didn't have any luck.

I've attached some sample code below, if you print this, section 2 will start on a new page because its content spans more than a page. I need it to start right after section 1.

The aspx file:
Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="HtmlToPdf_Paging.TestPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <input type="submit" value="Print" />
    <div class="Section">
        <table>
            <thead>
                <tr>
                    <td>
                        <div style="background-color: Black; color: White; font-weight: bold; font-size: 14px;">
                            Section 1
                        </div>
                    </td>
                </tr>
            </thead>        
            <tbody>
                <tr>
                    <td>
                        <div>
                            A small section. The next section should start on the same page
                        </div>
                    </td>
                </tr>
            </tbody>   
        </table>
    </div>
    <div class="Section">
        <table>
            <thead>
                <tr>
                    <td>
                        <div style="background-color: Black; color: White; font-weight: bold; font-size: 14px;">
                            Section 2
                        </div>
                    </td>
                </tr>
            </thead>        
            <tbody>
                <tr>
                    <td>
                        <div>
                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean varius nibh et leo iaculis convallis. Ut hendrerit justo lorem. Mauris eros justo, facilisis at pharetra sed, adipiscing non tellus. Phasellus ullamcorper, augue lacinia sodales interdum, dolor neque tincidunt arcu, ut pharetra mauris erat et justo. In sollicitudin, tellus in posuere porttitor, lacus massa luctus justo, vel pulvinar odio lectus eu velit. Nunc suscipit, arcu sit amet sodales interdum, urna nibh rutrum dolor, sed fringilla nunc libero a orci. Integer molestie, augue et dictum eleifend, est augue lobortis metus, et rutrum tortor orci ut nunc.

Sed massa metus, ultrices id adipiscing eu, rhoncus eget mi. Suspendisse nec dui lacus. Vivamus eros erat, mattis et pellentesque sit amet, egestas eget neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam vitae ligula in odio tempus congue et at elit. Ut dictum accumsan lorem eu venenatis. Etiam bibendum rhoncus lacus ut auctor. Morbi risus sem, scelerisque at dictum ac, placerat sed velit. Phasellus dictum, diam a tristique adipiscing, sem nisl lacinia urna, sed ullamcorper neque nibh a est. Duis in nunc erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce leo ipsum, feugiat quis tristique vel, luctus a augue. Fusce lobortis accumsan neque non venenatis. Aenean tristique lobortis dapibus. In aliquet tortor quis quam tincidunt fringilla. Etiam auctor condimentum risus ut pellentesque.

Nullam at tempor risus. Morbi sollicitudin euismod lectus, vel ultrices tortor auctor quis. Sed quis velit non sem viverra faucibus vitae blandit risus. Praesent vel pretium nisl. Morbi in massa in nisi ullamcorper eleifend. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque elementum, metus ut ornare consectetur, velit mauris feugiat leo, ut consequat tortor leo in purus. Suspendisse molestie posuere sodales. Nam adipiscing odio et augue consectetur a ullamcorper neque rutrum. Nam in augue ante, ut interdum nunc. Pellentesque imperdiet lectus hendrerit tellus vehicula quis gravida dui interdum. Nulla eget ligula augue.

Duis erat enim, convallis sit amet elementum in, adipiscing eget diam. Nam sit amet cursus nisi. Donec vitae risus magna. Suspendisse ut dolor sapien, non ornare purus. Ut nec erat a tellus volutpat iaculis nec accumsan magna. Aliquam sem tellus, accumsan eu commodo eget, ultricies et nunc. Morbi purus nulla, lacinia vestibulum dapibus id, euismod non augue. Sed malesuada elementum ante, vel vehicula risus vehicula vel. Vestibulum eu euismod lectus. Suspendisse potenti. Donec eget felis lectus, sit amet scelerisque nulla. Duis facilisis euismod dignissim. Sed tincidunt, augue sed blandit consequat, ipsum enim convallis nibh, vitae dictum erat nibh sit amet sem. Curabitur turpis magna, consectetur eget eleifend nec, blandit sit amet purus.

Vestibulum fringilla ipsum ut sapien vestibulum dignissim dapibus est adipiscing. Sed id tortor est, pretium condimentum ipsum. Suspendisse convallis odio non dolor viverra viverra. Aenean pharetra sodales elit, quis mollis lorem sagittis eu. Suspendisse potenti. Maecenas velit lorem, convallis eget dictum vel, luctus eget felis. Praesent dignissim feugiat velit eu ultrices.

Donec sit amet eros purus. Vivamus porta elit a tortor posuere eget vestibulum nulla mollis. Ut varius auctor leo, vel aliquet nisi laoreet et. Suspendisse eget diam mauris. Nunc at mauris ac mi tristique elementum quis eget neque. Donec nec nulla magna, in eleifend lorem. Pellentesque auctor risus quis lacus dignissim dapibus. Pellentesque elementum lacinia faucibus. Nunc laoreet velit vitae magna dictum posuere. Vivamus metus felis, euismod vel ullamcorper vitae, volutpat et arcu. Integer vitae imperdiet tortor. Quisque dictum sem non ipsum accumsan consequat. Phasellus ullamcorper urna eget ligula tincidunt tincidunt.

Nulla feugiat posuere quam quis dictum. Vivamus mi leo, adipiscing vel malesuada et, ullamcorper eget mi. Praesent suscipit ipsum vitae metus ultrices at varius felis volutpat. Proin suscipit ante facilisis enim posuere porta. In id erat tristique ante fringilla sodales a nec justo. Phasellus elit dolor, porttitor non consequat quis, faucibus et erat. Fusce sit amet augue leo, nec feugiat tellus. Cras vel dui est. Maecenas semper aliquam velit, aliquet dapibus magna semper vitae. Sed eu nunc tellus, id fringilla libero. Phasellus dapibus urna a risus consequat tristique. Praesent nisl magna, auctor quis aliquet nec, molestie id dolor. Nulla molestie lacus vel sapien vulputate nec placerat purus auctor. Maecenas vitae nulla mi, eu pellentesque mauris.

Pellentesque quam erat, rhoncus ac commodo vitae, commodo et felis. In tempus justo eu nunc adipiscing vitae suscipit nulla rhoncus. Cras vitae nunc turpis, sit amet eleifend est. Vivamus massa mi, aliquet eget imperdiet non, suscipit id augue. Aliquam sed est ut metus suscipit commodo. Nunc et eros augue, nec blandit sapien. Vestibulum pretium tincidunt lacus id mollis. Mauris tristique molestie purus id porta. Fusce bibendum laoreet dolor quis accumsan. Suspendisse lobortis, nisl eget consectetur hendrerit, enim lectus faucibus mauris, in scelerisque lectus nisi in turpis. Nulla accumsan euismod dictum. Vivamus at ligula lobortis nisi vulputate auctor. Quisque bibendum blandit magna eu tempor. Integer quis mauris sapien.
Pellentesque quam erat, rhoncus ac commodo vitae, commodo et felis. In tempus justo eu nunc adipiscing vitae suscipit nulla rhoncus. Cras vitae nunc turpis, sit amet eleifend est. Vivamus massa mi, aliquet eget imperdiet non, suscipit id augue. Aliquam sed est ut metus suscipit commodo. Nunc et eros augue, nec blandit sapien. Vestibulum pretium tincidunt lacus id mollis. Mauris tristique molestie purus id porta. Fusce bibendum laoreet dolor quis accumsan. Suspendisse lobortis, nisl eget consectetur hendrerit, enim lectus faucibus mauris, in scelerisque lectus nisi in turpis. Nulla accumsan euismod dictum. Vivamus at ligula lobortis nisi vulputate auctor. Quisque bibendum blandit magna eu tempor. Integer quis mauris sapien.
Pellentesque quam erat, rhoncus ac commodo vitae, commodo et felis. In tempus justo eu nunc adipiscing vitae suscipit nulla rhoncus. Cras vitae nunc turpis, sit amet eleifend est. Vivamus massa mi, aliquet eget imperdiet non, suscipit id augue. Aliquam sed est ut metus suscipit commodo. Nunc et eros augue, nec blandit sapien. Vestibulum pretium tincidunt lacus id mollis. Mauris tristique molestie purus id porta. Fusce bibendum laoreet dolor quis accumsan. Suspendisse lobortis, nisl eget consectetur hendrerit, enim lectus faucibus mauris, in scelerisque lectus nisi in turpis. Nulla accumsan euismod dictum. Vivamus at ligula lobortis nisi vulputate auctor. Quisque bibendum blandit magna eu tempor. Integer quis mauris sapien.
                        </div>
                    </td>
                </tr>
            </tbody>   
        </table>
    </div>
    </form>
</body>
</html>


The cs code behind file:
Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EO.Pdf;
using System.Collections.Specialized;
using System.IO;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Drawing;

namespace HtmlToPdf_Paging
{
    public partial class TestPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.ContentType = "application/pdf";
                Response.AppendHeader("Content-Disposition", "attachment; filename=\"TestPrint.pdf\"");

               

                EO.Pdf.HtmlToPdf.Options.PreserveHighResImages = true;
                EO.Pdf.HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.A4;
                EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0.1f, 1.1f, 7.9f, 10.0f);                

                using (MemoryStream memory = new MemoryStream())
                {
                    EO.Pdf.HtmlToPdf.ConvertHtml(form1.InnerHtml, memory);

                    Response.BinaryWrite(memory.ToArray());
                }
                Response.End();
            }
        }
    }
}


Thanks in advance for your assistance :)
eo_support
Posted: Tuesday, June 19, 2012 9:13:27 AM
Rank: Administration
Groups: Administration

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

You must already have some "page-break-inside:avoid" somewhere in your code. When you have "page-break-inside:avoid" on an element and that element is too long to fit in the current page, it will start a new page.

Thanks!
NeilJM
Posted: Tuesday, June 19, 2012 9:36:24 AM
Rank: Newbie
Groups: Member

Joined: 9/1/2011
Posts: 4
Hi,

I don't have any "page-break-inside:avoid" in the code above, but section 2 always starts on a new page if it spans more than a page. I need it to start underneath section 1 on the first page.

Thanks
eo_support
Posted: Tuesday, June 19, 2012 9:46:08 AM
Rank: Administration
Groups: Administration

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

Try to add a dummy row before your big row (thus between the header row and the big row). Our converter will automatically try to avoid an empty header row (an empty header row at the bottom of the first page, then a repeated header row on the next page) so that the header row is always followed by at least one content row. It does this by locking the header row and the first content row. When the first content row is too big, it would shift the whole block to the next page. Adding a dummy row before your first real content row should avoid this problem.

Thanks!
NeilJM
Posted: Tuesday, June 19, 2012 9:48:44 AM
Rank: Newbie
Groups: Member

Joined: 9/1/2011
Posts: 4
Hi,

That worked perfectly!

Thanks very much :)
eo_support
Posted: Tuesday, June 19, 2012 10:06:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
You are very welcome. Please feel free to let us know if there is anything else.

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.