小编Vic*_*idt的帖子

Qt:无法在C#上初始化OLE(错误80010106)-(libwkhtmltox.dll)

即时通讯使用此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)

关于上面的代码:

  • content =我要转换为pdf的html内容。
  • fullPath =将在其中存储html内容。
  • _projectSettingsOptions =项目的路径,例如图像路径,pdf路径等...

然后,我调用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)

c# wkhtmltopdf asp.net-core-mvc

7
推荐指数
1
解决办法
2495
查看次数

标签 统计

asp.net-core-mvc ×1

c# ×1

wkhtmltopdf ×1