Extra blank page when converting HTML to PDF using abcPDF

前端 未结 8 1155
花落未央
花落未央 2020-12-30 08:40

I have an HTML report, with each print page contained by a

. The page class is defined as

width: 180mm;
height: 250mm         


        
相关标签:
8条回答
  • 2020-12-30 09:37
    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-30 09:38

    To avoid page breaking in the last page, I did something like this and it worked.

    I made sure that the last page didn't have the page-break-after: always, this can be done with any templating or front-end framework like angularJS, but for this example I use blade templating (but any php will do...)

    @if ($last_page)
       <div class='footer last-page'>
    @else
       <div class='footer'>
    

    and then I have this in my style sheet

    .footer {
        page-break-after:always;
    }
    
    .last-page {
        page-break-after:avoid;
    }
    
    0 讨论(0)
提交回复
热议问题