Tell abcPdf to scale the html to fit on a single pdf page

前端 未结 3 1550
孤街浪徒
孤街浪徒 2021-01-03 01:27

I am using abcPdf to convert an HTML report into a pdf file. The pdf has to be a single landscape A4 page.

Do you know if there is any way to tell abcPdf to scale th

3条回答
  •  时光说笑
    2021-01-03 02:21

    In case you are using 'Gecko' engine, this engine does not support 'GetInfoInt' so we need write some javascript to get the height. Do a dummy render first to determine height and then set this height to original AbcDoc.

    using (var tempDoc = new Doc())
                    {
                        tempDoc.HtmlOptions.Engine = EngineType.Gecko;
                        tempDoc.HtmlOptions.Media = MediaType.Print;
                        tempDoc.HtmlOptions.UseScript = true;
                        if (width.HasValue)
                            tempDoc.HtmlOptions.BrowserWidth = width.Value;
    
                        tempDoc.HtmlOptions.OnLoadScript = " window.onbeforeprint = function () { document.documentElement.abcpdf = Math.max( document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );}";
                        int theTempID = tempDoc.AddImageHtml(htmlData);
    
                        int height = Convert.ToInt32(tempDoc.HtmlOptions.GetScriptReturn(theTempID));
    
                        tempDoc.Clear();
                        tempDoc.Dispose();
    
                        theDoc.MediaBox.Height = height;
                        theDoc.Rect.String = theDoc.MediaBox.String;
                        theDoc.AddImageHtml(htmlData);
                    }
    

提交回复
热议问题