跳過到頁腳內容
遷移指南

如何在 C# 中從 BitMiracle Docotic PDF 遷移到 IronPDF

BitMiracle Docotic PDF 是一個廣受好評的 .NET PDF 函式庫,以其 100% 的管理代碼架構和廣泛的程式化 PDF 操作功能而聞名。 然而,其模組化的附加元件結構 (HTML-to-PDF轉換、排版功能和其他功能需要獨立的套件),增加了專案管理和授權的複雜性。 本綜合指南提供了從BitMiracle Docotic PDF到IronPDF的逐步遷移路徑 -IronPDFfor .NET 是一個統一的 .NET PDF 函式庫,內建了基於 Chromium 的 HTML 渲染功能,所有功能都包含在單一的 NuGet 套件中。

為什麼要從BitMiracle Docotic PDF轉移到 IronPDF?

雖然BitMiracle Docotic PDF提供強大的 PDF 操作功能,但仍有幾個因素促使開發團隊尋找架構更精簡的替代方案。

套件架構比較

BitMiracle Docotic PDF 使用模組化的附加元件方式,需要多個套件才能達到完整的功能:

範疇 BitMiracle Docotic PDF IronPDF
HTML轉PDF 需要單獨的附加元件 (HtmlToPdf) 內建核心功能
套件結構 核心 + 多個附加元件 單一 NuGet 套件
授權模式 按附加元件授權 所有功能包括
API複雜性 每個附加元件有獨立的名稱空間 統一 API
HTML 引擎 Chromium (透過附加元件) Chromium (內建)
社群大小 較小 規模更大、資源更多
說明文件 技術參考 廣泛的教學

功能對等

這兩個函式庫都支援全面的 PDF 功能:

特點 BitMiracle Docotic PDF IronPDF
從零開始建立 PDF
HTML 至 PDF ✅ (需要附加元件) ✅(內建)
URL 至 PDF ✅ (需要附加元件) ✅(內建)
PDF 操作
文字擷取
合併/分割
數位簽名
加密
表格填寫
符合 PDF/A 規範

方法上的主要差異

BitMiracle Docot PDF 使用基於畫布的繪圖和座標定位 (canvas.DrawString(x, y, text)),而IronPDF利用 HTML/CSS 進行佈局和定位。 這代表了一種模式的轉變,簡化了熟悉網路技術的開發人員的內容創作。

遷移前的準備工作

先決條件

確保您的環境符合這些要求:

  • .NET Framework 4.6.2+ 或 .NET Core 3.1 / .NET 5-9
  • Visual Studio 2019+ 或具有 C# 擴充功能的 VS Code
  • NuGet 套件管理員存取權限 -IronPDF授權金鑰 (可於 ironpdf.com 網站免費試用)

審核BitMiracle Docotic PDF使用情況

在您的解決方案目錄中執行這些指令,以識別所有 Docotic.Pdf 引用:

# Find all Docotic.Pdf usages in your codebase
grep -r "using BitMiracle.Docotic" --include="*.cs" .
grep -r "PdfDocument\|PdfPage\|PdfCanvas" --include="*.cs" .

# Find NuGet package references
grep -r "Docotic.Pdf" --include="*.csproj" .
# Find all Docotic.Pdf usages in your codebase
grep -r "using BitMiracle.Docotic" --include="*.cs" .
grep -r "PdfDocument\|PdfPage\|PdfCanvas" --include="*.cs" .

# Find NuGet package references
grep -r "Docotic.Pdf" --include="*.csproj" .
SHELL

可預期的重大變更

變更 BitMiracle Docotic PDF IronPDF 影響力
HTML 渲染 需要 HtmlToPdf 附加元件 內建 移除附加套件
頁面索引 基於 0 的 (Pages[0]) 基於 0 的 (Pages[0]) 不需要變更
坐標系統 左下方來源 HTML/CSS 流程 使用 CSS 進行定位
畫布繪圖 PdfCanvas.DrawText() HTML 標記 範式轉換
文字萃取 page.GetText() pdf.ExtractAllText() 方法名稱變更
文件載入 new PdfDocument(path) PdfDocument.FromFile(path) 構成器 → 靜態方法
節省成本 document.Save(path) pdf.SaveAs(path) 方法名稱變更
處理方式 IDisposable 模式 不需要 更簡單的資源管理

