zoukankan      html  css  js  c++  java
  • 使用Select.HtmlToPdf.NetCore 把html内容生成pdf文件

    引用类库

    通过nuget查找Select.HtmlToPdf.NetCore并引用

    控制器使用

    自己写一个页面,或者找个可用的网站都可以测试
    代码如下

            /// <summary>
            /// 导出pdf
            /// </summary>
            /// <returns></returns>
            [HttpGet]
            public async Task<IActionResult> Export(string url)
            {
                SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
                //converter.Options.PdfPageOrientation = SelectPdf.PdfPageOrientation.Landscape;
                SelectPdf.PdfDocument doc = converter.ConvertUrl(url);//"http://localhost:5020/PRINT/DyColdStoragePrint"
    
                var path = "wwwroot/pdf/" + DateTime.Now.ToString("yyyyMMdd") + "/test.pdf";
                doc.Save(path);
                doc.Close();
    
                return Content(path.Replace("wwwroot/", ""));
            }
    

    遇到问题

    只能在windows上使用,无法跨平台,会报错

    Conversion failure. Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory
    System.Exception: Conversion failure. Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory
    at SelectPdf.HtmlToImage.ᜀ(String A_0, ឭ[]& A_1, ជ& A_2, String& A_3)
    at SelectPdf.HtmlToPdf.ᜂ(String A_0, String A_1, String A_2, String A_3, Boolean A_4)
    at SelectPdf.HtmlToPdf.ConvertUrl(String url)

    官方表明只能支持windows,比较遗憾
    https://github.com/selectpdf/selectpdf-free-html-to-pdf-converter/issues/2

  • 相关阅读:
    UML_状态图
    UML_时序图
    UML_类图
    浅谈依赖注入
    MyEclipse_搭建SSH框架
    AOP:面向切面编程
    工厂模式
    (转)oracle使用expdp、impdp和exp、imp导入导出表及表结构
    oracle exp 和 imp 数据和表结构互相独立导出导入
    oracle 清空当前用户所有对象
  • 原文地址:https://www.cnblogs.com/xcsn/p/14825700.html
Copyright © 2011-2022 走看看