比較

為.NET 8選擇文件生成程式庫

.NET 8 引入的運行時變更使許多傳統的 PDF 程式庫不相容。 System.Drawing.Common 在非 Windows 平台上已被棄用,Native AOT 對於依賴反射的程式庫施加了新的限制,容器優先部署模型暴露了在 Windows 開發機上未出現的依賴問題。 在 .NET Framework 或甚至 .NET 6 中可用的程式庫可能會在 .NET 8 中出現 DllNotFoundExceptionPlatformNotSupportedException 錯誤。

本文檔案記錄了哪些 PDF 程式庫適用於 .NET 8,顯示了與不相容程式庫相關的具體錯誤,並提供了 Docker 和 Azure Functions 的部署配置。

快速入門:在 .NET 8 中從 HTML 生成 PDF

using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;

var pdf = renderer.RenderHtmlAsPdf(@"
    <html>
    <head><style>
        body { font-family: 'Segoe UI', sans-serif; padding: 40px; }
        h1 { color: #2563eb; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th { background: #2563eb; color: white; padding: 12px; text-align: left; }
        td { padding: 10px; border-bottom: 1px solid #e5e7eb; }
    </style></head>
    <body>
        <h1>Q4 Report</h1>
        <table>
            <tr><th>Metric</th><th>Value</th><th>Change</th></tr>
            <tr><td>Revenue</td><td>$1.2M</td><td>+12%</td></tr>
            <tr><td>Users</td><td>45,230</td><td>+23%</td></tr>
        </table>
    </body></html>");

pdf.SaveAs("report.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;

var pdf = renderer.RenderHtmlAsPdf(@"
    <html>
    <head><style>
        body { font-family: 'Segoe UI', sans-serif; padding: 40px; }
        h1 { color: #2563eb; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th { background: #2563eb; color: white; padding: 12px; text-align: left; }
        td { padding: 10px; border-bottom: 1px solid #e5e7eb; }
    </style></head>
    <body>
        <h1>Q4 Report</h1>
        <table>
            <tr><th>Metric</th><th>Value</th><th>Change</th></tr>
            <tr><td>Revenue</td><td>$1.2M</td><td>+12%</td></tr>
            <tr><td>Users</td><td>45,230</td><td>+23%</td></tr>
        </table>
    </body></html>");

pdf.SaveAs("report.pdf");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4

Dim pdf = renderer.RenderHtmlAsPdf("
    <html>
    <head><style>
        body { font-family: 'Segoe UI', sans-serif; padding: 40px; }
        h1 { color: #2563eb; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th { background: #2563eb; color: white; padding: 12px; text-align: left; }
        td { padding: 10px; border-bottom: 1px solid #e5e7eb; }
    </style></head>
    <body>
        <h1>Q4 Report</h1>
        <table>
            <tr><th>Metric</th><th>Value</th><th>Change</th></tr>
            <tr><td>Revenue</td><td>$1.2M</td><td>+12%</td></tr>
            <tr><td>Users</td><td>45,230</td><td>+23%</td></tr>
        </table>
    </body></html>")

pdf.SaveAs("report.pdf")
$vbLabelText   $csharpLabel

通過 NuGet 安裝:Install-Package IronPdf。 目標 net8.0 無需額外配置。 部署至 Windows、Linux、macOS、Docker 和 Azure 無需平台特定設置。

為什麼舊版 PDF 程式庫在 .NET 8 中失敗?

iText— 不相容於 .NET 8

iText(iText 的原始 .NET 移植版)自 2018 年以來未更新。它僅針對 .NET Framework:

錯誤 NU1202:iTextSharp 套件 5.5.13 與 net8.0 不相容

遷移路徑為 iText,其具有不同的 API 並需要 AGPL 合規(開源整個應用程式)或商業授權。 價格未公布 — 第三方數據顯示每年 $15,000–$210,000。

wkhtmltopdf 包裝器 — .NET 8 上的 DLL 加載失敗

C# 包裝器 wkhtmltopdf(DinkToPdf、Rotativa、NReco.PdfGenerator)在 .NET 8 的部署模型中因平台特定錯誤而失敗:

DinkToPdf — 找不到原生庫:

System.DllNotFoundException:無法加載DLL 'libwkhtmltox'

Rotativa.AspNetCore — 需要手動二進制路徑配置,與 .NET 8 的容器優先部署衝突:

// This pattern requires deploying wkhtmltopdf binaries alongside your app
// and breaks in Docker containers without explicit path configuration
RotativaConfiguration.Setup(env.WebRootPath, "wkhtmltopdf");
// This pattern requires deploying wkhtmltopdf binaries alongside your app
// and breaks in Docker containers without explicit path configuration
RotativaConfiguration.Setup(env.WebRootPath, "wkhtmltopdf");
' This pattern requires deploying wkhtmltopdf binaries alongside your app
' and breaks in Docker containers without explicit path configuration
RotativaConfiguration.Setup(env.WebRootPath, "wkhtmltopdf")
$vbLabelText   $csharpLabel

TuesPechkin / NReco — 架構不匹配:

System.BadImageFormatException:無法加載檔案或組件

這些錯誤反映了更深層次的問題:wkhtmltopdf 在 2024 年 7 月被歸檔,未修補 CVE。 原生二進制架構早於 .NET 8 的平台檢測改進。 沒有解決方法 — 僅能遷移至不同的程式庫。

PDFSharp— 在 Linux 上的 System.Drawing.Common 失敗

PDFSharp 依賴於 System.Drawing.Common,微軟在 .NET 6 中對非 Windows 平台棄用了。在 .NET 8 中,這在部署到 Linux 或 Docker 時會產生運行時失敗:

using PdfSharp.Pdf;
using PdfSharp.Drawing;

var document = new PdfDocument();
// PlatformNotSupportedException on Linux:
// System.Drawing.Common is not supported on this platform
using PdfSharp.Pdf;
using PdfSharp.Drawing;

var document = new PdfDocument();
// PlatformNotSupportedException on Linux:
// System.Drawing.Common is not supported on this platform
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing

Dim document As New PdfDocument()
' PlatformNotSupportedException on Linux:
' System.Drawing.Common is not supported on this platform
$vbLabelText   $csharpLabel

PDFSharp 6.x 一直致力於消除這一依賴,但截至 2026 年初,跨平台支持仍不完整。對於僅限於 Windows 的部署,PDFSharp 與 .NET 8 配合良好。對於 Linux、Docker 或雲部署,則不可靠。

哪些 PDF 程式庫適用於 .NET 8?

IronPDF— 完全支持 .NET 8,跨平台

IronPDF 針對 net8.0 本地優化,內嵌 Chromium 渲染。 沒有 System.Drawing.Common 依賴,沒有原生二進制管理,沒有特定平台的配置。

Minimal API 整合(主要的 .NET 8 模式):

using IronPdf;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/invoice/{id}/pdf", async (int id, InvoiceService service) =>
{
    var invoice = await service.GetInvoiceAsync(id);
    var renderer = new ChromePdfRenderer();

    var pdf = renderer.RenderHtmlAsPdf(invoice.ToHtml());

    return Results.File(pdf.BinaryData, "application/pdf", $"invoice-{id}.pdf");
});

app.Run();
using IronPdf;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/invoice/{id}/pdf", async (int id, InvoiceService service) =>
{
    var invoice = await service.GetInvoiceAsync(id);
    var renderer = new ChromePdfRenderer();

    var pdf = renderer.RenderHtmlAsPdf(invoice.ToHtml());

    return Results.File(pdf.BinaryData, "application/pdf", $"invoice-{id}.pdf");
});

app.Run();
Imports IronPdf

Dim builder = WebApplication.CreateBuilder(args)
Dim app = builder.Build()

app.MapGet("/invoice/{id}/pdf", Async Function(id As Integer, service As InvoiceService) 
    Dim invoice = Await service.GetInvoiceAsync(id)
    Dim renderer = New ChromePdfRenderer()

    Dim pdf = renderer.RenderHtmlAsPdf(invoice.ToHtml())

    Return Results.File(pdf.BinaryData, "application/pdf", $"invoice-{id}.pdf")
End Function)

app.Run()
$vbLabelText   $csharpLabel

對於使用控制器模式的團隊,相同的代碼可以在控制器操作內部運行 — RenderHtmlAsPdf 返回一個 PdfDocument,您可以使用 .BinaryData 將其轉換為位元組。

授權:永久授權起價 $2,998(Lite — 1 開發者,1 項目)。 Professional:$1,499(10 開發者)。 Enterprise:$2,999(無限)。 發表於 ironpdf.com

QuestPDF— .NET 8 相容,無 HTML

QuestPDF 與 .NET 8 配合,無需平台依賴。 其流暢的 C# API 可程序化地構建文件 — 無 HTML 解析器,無 CSS 引擎,無瀏覽器引擎:

using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

QuestPDF.Settings.License = LicenseType.Community; // Free under $1M revenue

Document.Create(container =>
{
    container.Page(page =>
    {
        page.Size(PageSizes.A4);
        page.Margin(2, Unit.Centimetre);
        page.Content().Column(col =>
        {
            col.Item().Text("Q4 Report").FontSize(24).Bold();
            col.Item().Table(table =>
            {
                table.ColumnsDefinition(c => { c.RelativeColumn(2); c.RelativeColumn(1); c.RelativeColumn(1); });
                table.Header(h =>
                {
                    h.Cell().Text("Metric").Bold();
                    h.Cell().Text("Value").Bold();
                    h.Cell().Text("Change").Bold();
                });
                table.Cell().Text("Revenue"); table.Cell().Text("$1.2M"); table.Cell().Text("+12%");
                table.Cell().Text("Users"); table.Cell().Text("45,230"); table.Cell().Text("+23%");
            });
        });
    });
}).GeneratePdf("report.pdf");
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

QuestPDF.Settings.License = LicenseType.Community; // Free under $1M revenue

Document.Create(container =>
{
    container.Page(page =>
    {
        page.Size(PageSizes.A4);
        page.Margin(2, Unit.Centimetre);
        page.Content().Column(col =>
        {
            col.Item().Text("Q4 Report").FontSize(24).Bold();
            col.Item().Table(table =>
            {
                table.ColumnsDefinition(c => { c.RelativeColumn(2); c.RelativeColumn(1); c.RelativeColumn(1); });
                table.Header(h =>
                {
                    h.Cell().Text("Metric").Bold();
                    h.Cell().Text("Value").Bold();
                    h.Cell().Text("Change").Bold();
                });
                table.Cell().Text("Revenue"); table.Cell().Text("$1.2M"); table.Cell().Text("+12%");
                table.Cell().Text("Users"); table.Cell().Text("45,230"); table.Cell().Text("+23%");
            });
        });
    });
}).GeneratePdf("report.pdf");
Imports QuestPDF.Fluent
Imports QuestPDF.Infrastructure

QuestPDF.Settings.License = LicenseType.Community ' Free under $1M revenue

Document.Create(Sub(container)
    container.Page(Sub(page)
        page.Size(PageSizes.A4)
        page.Margin(2, Unit.Centimetre)
        page.Content().Column(Sub(col)
            col.Item().Text("Q4 Report").FontSize(24).Bold()
            col.Item().Table(Sub(table)
                table.ColumnsDefinition(Sub(c)
                    c.RelativeColumn(2)
                    c.RelativeColumn(1)
                    c.RelativeColumn(1)
                End Sub)
                table.Header(Sub(h)
                    h.Cell().Text("Metric").Bold()
                    h.Cell().Text("Value").Bold()
                    h.Cell().Text("Change").Bold()
                End Sub)
                table.Cell().Text("Revenue")
                table.Cell().Text("$1.2M")
                table.Cell().Text("+12%")
                table.Cell().Text("Users")
                table.Cell().Text("45,230")
                table.Cell().Text("+23%")
            End Sub)
        End Sub)
    End Sub)
End Sub).GeneratePdf("report.pdf")
$vbLabelText   $csharpLabel

QuestPDF 不轉換 HTML。 如果您的工作流程使用 HTML 範本(Razor 視圖、儀表盤匯出、網頁內容歸檔),您需要一個不同的程式庫。 社區授權覆蓋年收入低於 $1M 的企業; 超過此範圍則需要商業授權

iText— .NET 8 相容,AGPL 授權

iText(iText 的繼承者)支持 .NET 8。pdfHTML 插件提供 HTML 到 PDF 的轉換,具有自訂解析器 — 不是瀏覽器引擎,因此現代 CSS 功能(Flexbox、Grid)無法正確渲染。

授權:AGPL 用於開源使用,商業授權(訂閱,價格未公布)用於專有應用程式。iText在 2024 年過渡到訂閱制商業授權

Docker 部署

標準 Debian 映像(推薦)

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["MyApp.csproj", "."]
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app

#IronPDFworks without additional apt-get installs
# Chromium dependencies are handled internally

COPY --from=build /app/publish .

ENV DOTNET_RUNNING_IN_CONTAINER=true
EXPOSE 8080
ENTRYPOINT ["dotnet", "MyApp.dll"]

Alpine 映像(更小的佔地面積)

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
COPY ["MyApp.csproj", "."]
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
WORKDIR /app

# Alpine requires explicit Chromium dependencies
RUN apk add --no-cache chromium nss freetype harfbuzz ca-certificates ttf-freefont

COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Debian 映像不需要額外安裝包。 Alpine 映像較小,但需要明確安裝 Chromium 庫。 對於大多數部署,標準 Debian 映像更簡單且更可靠。

Azure Functions(隔離工作者)

.NET 8 Azure Functions 使用隔離工作者模型。IronPDF與此模型一起使用,實現按需生成 PDF:

using IronPdf;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

namespace MyApp.Functions;

public class PdfFunctions
{
    [Function("GenerateInvoice")]
    public async Task<HttpResponseData> GenerateInvoice(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
    {
        var invoice = await req.ReadFromJsonAsync<InvoiceRequest>();

        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf(BuildInvoiceHtml(invoice));

        var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
        response.Headers.Add("Content-Type", "application/pdf");
        response.Headers.Add("Content-Disposition",
            $"attachment; filename=invoice-{invoice.Id}.pdf");
        await response.Body.WriteAsync(pdf.BinaryData);

        return response;
    }

    private string BuildInvoiceHtml(InvoiceRequest invoice)
    {
        return $@"<html><body>
            <h1>Invoice #{invoice.Id}</h1>
            <p>Amount: ${invoice.Amount:F2}</p>
        </body></html>";
    }
}

public record InvoiceRequest(string Id, decimal Amount);
using IronPdf;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

namespace MyApp.Functions;

public class PdfFunctions
{
    [Function("GenerateInvoice")]
    public async Task<HttpResponseData> GenerateInvoice(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
    {
        var invoice = await req.ReadFromJsonAsync<InvoiceRequest>();

        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf(BuildInvoiceHtml(invoice));

        var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
        response.Headers.Add("Content-Type", "application/pdf");
        response.Headers.Add("Content-Disposition",
            $"attachment; filename=invoice-{invoice.Id}.pdf");
        await response.Body.WriteAsync(pdf.BinaryData);

        return response;
    }

    private string BuildInvoiceHtml(InvoiceRequest invoice)
    {
        return $@"<html><body>
            <h1>Invoice #{invoice.Id}</h1>
            <p>Amount: ${invoice.Amount:F2}</p>
        </body></html>";
    }
}

public record InvoiceRequest(string Id, decimal Amount);
Imports IronPdf
Imports Microsoft.Azure.Functions.Worker
Imports Microsoft.Azure.Functions.Worker.Http

Namespace MyApp.Functions

    Public Class PdfFunctions

        <Function("GenerateInvoice")>
        Public Async Function GenerateInvoice(
            <HttpTrigger(AuthorizationLevel.Function, "post")> req As HttpRequestData) As Task(Of HttpResponseData)

            Dim invoice = Await req.ReadFromJsonAsync(Of InvoiceRequest)()

            Dim renderer = New ChromePdfRenderer()
            Dim pdf = renderer.RenderHtmlAsPdf(BuildInvoiceHtml(invoice))

            Dim response = req.CreateResponse(System.Net.HttpStatusCode.OK)
            response.Headers.Add("Content-Type", "application/pdf")
            response.Headers.Add("Content-Disposition", $"attachment; filename=invoice-{invoice.Id}.pdf")
            Await response.Body.WriteAsync(pdf.BinaryData)

            Return response
        End Function

        Private Function BuildInvoiceHtml(invoice As InvoiceRequest) As String
            Return $"<html><body>
            <h1>Invoice #{invoice.Id}</h1>
            <p>Amount: ${invoice.Amount:F2}</p>
        </body></html>"
        End Function

    End Class

    Public Class InvoiceRequest
        Public Property Id As String
        Public Property Amount As Decimal

        Public Sub New(id As String, amount As Decimal)
            Me.Id = id
            Me.Amount = amount
        End Sub
    End Class

End Namespace
$vbLabelText   $csharpLabel

部署考慮:IronPDF 的 Chromium 二進制檔案為部署包增加約 200MB。 Azure Functions 使用計劃的消耗計劃具有 1.5GB 的部署大小限制 — 檢驗您的總包大小。對於 Premium 或 Dedicated 計劃,此限制不適用。 首次生成 PDF 的冷啟動延遲為 2–5 秒,因為 Chromium 正在初始化。

Native AOT 相容性

.NET 8 擴展了 Native AOT 支持,但 PDF 程式庫面臨基本限制。 基於 Chromium 的程式庫(IronPDF、Puppeteer Sharp)無法編譯 AOT,因為它們嵌入或生成瀏覽器進程。iText使用廣泛的反射,與修剪相衝突。

當前狀態與 <PublishAot>true</PublishAot>

程式庫AOT 狀態原因
IronPDF不相容嵌入 Chromium 運行時
iText不相容大量反射,動態代碼生成
QuestPDF部分(使用 TrimMode=partial一些反射使用
PDFSharp不相容System.Drawing.Common 依賴

如果 Native AOT 是一個嚴格要求,QuestPDF 與 TrimMode=partial 是最接近的選項 — 但僅適用於程序化文件生成,不用於 HTML 轉換。 對於 HTML 到 PDF 的場景,目前沒有適用的程式庫進行 AOT。

授權比較

程式庫模式成本.NET 8 支持
IronPDF永久$2,998(Lite)/$1,499(Pro)/$2,999(Enterprise)完整
iTextAGPL 或訂閱未公布(估計 $15K-$210K/年)完整
QuestPDF社區/商業低於 $1M 收入免費,然後商用完整
PDFSharpMIT(免費)$0僅限 Windows(Linux 不完整)
Aspose.PDF按開發者約 $999+全部(Linux 記憶體問題)

.NET 9 前向相容性

.NET 9 (2025 年 11 月發布)延續了 .NET 8 確立的模式。在 .NET 8 工作的程式庫通常不需要更改即可在 .NET 9 中工作。 與 PDF 生成相關的 .NET 9 關鍵新增功能是改進的 ARM64 性能(利於 Apple Silicon 和 AWS Graviton 上的 Chromium 基於渲染)及持續的 Native AOT 改進(儘管 PDF 程式庫的基本限制仍然存在)。

如果您目標是 .NET 9 或計劃升級,選擇一個完全支持 .NET 8 跨平台部署的程式庫是最安全的途徑。 存在平台特定問題的程式庫(如 Linux 上的 PDFSharp,Aspose 與 libgdiplus)不太可能在 .NET 9 中解決這些問題,因為基礎依賴項的棄用是永久性的。

遷移指南

從iText遷移到 IronPDF

// Before (iTextSharp — doesn't compile against net8.0)
using iTextSharp.text;
using iTextSharp.text.pdf;

var doc = new Document();
PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("Hello World"));
doc.Close();

// After (IronPDF — targets net8.0)
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Hello World</p>");
pdf.SaveAs("output.pdf");
// Before (iTextSharp — doesn't compile against net8.0)
using iTextSharp.text;
using iTextSharp.text.pdf;

var doc = new Document();
PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("Hello World"));
doc.Close();

// After (IronPDF — targets net8.0)
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Hello World</p>");
pdf.SaveAs("output.pdf");
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports IronPdf
Imports System.IO

' Before (iTextSharp — doesn't compile against net8.0)
Dim doc As New Document()
PdfWriter.GetInstance(doc, New FileStream("output.pdf", FileMode.Create))
doc.Open()
doc.Add(New Paragraph("Hello World"))
doc.Close()

' After (IronPDF — targets net8.0)
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<p>Hello World</p>")
pdf.SaveAs("output.pdf")
$vbLabelText   $csharpLabel

從 wkhtmltopdf 包裝器遷移到 IronPDF

// Before (DinkToPdf — DllNotFoundException on .NET 8)
var converter = new SynchronizedConverter(new PdfTools());
var doc = new HtmlToPdfDocument
{
    Objects = { new ObjectSettings { HtmlContent = html } }
};
var bytes = converter.Convert(doc);

// After (IronPDF — native .NET 8 support)
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
var bytes = pdf.BinaryData;
// Before (DinkToPdf — DllNotFoundException on .NET 8)
var converter = new SynchronizedConverter(new PdfTools());
var doc = new HtmlToPdfDocument
{
    Objects = { new ObjectSettings { HtmlContent = html } }
};
var bytes = converter.Convert(doc);

// After (IronPDF — native .NET 8 support)
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
var bytes = pdf.BinaryData;
Imports IronPdf

' Before (DinkToPdf — DllNotFoundException on .NET 8)
Dim converter = New SynchronizedConverter(New PdfTools())
Dim doc = New HtmlToPdfDocument With {
    .Objects = {New ObjectSettings With {.HtmlContent = html}}
}
Dim bytes = converter.Convert(doc)

' After (IronPDF — native .NET 8 support)
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)
bytes = pdf.BinaryData
$vbLabelText   $csharpLabel

在這兩種情況下,API 表面更簡單。 主要的遷移成本是測試您的現有 HTML 範本以驗證輸出是否符合預期。

建議

對於需要 HTML 到 PDF 轉換的 .NET 8 專案:IronPDF 提供嵌入的 Chromium 渲染,跨平台運行無需配置。 它開箱即用處理 Docker 部署、Azure Functions 和 Linux 容器。

對於從數據程序化生成文件的 .NET 8 專案:QuestPDF 的流暢 API 設計良好,與 .NET 8 相容,社區授權覆蓋大多數初創公司和小型團隊。

對於在 Windows 上的 PDF 操作(合併、拆分、表單):如果您的部署目標僅限於 Windows,則PDFSharp仍然可用。

避免使用 iText(不相容)、wkhtmltopdf 包裝器(已歸檔,CVE)以及任何依賴於 System.Drawing.Common 的跨平台部署程式庫。

請注意Aspose、DinkToPdf、NReco、PDFSharp、PuppeteerSharp、QuestPDF、Rotativa、TuesPechkin、iText 和 wkhtmltopdf 是其各自所有者的註冊商標。 本網站與 Aspose Pty Ltd、CodeFlint、DinkToPdf、NReco、PuppeteerSharp、Rotativa、TuesPechkin、empira Software GmbH、iText Group 或 wkhtmltopdf 無關,未獲得其認可或贊助。 所有產品名稱、標誌及商標均為其各自所有者的財產。 比較僅供信息參考,反映在寫作時公開的相關信息。)}]