逐步遷移的過程

步驟 1:更新 NuGet 套件

移除BitMiracle Docotic PDF套件並安裝 IronPDF:

# Remove Docotic.Pdf packages
dotnet remove package BitMiracle.Docotic.Pdf
dotnet remove package BitMiracle.Docotic.Pdf.HtmlToPdf
dotnet remove package BitMiracle.Docotic.Pdf.Layout

# Install IronPDF
dotnet add package IronPdf
# Remove Docotic.Pdf packages
dotnet remove package BitMiracle.Docotic.Pdf
dotnet remove package BitMiracle.Docotic.Pdf.HtmlToPdf
dotnet remove package BitMiracle.Docotic.Pdf.Layout

# Install IronPDF
dotnet add package IronPdf
SHELL

步驟 2:更新命名空間參考資料

用IronPDF取代BitMiracle Docotic PDF命名空間:

// Remove these
using BitMiracle.Docotic.Pdf;
using BitMiracle.Docotic.Pdf.Layout;
using BitMiracle.Docotic.Pdf.HtmlToPdf;

// Add this
using IronPdf;
// Remove these
using BitMiracle.Docotic.Pdf;
using BitMiracle.Docotic.Pdf.Layout;
using BitMiracle.Docotic.Pdf.HtmlToPdf;

// Add this
using IronPdf;
Imports IronPdf
$vbLabelText   $csharpLabel

步驟 3:配置授權

// Add at application startup (Program.cs or Global.asax)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Global.asax)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Global.asax)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

完整的 API 遷移參考。

文件操作

任務 BitMiracle Docotic PDF IronPDF
建立空白文件 new PdfDocument() new PdfDocument()
從檔案載入 new PdfDocument(path) PdfDocument.FromFile(path)
從串流載入 PdfDocument.Load(stream) PdfDocument.FromStream(stream)
從字節載入 PdfDocument.Load(bytes) PdfDocument.FromBinaryData(bytes)
儲存至檔案 document.Save(path) pdf.SaveAs(path)
取得頁數 document.PageCount pdf.PageCount
關閉/刪除 document.Dispose() 不需要

HTML 至 PDF 轉換

任務 BitMiracle Docotic PDF (HtmlToPdf 附加元件) IronPDF
HTML 字串至 PDF HtmlConverter.Create(html).ToPdf() renderer.RenderHtmlAsPdf(html)
HTML 檔案轉 PDF HtmlConverter.Create(new Uri(filePath)).ToPdf() renderer.RenderHtmlFileAsPdf(path)
URL 至 PDF HtmlConverter.Create(new Uri(url)).ToPdf() renderer.RenderUrlAsPdf(url)
設定頁面大小 options.PageSize = PageSize.A4 renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
設定頁邊空白 options.PageMargins = new Margins(20) renderer.RenderingOptions.MarginTop = 20

合併與分割作業

任務 BitMiracle Docotic PDF IronPDF
合併文件 doc1.Append(doc2) PdfDocument.Merge(pdf1, pdf2)
分割文件 document.CopyPage(index) 到新文檔 pdf.CopyPages(start, end)

程式碼遷移範例

HTML 至 PDF 轉換

最常見的操作展示了IronPDF所提供的顯著簡化功能。

BitMiracle Docotic PDF 實作:

// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf = new PdfDocument())
        {
            string html = "<html><body><h1>Hello World</h1><p>This isHTML 至 PDFconversion.</p></body></html>";

            pdf.CreatePage(html);
            pdf.Save("output.pdf");
        }

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf = new PdfDocument())
        {
            string html = "<html><body><h1>Hello World</h1><p>This isHTML 至 PDFconversion.</p></body></html>";

            pdf.CreatePage(html);
            pdf.Save("output.pdf");
        }

        Console.WriteLine("PDF created successfully");
    }
}
Imports BitMiracle.Docotic.Pdf
Imports System

