Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net内核中使用DinkToPdf将Html转换为Pdf在Ubuntu中不起作用_C#_Html_Pdf_Asp.net Core Webapi_Dinktopdf - Fatal编程技术网

C# 在asp.net内核中使用DinkToPdf将Html转换为Pdf在Ubuntu中不起作用

C# 在asp.net内核中使用DinkToPdf将Html转换为Pdf在Ubuntu中不起作用,c#,html,pdf,asp.net-core-webapi,dinktopdf,C#,Html,Pdf,Asp.net Core Webapi,Dinktopdf,我正在尝试使用asp.net Core webapi 2.1版中的DinkToPdf将Html文档转换为pdf: 这是我的方法: public async Task<ActionResult> ToPdf() { var loader = new CustomAssemblyLoader(); var assemblyPath = Directory.GetCurrentDirectory(); loader.LoadU

我正在尝试使用asp.net Core webapi 2.1版中的DinkToPdf将Html文档转换为pdf:

这是我的方法:

 public async Task<ActionResult> ToPdf()
    {
         var loader = new CustomAssemblyLoader();
         var assemblyPath = Directory.GetCurrentDirectory();
         loader.LoadUnmanagedLibrary($@"{assemblyPath}/libwkhtmltox");

            var doc = new HtmlToPdfDocument()
            {
                GlobalSettings = {
                    Orientation = Orientation.Landscape,
                    PaperSize = PaperKind.A4,
                    Out = "wwwroot/test.pdf"
                },
                Objects = {
                    new ObjectSettings() {
                        PagesCount = true,
                        HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices  iaculis. Ut                               odio viverra, molestie lectus nec, venenatis turpis.",
                        WebSettings = { DefaultEncoding = "utf-8" },
                        HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
                    }
                }
            };

            _pdfConverter.Convert(doc);

    }
公共异步任务ToPdf()
{
var loader=新的CustomAssemblyLoader();
var assemblyPath=Directory.GetCurrentDirectory();
LoadUnmanagedLibrary($@“{assemblyPath}/libwkhtmltox”);
var doc=新的HtmlToPdfDocument()
{
全局设置={
方向=方向。横向,
PaperSize=PaperKind.A4,
Out=“wwwroot/test.pdf”
},
对象={
新的ObjectSettings(){
PageScont=true,
HtmlContent=@“Lorem ipsum door sit amet,Concertetur adipiscing elite.In Concertetur mauris eget ultrices iaculis.Ut odio viverra,molestie lectus nec,Venetis turpis.”,
WebSettings={DefaultEncoding=“utf-8”},
HeaderSettings={FontSize=9,Right=“第[Page]页,共[toPage]”,Line=true,间距=2.812}
}
}
};
_pdfConverter.Convert(文档);
}
我将libwkhtmltox.so和libwkhtmltox.dll复制到我的项目的根目录下,每个.dll都位于该目录下。 已安装sudo apt get安装libgdiplus

始终获取此错误 DllNotFoundException:无法加载共享库“/var/www/webapi/webapi/libwkhtmltox”或其依赖项之一。为了帮助诊断加载问题,请考虑设置LD.Debug环境变量:/VAR/WWW/WebAPI/WebAPI/LBWKHTMLTOX:不能打开共享对象文件:没有这样的文件或目录< /P> 顺便说一下,如果我在windows works上运行该项目,它将非常完美


提前谢谢你

尝试运行此命令
apt get install-y--没有安装建议zlib1g fontconfig libfreetype6 libx11-6 libxext6 libxrender1
。这对我有用

您是否检查了
assemblyPath
的值?Mb它指向错误的目录是的,选中了,它是我项目的根目录,顺便问一下,我也尝试了不带“/”的方法,您是否安装了
libgdiplus
<代码>sudo apt安装libgdiplus是,已安装。sudo apt get install libgdiplusI面临同样的问题。请编辑您的答案,以便更详细地解释。例如,该命令在何处运行?需要采取哪些必要步骤,这些步骤将有助于希望利用您的答案的任何人。非常感谢。