Welcome Guest Search | Active Topics | Sign In | Register

Removing a blank page Options
jgrubb
Posted: Wednesday, January 14, 2015 11:39:22 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2015
Posts: 2
I'm converting a report from HTML to PDF that has sections that I want to appear entirely on the same page, if possible. Typically, I' m satisfied with this style:

Code: HTML/ASPX
<div style="page-break-inside: avoid">



but I have a scenario where a section ends at a page boundary and the next section is larger than a page. This new section then skips a page and ends up starting on the page after that. I have a temporary solution that breaks these larger sections into smaller "page-break-inside: avoid" sections, but ultimately I would just like to search for and delete the blank pages once the PDF has rendered. Is there any way to remove blank pages once the ConvertHtml() has been run? Something like this?

Code: C#
...
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertHtml(htmlString, doc); // 1st time (produces a PDF containing a blank page)
for (var i = doc.Pages.Count-1; i >= 0; i--)
{
    if (doc.Pages[i].IsEmptyPage() == true)
        doc.Pages[i].RemovePage(); // remove the blank page
}
doc.Save(stream);


Thanks!
eo_support
Posted: Wednesday, January 14, 2015 12:35:29 PM
Rank: Administration
Groups: Administration

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

We do not have such a method on the Page object. However the HTML to PDF converter should automatically remove such blank page for you. So if you can isolate the problem into a small test HTML file, then we will be very happy to take a look.

Thanks!
jgrubb
Posted: Monday, January 19, 2015 12:29:32 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2015
Posts: 2
I have a smaller example than my original, but since the issue involves page breaks of large sections it is not a small HTML file. Can I email it to you?
eo_support
Posted: Monday, January 19, 2015 12:46:57 PM
Rank: Administration
Groups: Administration

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

You can email it to us as soon as we can use it to reproduce the problem. So if your HTML file depends on other resources (JavaScript files, CSS, etc), then you will need to include those as well. What we do here is we try to run the conversion in a debugger, then see what we can find. So if certain files are missing and we can't see the problem here, then it would not help.

You can find more instructions on how to send us test files/project here:

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

Thanks!
eo_support
Posted: Monday, January 19, 2015 8:41:15 PM
Rank: Administration
Groups: Administration

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

We have received your test file and looked into the test file. Please try to change the root DIV for each section from:

Code: HTML/ASPX
<div style="page-break-inside: avoid;">
 .....section content
</div>


Code: HTML/ASPX
<div style="page-break-inside: avoid;display:inline-block;">
 .....section content
</div>


Note the additional "display:inline-block" added. The reason is inside this DIV immediately you have another DIV with margin-top:30px. This causes the outer DIV to take the margin value thus making this margin NOT to be included in the "page-break-inside:avoid" area. This 30px caused the extra blank page. We automatically deletes small blank page, but not "big" blank pages because some times user intentionally inserts blank pages.

The reason that the blank page does not occur between section 3 and section 4 is because the margin before section 3 and section 4 both got pushed to the previous page. However the margin before section 1 can not be pushed to anywhere since it is the first page.

Once you add "display:inline-block", it will include the 30px margin inside the "page-break-inside:avoid" range thus not having this blank space to occupy a separate page.

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.