Class Program
    Shared Sub Main()
        Using pdf As New PdfDocument()
            Dim html As String = "<html><body><h1>Hello World</h1><p>This isHTML 至 PDFconversion.</p></body></html>"

            pdf.CreatePage(html)
            pdf.Save("output.pdf")
        End Using

        Console.WriteLine("PDF created successfully")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF 實作:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string html = "<html><body><h1>Hello World</h1><p>This isHTML 至 PDFconversion.</p></body></html>";

        var pdf = renderer.RenderHtmlAsPdf(html);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string html = "<html><body><h1>Hello World</h1><p>This isHTML 至 PDFconversion.</p></body></html>";

        var pdf = renderer.RenderHtmlAsPdf(html);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim html As String = "<html><body><h1>Hello World</h1><p>This is HTML to PDF conversion.</p></body></html>"

        Dim pdf = renderer.RenderHtmlAsPdf(html)
        pdf.SaveAs("output.pdf")

        Console.WriteLine("PDF created successfully")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF 消除了 using 語句要求,並提供了一個專用的 ChromePdfRenderer 類,清楚地表明了其基於 Chromium 的渲染功能。 如需更多 HTML 轉換選項,請參閱 HTML to PDF 文件

合併多個 PDF 文件

BitMiracle Docotic PDF 實作:

// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf1 = new PdfDocument("document1.pdf"))
        using (var pdf2 = new PdfDocument("document2.pdf"))
        {
            pdf1.Append(pdf2);
            pdf1.Save("merged.pdf");
        }

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf1 = new PdfDocument("document1.pdf"))
        using (var pdf2 = new PdfDocument("document2.pdf"))
        {
            pdf1.Append(pdf2);
            pdf1.Save("merged.pdf");
        }

        Console.WriteLine("PDFs merged successfully");
    }
}
Imports BitMiracle.Docotic.Pdf
Imports System

Class Program
    Shared Sub Main()
        Using pdf1 As New PdfDocument("document1.pdf"), pdf2 As New PdfDocument("document2.pdf")
            pdf1.Append(pdf2)
            pdf1.Save("merged.pdf")
        End Using

        Console.WriteLine("PDFs merged successfully")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF 實作:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

        var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 });
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

        var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 });
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic

Module Program
    Sub Main()
        Dim pdf1 As PdfDocument = PdfDocument.FromFile("document1.pdf")
        Dim pdf2 As PdfDocument = PdfDocument.FromFile("document2.pdf")

        Dim merged As PdfDocument = PdfDocument.Merge(New List(Of PdfDocument) From {pdf1, pdf2})
        merged.SaveAs("merged.pdf")

        Console.WriteLine("PDFs merged successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDF 的靜態 Merge 方法直接接受多個文檔,提供比迭代 Append 模式更簡潔的 API。 更多選項請參閱PDF 合併文件

文字萃取

BitMiracle Docotic PDF 實作:

// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf = new PdfDocument("document.pdf"))
        {
            string allText = "";

            foreach (var page in pdf.Pages)
            {
                allText += page.GetText();
            }

            Console.WriteLine("Extracted text:");
            Console.WriteLine(allText);
        }
    }
}
// NuGet: Install-Package Docotic.Pdf
using BitMiracle.Docotic.Pdf;
using System;

class Program
{
    static void Main()
    {
        using (var pdf = new PdfDocument("document.pdf"))
        {
            string allText = "";

            foreach (var page in pdf.Pages)
            {
                allText += page.GetText();
            }

            Console.WriteLine("Extracted text:");
            Console.WriteLine(allText);
        }
    }
}
Imports BitMiracle.Docotic.Pdf
Imports System

