这听起来很“简单”,但我还没有找到真正的解决方案。我需要从.Net Core上的API从HTML字符串创建Pdf文件。该库必须是免费的(不付款或任何相关内容)。我发现PDFSharp是一个不错的选择,但现在我检查出PDFSharp无法用于.Net Core,并且它不允许注入HTML字符串。
因此,对于这种情况,PDFSharp是一个不错的选择?或者您会推荐我什么其他图书馆?
非常感谢。
最近我本人也遇到了完全相同的问题。目前,.NET Core中处理PDF的方式极为有限。经历他们...
IMO唯一可以满足您需求的免费软件是SelectPDF。这是因为我不对库或API进行评分。但是它是免费的并且可以正常工作。
更多信息:https://dotnetcoretutorials.com/2019/07/02/creating-a-pdf-in-net-core/
如果有人需要此选项,这是我决定使用的最终解决方案。
var url = "https://stackoverflow.com/questions/564650/convert-html-to-pdf-in-net";
var chromePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
var output = Path.Combine(Environment.CurrentDirectory, "printout.pdf");
using (var p = new Process())
{
p.StartInfo.FileName = chromePath;
p.StartInfo.Arguments = $"--headless --disable-gpu --print-to-pdf={output} {url}";
p.Start();
p.WaitForExit();
}
https://stackoverflow.com/a/59943987/3877537
感谢@ leonard-AB