即时通讯使用此libwkhtmltox.dll将我的html转换为pdf。我正在使用c#.netCore。
用法:
private static string CreatePdf(string content, string fileName)
{
var fullPath = $"{_projectSettingsOptions.Pdf}/{fileName}";
using (var sw = new StreamWriter(new FileStream(fullPath, FileMode.Create), Encoding.UTF8))
{
sw.Write(content);
sw.Flush();
}
new Pdf(_projectSettingsOptions).Convert(fullPath, content);
return fullPath;
}
Run Code Online (Sandbox Code Playgroud)
关于上面的代码:
然后,我调用Pdf类,传递要转换的路径和内容。
new Pdf(_projectSettingsOptions).Convert(fullPath, content);
Run Code Online (Sandbox Code Playgroud)
这是我的Pdf课:
namespace SiteMFPManager.Library.Util
{
using Assembly;
using DinkToPdf;
using Settings;
using System.IO;
public class Pdf
{
public Pdf(ProjectSettingsOptions projectSettingsOptions) =>
new CustomAssemblyLoadContext().LoadUnmanagedLibrary(Path.Combine(projectSettingsOptions.References, "libwkhtmltox", "libwkhtmltox.dll"));
public void Convert(string fullPath, string content) =>
new SynchronizedConverter(new PdfTools()).Convert(new HtmlToPdfDocument
{ …Run Code Online (Sandbox Code Playgroud)