Module Program
    Sub Main()
        Using pdf As New PdfDocument("document.pdf")
            Dim allText As String = ""

            For Each page In pdf.Pages
                allText &= page.GetText()
            Next

            Console.WriteLine("Extracted text:")
            Console.WriteLine(allText)
        End Using
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDF 實作:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("document.pdf");
        string allText = pdf.ExtractAllText();

        Console.WriteLine("Extracted text:");
        Console.WriteLine(allText);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("document.pdf");
        string allText = pdf.ExtractAllText();

        Console.WriteLine("Extracted text:");
        Console.WriteLine(allText);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim pdf = PdfDocument.FromFile("document.pdf")
        Dim allText As String = pdf.ExtractAllText()

        Console.WriteLine("Extracted text:")
        Console.WriteLine(allText)
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF 將文字擷取從多行迴圈縮減為單一方法呼叫。 如需更多擷取選項,請參閱文字擷取文件

密碼保護與加密

IronPDF 實作:

using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Document</h1>");

// Set security
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;

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

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Document</h1>");

// Set security
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;

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

Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Document</h1>")

' Set security
pdf.SecuritySettings.UserPassword = "userPassword"
pdf.SecuritySettings.OwnerPassword = "ownerPassword"
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
pdf.SecuritySettings.AllowUserCopyPasteContent = False

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

有關全面的安全性選項,請參閱加密文件

頁首和頁尾

IronPDF 實作:

using IronPdf;

var renderer = new ChromePdfRenderer();

renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = @"
        <div style='text-align:center; font-size:12px;'>
            Company Header - Confidential
        </div>",
    DrawDividerLine = true,
    MaxHeight = 30
};

renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = @"
        <div style='text-align:center; font-size:10px;'>
            Page {page} of {total-pages}
        </div>",
    DrawDividerLine = true,
    MaxHeight = 25
};

var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>");
pdf.SaveAs("with_headers.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = @"
        <div style='text-align:center; font-size:12px;'>
            Company Header - Confidential
        </div>",
    DrawDividerLine = true,
    MaxHeight = 30
};

renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = @"
        <div style='text-align:center; font-size:10px;'>
            Page {page} of {total-pages}
        </div>",
    DrawDividerLine = true,
    MaxHeight = 25
};

var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>");
pdf.SaveAs("with_headers.pdf");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()

renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
    .HtmlFragment = "
        <div style='text-align:center; font-size:12px;'>
            Company Header - Confidential
        </div>",
    .DrawDividerLine = True,
    .MaxHeight = 30
}

renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
    .HtmlFragment = "
        <div style='text-align:center; font-size:10px;'>
            Page {page} of {total-pages}
        </div>",
    .DrawDividerLine = True,
    .MaxHeight = 25
}

Dim pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>")
pdf.SaveAs("with_headers.pdf")
$vbLabelText   $csharpLabel

IronPDF 支援 {page}{total-pages} 等佔位標記,用於動態頁碼。 如需更多選項,請參閱 headers and footers 文件

關鍵遷移注意事項

Canvas 到 HTML 的範式轉換

BitMiracle Docotic PDF 基於畫布的繪圖方式必須以 CSS 定位轉換為 HTML:

BitMiracle Docotic PDF 模式:

var canvas = pdfPage.Canvas;
canvas.DrawString(50, 50, "Hello, World!");
var canvas = pdfPage.Canvas;
canvas.DrawString(50, 50, "Hello, World!");
Dim canvas = pdfPage.Canvas
canvas.DrawString(50, 50, "Hello, World!")
$vbLabelText   $csharpLabel

IronPDF模式:

var html = "<div style='position:absolute; left:50px; top:50px;'>Hello, World!</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
var html = "<div style='position:absolute; left:50px; top:50px;'>Hello, World!</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
Dim html As String = "<div style='position:absolute; left:50px; top:50px;'>Hello, World!</div>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
$vbLabelText   $csharpLabel

同頁索引

這兩個庫都使用從 0 開始的索引(Pages[0] 是第一頁)——頁面存取程式碼無需更改。

不需要處理。

IronPDF 不需要 using 語句進行記憶體管理,從而簡化了程式碼結構:

//BitMiracle Docotic PDF- disposal required
using (var pdf = new PdfDocument("input.pdf"))
{
    // operations
}

//IronPDF- disposal optional
var pdf = PdfDocument.FromFile("input.pdf");
// operations - no using statement needed
//BitMiracle Docotic PDF- disposal required
using (var pdf = new PdfDocument("input.pdf"))
{
    // operations
}

