• C# Pechkin初始化一次后被锁住的问题


    Pechkin.dll可用于pdf的生成,常规用法网上都有介绍:https://www.cnblogs.com/felixnet/p/5143934.html

    但是当在一个页面上执行过一次之后,再次就无法运行,结束调试重新调试时会报错,显示相关的dll被锁定。

    解决方案:

    在web.config中的system.webServer界面中增加如下配置:

    <handlers>
    <add name="html_x64*" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:WindowsMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    <add name="html_x64" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:WindowsMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    </handlers>

     此方法不稳定,晚点研究下Tuespechkin

    Tuespechkin还是有同样的问题,需要把converter作为全局静态变量处理

    后来尝试用了Pechkin.Synchronized,效果不错,只是每次网站内容更新后需重启一下iis(开始-运行-iisreset)

    示例代码:

    var htmlStrForPdf="";//此处是要转换为pdf的html内容
    #region 将html生成pdf保存在服务器
    SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig()
        .SetMargins(new Margins() { Left = 0, Right = 0, Top = 0, Bottom = 0 }) //设置边距
        .SetPaperOrientation(false) //设置纸张方向为横向
    ); //设置纸张大小(使用者可以根据自己的需求设置。这里的50代表长,100代表宽)
    ObjectConfig oc = new ObjectConfig();
                                oc.SetPrintBackground(true).SetRunJavascript(true).SetScreenMediaType(true)
        .SetLoadImages(true);
    //以上设置十分重要:
    //SetPrintBackground(true)是显示样式所必须的(例如令设置有颜色的<div>能在PDF中显示出来)。
    //SetLoadImages(true)令PDF可以加载图片。由于Pechkin是封装wkhtmltopdf。wkhtmltopdf是不能识别相对路径的图片文件的。所以HTML内的所有图片路径都不能使用相对路径!必须使用绝对路径!
    //.Header.SetHtmlContent(WebPageUri)是使用一个网页内容来设置PDF的页眉。
    byte[] bytePDF = sc.Convert(oc, htmlStrForPdf);
    File.WriteAllBytes(fullFileName, bytePDF);
    #endregion
    

      

  • 相关阅读:
    7、注解@Mapper、@MapperScan
    SpringBoot
    正则表达式"(^|&)" ,什么意思?
    JSON.NET的Self referencing loop detected with type的原因以及解决办法
    jquery ajax 中各个事件执行顺序
    Lucene BooleanQuery中的Occur.MUST与Occur.Should
    lucene中Field简析
    IDENTITY、SCOPE_IDENTITY、IDENT_CURRENT的分析
    HTML5学习(1)简介
    HTML学习(17)URL
  • 原文地址:https://www.cnblogs.com/q251458060/p/12148252.html
Copyright © 2020-2023  润新知