C# 无法为.net core2.2 azure functionapp使用dinktopdf加载dll libwkhtmltox
我有一个使用.NETCore2.2的Azure functionapp,它是为将html文本转换为pdf而编写的。我用的是Dinktopf。当我运行函数时,我得到“无法加载libwkhtmltox.dll。我已经尝试了一些帖子中提到的替代解决方案,但它仍然抛出相同的错误 我尝试使用Directory.GetCurrentDirectory和path.combine 代码如下:C# 无法为.net core2.2 azure functionapp使用dinktopdf加载dll libwkhtmltox,c#,html,pdf,azure-functions,dinktopdf,C#,Html,Pdf,Azure Functions,Dinktopdf,我有一个使用.NETCore2.2的Azure functionapp,它是为将html文本转换为pdf而编写的。我用的是Dinktopf。当我运行函数时,我得到“无法加载libwkhtmltox.dll。我已经尝试了一些帖子中提到的替代解决方案,但它仍然抛出相同的错误 我尝试使用Directory.GetCurrentDirectory和path.combine 代码如下: [FunctionName("Function1")] public static as
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit";
context.LoadUnmanagedLibrary($@"{Directory.GetCurrentDirectory()}\Dependencies\libwkhtmltox.dll");
var IocContainer = new SynchronizedConverter(new PdfTools());
string html = await new StreamReader(req.Body).ReadToEndAsync();
var globalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 10 },
};
var objectSettings = new ObjectSettings
{
PagesCount = true,
WebSettings = { DefaultEncoding = "utf-8" },
HtmlContent = html
};
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = globalSettings,
Objects = { objectSettings }
};
byte[] pdfBytes = null;// IocContainer.Convert(pdf);
return new FileContentResult(pdfBytes, "application/pdf");
}
}
[FunctionName(“Function1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
LogInformation(“C#HTTP触发器函数处理了一个请求。”);
CustomAssemblyLoadContext=新建CustomAssemblyLoadContext();
var architectureFolder=(IntPtr.Size==8)?“64位”:“32位”;
LoadUnmanagedLibrary($@“{Directory.GetCurrentDirectory()}\Dependencies\libwkhtmltox.dll”);
var IocContainer=新的SynchronizedConverter(新的PdfTools());
字符串html=wait new StreamReader(req.Body).ReadToEndAsync();
var globalSettings=新的globalSettings
{
ColorMode=ColorMode.Color,
方向=方向。纵向,
PaperSize=PaperKind.A4,
边距=新边距设置{Top=10},
};
var objectSettings=新的objectSettings
{
PageScont=true,
WebSettings={DefaultEncoding=“utf-8”},
HtmlContent=html
};
var pdf=新的HtmlToPdfDocument()
{
全局设置=全局设置,
对象={objectSettings}
};
字节[]pdfBytes=null;//IocContainer.Convert(pdf);
返回新的FileContentResult(pdfBytes,“application/pdf”);
}
}
使用此解决方案时,我也遇到了很多问题,但我认为一个问题可能是您的目录。请尝试使用
$@"{context.FunctionDirectory}\Dependencies\libwkhtmltox.dll");
相反。
您可以通过重载函数来访问执行上下文
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "iamgroot")] HttpRequest req, ExecutionContext context)
对于访问函数主机的目录这个解决方案我也遇到了很多问题,但我认为一个问题可能是您的目录。请尝试使用
$@"{context.FunctionDirectory}\Dependencies\libwkhtmltox.dll");
相反。
您可以通过重载函数来访问执行上下文
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "iamgroot")] HttpRequest req, ExecutionContext context)
要访问函数主机的目录您可以在azure portal->azure function kudu站点中看到libwkhtmltox.dll吗?我仍在本地尝试。它仍没有部署到azure portal。我还尝试手动将库添加到函数中,并将属性设置为始终复制。仍不起作用。是否有此问题的更新?是否可以你在azure portal->azure function kudu站点中看到libwkhtmltox.dll了吗?我仍然在本地尝试。它仍然没有部署到azure portal。我还尝试手动将库添加到函数中,并将属性设置为始终复制。仍然不起作用。对此问题有任何更新吗?