Extra blank page when converting HTML to PDF using abcPDF

前端 未结 8 1297
花落未央
花落未央 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:19

    The AddImageURL() method of ABCPDF is loosely bind method which doesn't render html tightly within required area which causes new blank page.

    try to use AddImageHTML() method to convert your desired HTML into PDF..

    Doc theDoc = new Doc();
    theDoc.Page = theDoc.AddPage();
    
    int theID = 0;
    theDoc.SetInfo(0, "CheckBgImages", "1");
    theDoc.SetInfo(0, "RenderDelay", "5000");
    theDoc.HtmlOptions.Engine = EngineType.MSHtml;
    theID = theDoc.AddImageHtml(HTML);
    
    while (true)
    {
     if (!theDoc.Chainable(theID))
                    break;
                theDoc.Page = theDoc.AddPage();
                theID = theDoc.AddImageToChain(theID);
            }
    
            for (int i = 0; i <= theDoc.PageCount; i++)
            {
                theDoc.PageNumber = i;
                theDoc.Flatten();
            }
    
            theDoc.Save(HttpContext.Current.Server.MapPath(Path));
            theDoc.Clear();
    

    It will always give accurate results.

提交回复
热议问题