Rog*_*ina 7 pdf-generation pdfsharp .net-core
这可能听起来“容易”,但我还没有找到真正的解决方案。我需要从 .Net Core 上的 API 的 Html 字符串创建 Pdf 文件。图书馆必须是免费的(不是付款或任何相关的东西)。我发现 PDFSharp 是一个不错的选择,但现在我发现 PDFSharp 不适用于 .Net Core 并且它不允许注入 Html 字符串。
那么,对于这种情况,PDFSharp 是一个不错的选择吗?或者你会推荐我什么其他图书馆?
非常感谢。
Rog*_*ina 15
如果有人需要这个选项,这是我决定使用的最终解决方案。
var url = "/sf/ask/39525531/";
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();
}
Run Code Online (Sandbox Code Playgroud)
谢谢@leonard-AB
Min*_*ata 13
我最近自己也遇到了完全相同的问题。目前在 .NET Core 中处理 PDF 的方法非常有限。要通过他们...
IMO 唯一可以满足您需求的免费软件是 SelectPDF。这是因为我不评价库或 API。但它是免费的,而且有效。
更多信息:https : //dotnetcoretutorials.com/2019/07/02/creating-a-pdf-in-net-core/
小智 8
安装 NuGet 包 - Polybioz.HtmlRenderer.PdfSharp.Core https://www.nuget.org/packages/Polybioz.HtmlRenderer.PdfSharp.Core/1.0.0?_src=template
using PdfSharpCore;
using PdfSharpCore.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
var document = new PdfDocument();
var html = "<html><body style='color:black'>PMKJ</body></html>";
PdfGenerator.AddPdfPages(document, html , PageSize.A4);
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
document.Save(ms);
res = ms.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7608 次 |
| 最近记录: |