//IronPDF- disposal optional
var pdf = PdfDocument.FromFile("input.pdf");
// operations - no using statement needed
Imports BitMiracle.Docotic.Pdf

' BitMiracle Docotic PDF - disposal required
Using pdf As New PdfDocument("input.pdf")
    ' operations
End Using

' IronPDF - disposal optional
Dim pdf = PdfDocument.FromFile("input.pdf")
' operations - no using statement needed
$vbLabelText   $csharpLabel

同步支援

BitMiracle Docotic PDF 的 HtmlToPdf 附加元件處處需要使用 async 模式。IronPDF支援同步和異步方法:

// Synchronous
var pdf = renderer.RenderHtmlAsPdf(html);

// Asynchronous
var pdf = await renderer.RenderHtmlAsPdfAsync(html);
// Synchronous
var pdf = renderer.RenderHtmlAsPdf(html);

// Asynchronous
var pdf = await renderer.RenderHtmlAsPdfAsync(html);
' Synchronous
Dim pdf = renderer.RenderHtmlAsPdf(html)

' Asynchronous
Dim pdf = Await renderer.RenderHtmlAsPdfAsync(html)
$vbLabelText   $csharpLabel

ASP.NET Core 整合。

IronPDF模式:

[ApiController]
[Route("[controller]")]
public class PdfController : ControllerBase
{
    [HttpGet("generate")]
    public IActionResult GeneratePdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>");

        return File(pdf.BinaryData, "application/pdf", "report.pdf");
    }

    [HttpGet("generate-async")]
    public async Task<IActionResult> GeneratePdfAsync()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>");

        return File(pdf.Stream, "application/pdf", "report.pdf");
    }
}
[ApiController]
[Route("[controller]")]
public class PdfController : ControllerBase
{
    [HttpGet("generate")]
    public IActionResult GeneratePdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>");

        return File(pdf.BinaryData, "application/pdf", "report.pdf");
    }

    [HttpGet("generate-async")]
    public async Task<IActionResult> GeneratePdfAsync()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>");

        return File(pdf.Stream, "application/pdf", "report.pdf");
    }
}
Imports Microsoft.AspNetCore.Mvc

<ApiController>
<Route("[controller]")>
Public Class PdfController
    Inherits ControllerBase

    <HttpGet("generate")>
    Public Function GeneratePdf() As IActionResult
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>")

        Return File(pdf.BinaryData, "application/pdf", "report.pdf")
    End Function

    <HttpGet("generate-async")>
    Public Async Function GeneratePdfAsync() As Task(Of IActionResult)
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = Await renderer.RenderHtmlAsPdfAsync("<h1>Report</h1>")

        Return File(pdf.Stream, "application/pdf", "report.pdf")
    End Function
End Class
$vbLabelText   $csharpLabel

遷移後檢查清單

完成程式碼遷移後,請驗證下列事項:

執行所有單元測試以驗證 PDF 產生功能是否正常。

  • 比較 PDF 輸出品質(IronPDF 的 Chromium 引擎渲染效果可能略有不同——通常更好)
  • 驗證文字擷取準確性
  • 測試表單填寫功能
  • 如適用,驗證數位簽名
  • 效能測試批次作業
  • 在所有目標環境中進行測試
  • 更新 CI/CD 管線
  • 刪除 Docotic.Pdf 授權文件

讓您的 PDF 基礎架構面向未來

由於 .NET 10 即將推出,而 C# 14 也將引進新的語言功能,因此選擇具有統一架構的 PDF 函式庫可簡化相依性管理,並確保功能可用性的一致性。IronPDF的單一套件方式意味著當專案延伸至 2025 年和 2026 年時,您不需要追蹤多個附加版本的相容性。

其他資源


從BitMiracle Docotic PDF遷移到IronPDF可消除管理多個附加套件的複雜性,同時提供相同的基於 Chromium 的 HTML 渲染功能。 從以畫布為基礎的繪圖過渡到 HTML/CSS 定位,可利用大多數 .NET 開發人員已具備的網頁開發技能,進而產生更易維護的 PDF 生成程式碼。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我