我在包装器中使用pechkin
库。它与 protocal 一起工作得很好,但是在使用时,脚本和样式没有加载到 pdf 中。提前致谢。C#
wkhtmltopdf
http:
https:
看法:
<html> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta charset="utf-8" /> <link rel="icon" type="image/png" href="@Url.AbsoluteUrl("Content/Favicon/favicon.ico")" /> @Styles.Render(Url.AbsoluteUrl("Content/themes/base/css")) @Styles.Render(Url.AbsoluteUrl("Content/themes/css")) @Scripts.Render(Url.AbsoluteUrl("Scripts/library")) @Scripts.Render(Url.AbsoluteUrl("Scripts/Common")) </head> <body> <div class="pad-none printBody size-100"> <div class="tabs-nav"> <div class="global-pad"> <div class="row"> <div id="divReportGrids" class="size-100"> @string.Concat(AppConstants.Delimiters.StartDelimiter, AppConstants.Common.PrintBodyPlaceholder, AppConstants.Delimiters.EndDelimiter) </div> </div> </div> </div> </div> </body> </html>
代码:
var documentConfig = new ObjectConfig().SetZoomFactor(1) .SetScreenMediaType(true) .SetCreateExternalLinks(true) .SetAllowLocalContent(true) .SetLoadImages(true) .SetRunJavascript(true) .SetPrintBackground(true) .SetRenderDelay(10000); documentConfig.Footer.SetFont(new Font("Arial,Helvetica,sans-serif", 4F, FontStyle.Regular)); documentConfig.Footer.SetRightText(@"[page] of [topage]"); documentConfig.Footer.SetContentSpacing(5.00); var globalConfig = new GlobalConfig() .SetDocumentTitle("POB Report") .SetPaperSize(PaperKind.A4) .SetOutputDpi(360); var pechkin = new SynchronizedPechkin(globalConfig); //Convert html to pdf byte[] htmlBytes = pechkin.Convert(documentConfig, completeHtml);