Welcome Guest Search | Active Topics | Sign In | Register

page-break-after:always not working as expected Options
Ashwanth
Posted: Thursday, June 22, 2017 5:32:50 PM
Rank: Newbie
Groups: Member

Joined: 6/22/2017
Posts: 4
Hello There,
I have two divs on my page. When I set the "page-break-after: always" style on the first div or "set page-break-before: always" style on the second div, part of the second div still shows in the first page when generating a PDF file.

I am using EO.PDF (v17.1.76) and EO.PDF.MVC(v 17.1.76). I am using the trial license as I am evaluating the pdf generating before we decide to buy it.

I am converting my divs sitting in a .cshtml file into a pdf file.

My cshtml code is as follows:
<div style="page-break-after:always">
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>
</div>
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and gives you full control over markup
for enjoyable, agile development.
</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
</div>
</div>

Do you have sample code for MVC that shows how manual paging works ?

Please let me know.

Best Regards,
Ashwanth

eo_support
Posted: Thursday, June 22, 2017 6:02:13 PM
Rank: Administration
Groups: Administration

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

This can be normal. The key is the paging is based on the Y position. It has nothing to do with the sequence of the elements appearing in the HTML. Consider the following code:

Code: HTML/ASPX
<div style="position:absolute;left:0px;top:0px;width:100px;height:100px;page-break-after:always;">DIV1</div>
<div style="position:absolute;left:0px;top:0px;width:100px;height:50px;">DIV2</div>


In this case DIV2 will appear on page 1 even if it appears after DIV1 in HTML, despite that DIV1 has page-break-after:always set. The reason is the precise meaning of "page-break-after:always" means everything whose Y position is after the bottom of this element should be on the next page. It does not mean every element after this element in the HTML should be on the next page.

In the previous example, even though DIV2 appears after DIV1 in the HTML, but its Y range is 0 to 50, where as the page break point is 100 (the bottom Y position of DIV1), since 50 < 100, DIV1 will stay on page 1.

Another way to understand this is, the paging process will NEVER change relative layout of elements. In the previous example, the top edge of DIV1 and DIV2 are always aligned (because they both have a top value of 0). So they will always be aligned when they are rendered as PDF, this means they will never be split into two different pages.

Hope this makes sense to you. Please feel free to let us know if you still have any questions.

Thanks!
Ashwanth
Posted: Friday, June 23, 2017 5:38:34 PM
Rank: Newbie
Groups: Member

Joined: 6/22/2017
Posts: 4
Thank you for emphasizing/clarifying this. When I try your simple example it works.

The default behavior of Divs is to stack up vertically. In my case, the Divs get stacked vertically when seen on the browser. Div2 is below Div1. The simplified code is as follows:
<div style="page-break-after:always;">
<button class="btn btn-default">First Button</button>
</div>
<div>
<button class="btn btn-default">Second Button</button>
</div>
<div>
<a href="@(Url.Action("GeneratePDF", "Home"))">Generate PDF</a>
<button class="btn btn-primary .GenPDF" id="GenPDF">Generate PDF</button>
</div>

My Div1 has a height of 34 and my Div2 starts from the bottom edge of Div1. When I generate the PDF, part of my Div2 shows in the first page. Can you execute the above code in a simple asp.net mvc project and check ? Or give me a example where the height of the Divs are not specified explicitly like you did in your example.

Best Regards,
Ashwanth


eo_support
Posted: Friday, June 23, 2017 6:11:33 PM
Rank: Administration
Groups: Administration

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

Please check your CSS styles (your btn btn-default classes). If any of your class has a negative margin, it can cause the DIVs to shift up from their boundary and cause overlap. The easiest way for you to test it is to remove all classes and then see if it works. If that works, then it definitely has to do with your CSS rules. In that case you can check each CSS attribute to see if you can find the offending CSS attribute. Usually as soon as you find out which attribute causes the problem for you, it will make sense to you. We won't be able to reproduce the problem here without your CSS files.

Thanks!
Ashwanth
Posted: Monday, June 26, 2017 8:57:19 AM
Rank: Newbie
Groups: Member

Joined: 6/22/2017
Posts: 4
Hi,
Thank you for your inputs.
The issue happens even without the CSS styles and with the code below in a cshtml file.
<div style="page-break-after:always;">
<button>First Button</button>
</div>
<div>
<button>Second Button</button>
</div>
<div>
<a href="@(Url.Action("GeneratePDF", "Home"))">Generate PDF</a>
</div>

Part of the second button appears in the first page.

Best Regards,
Ashwanth
eo_support
Posted: Tuesday, June 27, 2017 2:35:06 PM
Rank: Administration
Groups: Administration

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

Even if your button does not have any style attribute, you may still have style applied to it through your CSS files. If you do not have any CSS files either, then please try to isolate the problem into a test project and send the test project to us. Once we have that we will be happy to investigate further. See here for more information on how to send test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Ashwanth
Posted: Tuesday, June 27, 2017 4:44:06 PM
Rank: Newbie
Groups: Member

Joined: 6/22/2017
Posts: 4
Hi,
I sent you the test project.

Best Regards,
Ashwanth
eo_support
Posted: Tuesday, June 27, 2017 5:22:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
We ran the test project here and the result seems to be correct. I will email you the test result shortly.


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.