|
Rank: Member Groups: Member
Joined: 1/2/2012 Posts: 10
|
I am using the HtmlToPdf component, and find it equivalent for most of my needs. One thing that makes me frustrated, though, is that tables are not moved to the next page in cases where they will not fit on the current page. Is there a way to force this behaviour?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Yes. What you need to do is to apply "page-break-inside:avoid" on the table, or put the table in a DIV and apply the same style on that DIV. That way it will try to keep the whole table together and if it can not fit in the current page, it will move it to the next page. Without "page-break-inside:avoid", it will automatically split the table in the middle of the table if the table spans multiple pages.
Hope this helps. Please feel free to let us know if you still have problems.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/2/2012 Posts: 10
|
Thank you for your reply. I have implemented the code you suggested, and it works to some extent. Here is my code for generating the PDF:
Code: Visual Basic.NET
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.ClearHeaders()
response.ContentType = "application/pdf"
response.AddHeader("Content-Disposition", "attachment; filename=test.pdf")
If (String.Equals(orientation, "verticalOrientation") = True) Then
HtmlToPdf.Options.PageSize = New SizeF(PdfPageSizes.A4.Width, PdfPageSizes.A4.Height)
HtmlToPdf.Options.OutputArea = New RectangleF(0.3F, 0.3F, 7.8F, 11.0F)
Else
HtmlToPdf.Options.PageSize = New SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width)
HtmlToPdf.Options.OutputArea = New RectangleF(0.3F, 0.3F, 11.0F, 7.8F)
End If
HttpContext.Current.Session("reportName") = fileName
HtmlToPdf.Options.AfterRenderPage = New PdfPageEventHandler(AddressOf GenerateHeadersAndFooters)
HtmlToPdf.ConvertHtml(htmlString.ToString(), response.OutputStream)
response.End()
And here is an excerpt from the HTML string:
Code: HTML/ASPX
<div
class="componentContainer" style="page-break-inside: avoid"><span
class="componentName">Utdanning</span><table
class="horizontalTable" style="page-break-inside: avoid"><thead><tr style="page-break-inside: avoid"> </tr><tr style="page-break-inside: avoid"><th
class="headerCell level0">Skole og utdanning</th><th
class="headerCell level0">Periode</th><th
class="headerCell level0">VT / Studiepoeng</th><th
class="headerCell level0">Karakter</th><th
class="headerCell level0">Autorisasjon</th><th
class="headerCell level0">Fagbrev</th><th
class="headerCell level0">Under utdanning</th><th
class="headerCell level0">Beskrivelse</th></tr></thead><tbody><tr style="page-break-inside: avoid"><td
class="contentCell">Some secret value</td><td
class="contentCell">20.08.2001 - 15.07.2003</td><td
class="contentCell">Some secret value</td><td
class="contentCell">Some secret value</td><td
class="contentCell">Ja</td><td
class="contentCell">Nei</td><td
class="contentCell">Nei</td>
The first page break in my document looks fine, but this is a screenshot of the second page break. As you can see from the screenshot, a table is split between two pages, despite using page-break-inside: avoid in the div, table and table rows.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Your code looks fine. Please try to isolate the problem into either a test HTML file or a test ASP.NET project and send it to us. We will PM you as to where to send the test project.
If your page is online, you can also give us the page Url and we should be able to find out why its breaking the page for you.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/2/2012 Posts: 10
|
I have isolated the problem in a test project and sent it your way, thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Thank you very much for test file. We have received it and will rely again as soon as we find anything or if we need anything else from you.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, We have received and looked into your test file. The reason that page break did not occur before a table is because you have nesting "page-break-inside:avoid". For example, if you have the following HTML:
Code: HTML/ASPX
<div style="page-break-inside:avoid">
table 1....
<div style="page-break-inside:avoid">
table 2.....
</div>
table 3....
</div>
Then the page-break-inside on the inner DIV will be ignored because the whole outer DIV block are now considered the be a single "unbreakable" page. However when in fact the contents inside that block is still over one page, the contents are still "spilled over" to the next page. The key at here is once you have an outer "page-break-inside:avoid", all inner "page-break-inside:avoid" will be ingored. Once you fix that problem, all the tables should page correctly. Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/2/2012 Posts: 10
|
You are absolutely right! I had set "page-break-inside:avoid" on the div that contained all the tables on candidate 2...n, but not on the div that contained the first candidate. That's the reason it worked so well for the first, but did not work for the rest!8-)
Thank you very much for your help, you have a great customer service!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Glad to hear that it works for you! Please feel free to let us know if you run into any other problems.
Thanks!
|
|