Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra blank page when converting HTML to PDF using abcPDF

Tags:

asp.net

abcpdf

I have an HTML report, with each print page contained by a <div class="page">. The page class is defined as

width: 180mm;
height: 250mm;
page-break-after: always;
background-position: centre top;
background-image: url(Images/MainBanner.png);
background-repeat: no-repeat;
padding-top: 30mm;

After making a few changes to my report content, when I call abcPDF to convert the report to PDF, suddenly I'm getting a blank page inserted after every real report page. I don't want to roll back the changes I've just made to remove this problem, so I'm hoping someone may know why the extra pages are being inserted.

like image 605
ProfK Avatar asked Mar 04 '10 13:03

ProfK


People also ask

Why does PDF add an extra page?

The problem can occur with the 'section break' setting set to 'Next Page' and the page before the blank page is full or has a forced page break inserted. If you change the 'section break' setting to 'continuous' then the problem goes away.


2 Answers

I have experienced the same exact problem. the empty page is due to the page-break-after: always; in the CSS. Not just ABCpdf but also the printed will spit out an extra page. So I used the following code to eliminate the last page: MyDoc.Delete(MyDoc.Page);

This however lead to a different kind of a problem. On development server, which has IE 8 I get an extra blank page and on production where I have IE6, I get no extra blank page. So I have emailed the support team at websupergoo to show me a way to look for a blank page. The idea is to iterate through a pdf and identify all blank pages and delete them using above logic.

And I second Jakkwylde's opinion. Websupergoo folks are extremely helpful and prompt in responding. I had another problem getting ABCpdf to work under 64 bit and had spent almost a day trying to figure it out. They provided me multiple scenarios which I could try out. Their support was right on the money and I got my app up and running in minutes.

like image 198
Kush Avatar answered Oct 26 '22 04:10

Kush


protected void RemoveBlankPages(Doc pdf)
{
    for (int i = pdf.PageCount; i > 0; i--)
    {
        pdf.PageNumber = i;

        //get the pdf content
        string textContent = pdf.GetText("Text");

        //delete the page if it is blank
        if (string.IsNullOrEmpty(textContent))
            pdf.Delete(pdf.Page);
    }
}
like image 27
Novice in.NET Avatar answered Oct 26 '22 03:10

Novice in.NET