如何用 C# 從 Gnostice PDFOne 轉移到 IronPDF
從Gnostice PDFOne轉換到 IronPDF,可將您的 .NET PDF 工作流程從基於坐標、平台分散的方式轉換為統一、HTML/CSS 驅動的解決方案,並完全支援現代網路標準。 本指南提供了一個全面、循序漸進的遷移路徑,為專業的 .NET 開發人員消除了文件中關於 CSS、JavaScript 和記憶體穩定性的限制。
為什麼要從Gnostice PDFOne轉移到 IronPDF?
Gnostice PDFOne的挑戰
Gnostice PDFOne 和 Document Studio .NET 有著被詳細記錄的限制,會影響生產應用程式:
1.不支援外部 CSS:Gnostice PDFOne的文檔明確指出它不支援外部 CSS 樣式表-這是現代 Web 到 PDF 轉換的基本要求。
2.無法執行 JavaScript:需要 JavaScript 的動態內容無法渲染,因此無法準確地轉換現代 Web 應用程式。
3.不支援直接 HTML 轉 PDF:Gnostice PDFOne不支援直接 HTML 轉 PDF 轉換。 您需要使用 Document Studio 進行 HTML 轉換,或手動解析和呈現 HTML 元素 - 這是相當大的開發開銷。
4.平台碎片化: WinForms、WPF、ASP.NET 和 Xamarin 各自擁有獨立的產品,功能集和 API 也各不相同。您可能需要多個許可證和程式碼庫。
5.記憶體洩漏和穩定性:使用者論壇和 Stack Overflow 報告稱,在處理影像時有持續的記憶體洩漏、JPEG 錯誤 #53 和 StackOverflow 異常。
6.不支援從右到左的 Unicode:明確不支援阿拉伯語、希伯來語和其他 RTL 語言——這對國際應用來說是致命的缺陷。
7.數位簽章支援有限:Gnostice PDFOne一直以來都缺乏數位簽章功能或數位簽章功能不可靠。
8.基於座標的 API:許多操作需要手動 X/Y 定位,而不是現代佈局方法,因此每個元素的放置都需要精確計算。
Gnostice PDFOne與IronPDF的比較
| 範疇 | Gnostice PDFOne | IronPDF |
|---|---|---|
| 外部 CSS | 不支援 | 支援 |
| JavaScript 執行 | 不支援 | 完整的 Chromium 引擎 |
| RTL 語言 | 不支援 | 完全支援 Unicode |
| 數位簽名 | 有限/遺漏 | 完全支援 X509 |
| 平台 | 零散的產品 | 單一統一的程式庫 |
| 記憶體穩定性 | 報告的問題 | 穩定、管理完善 |
| HTML 至 PDF | 基本,需要變通 | Chrome 品質的渲染 |
| 學習曲線 | 複雜的 API | 簡單直覺的 API |
| 現代 CSS (Flexbox、Grid) | 不支援 | 完全支援 CSS3 |
| 圖像處理 | 已知問題 | 可靠 |
對於計劃在 2025 年和 2026 年之前採用 .NET 10 和 C# 14 的團隊而言,IronPDF 提供了一個面向未來的基礎,其統一的資料庫可在所有 .NET 平台上一致運作。
遷移複雜性評估
按功能估計的工作量
| 特點 | 遷移複雜性 |
|---|---|
| 載入/儲存 PDF | 非常低 |
| 合併 PDF | 非常低 |
| 分割 PDF | 低 |
| 文字擷取 | 低 |
| 水印 | 低 |
| 頁首/頁尾 | 低 |
| HTML 至 PDF | 低 |
| 加密 | 語言 |
| 表格欄位 | 語言 |
| 數位簽名 | 低 |
您將獲得的功能
當從Gnostice PDFOne轉移到IronPDF時,這些以前不可能實現的功能將變得可用:
- 外部 CSS 樣式表
- JavaScript 執行
- 支援 RTL 語言(阿拉伯文、希伯來文)
- CSS 網格與 Flexbox
- 可靠的數位簽章
- 更好的記憶體管理
- 單一程式碼基礎的跨平台支援
開始之前
先決條件
- .NET 版本:IronPDF支援 .NET Framework 4.6.2+ 和 .NET Core 2.0+ / .NET 5/6/7/8/9+ 2.許可證密鑰:請從ironpdf.com取得您的IronPDF許可證密鑰。 3.備份:建立一個用於遷移工作的分支
辨識所有Gnostice PDFOne使用方式
# Find all Gnostice references
grep -r "Gnostice\|PDFOne\|PDFDocument\|PDFPage\|DocExporter" --include="*.cs" .
# Find package references
grep -r "Gnostice\|PDFOne" --include="*.csproj" .
# Find all Gnostice references
grep -r "Gnostice\|PDFOne\|PDFDocument\|PDFPage\|DocExporter" --include="*.cs" .
# Find package references
grep -r "Gnostice\|PDFOne" --include="*.csproj" .
NuGet 套件變更
# RemoveGnostice PDFOnepackages
dotnet remove package PDFOne.NET
dotnet remove package Gnostice.DocumentStudio.NET
dotnet remove package Gnostice.PDFOne.NET
dotnet remove package Gnostice.XtremeDocumentStudio.NET
# Install IronPDF
dotnet add package IronPdf
# RemoveGnostice PDFOnepackages
dotnet remove package PDFOne.NET
dotnet remove package Gnostice.DocumentStudio.NET
dotnet remove package Gnostice.PDFOne.NET
dotnet remove package Gnostice.XtremeDocumentStudio.NET
# Install IronPDF
dotnet add package IronPdf
快速啟動遷移
步驟 1:更新授權組態
之前 (Gnostice PDFOne):
// Gnostice license often set via config or property
PDFOne.License.LicenseKey = "YOUR-GNOSTICE-LICENSE";
// Gnostice license often set via config or property
PDFOne.License.LicenseKey = "YOUR-GNOSTICE-LICENSE";
' Gnostice license often set via config or property
PDFOne.License.LicenseKey = "YOUR-GNOSTICE-LICENSE"
After (IronPDF):
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
' Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY"
' Or in appsettings.json:
' { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
步驟 2:更新命名空間匯入
// Before (Gnostice PDFOne)
using Gnostice.PDFOne;
using Gnostice.PDFOne.Document;
using Gnostice.PDFOne.Graphics;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
// Before (Gnostice PDFOne)
using Gnostice.PDFOne;
using Gnostice.PDFOne.Document;
using Gnostice.PDFOne.Graphics;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Editing
完整的 API 參考資料
核心類映射
| Gnostice PDFOne | IronPDF | 說明 |
|---|---|---|
PDFDocument |
PdfDocument |
主要 PDF 文件類別 |
PDFPage |
PdfDocument.Pages[i] |
頁面表示 |
PDFFont |
CSS 造型 | 字型規格 |
PDFTextElement |
HTML 內容 | 文字內容 |
PDFImageElement |
HTML 標籤 | 圖片內容 |
DocExporter |
ChromePdfRenderer |
HTML/URL 至 PDF 的轉換 |
文件操作
| Gnostice PDFOne | IronPDF |
|---|---|
new PDFDocument() |
new PdfDocument() |
doc.Load(path) |
PdfDocument.FromFile(path) |
doc.Open() |
不適用 (自動) |
doc.Save(path) |
pdf.SaveAs(path) |
doc.Close() |
pdf.Dispose() |
doc.Pages.Count |
pdf.PageCount |
doc.Pages.Add() |
渲染 HTML 或合併 |
合併作業
| Gnostice PDFOne | IronPDF |
|---|---|
doc.Append(otherDoc) |
PdfDocument.Merge(pdf1, pdf2) |
多次 Append() 調用 |
PdfDocument.Merge(list) |
程式碼遷移範例
範例 1:HTML 到 PDF 的轉換
之前 (Gnostice PDFOne):
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Graphics;
using System;
class Program
{
static void Main()
{
PDFDocument doc = new PDFDocument();
doc.Open();
PDFPage page = doc.Pages.Add();
// PDFOne doesn't have directHTML 至 PDFconversion
// You need to use Document Studio for HTML conversion
// Or manually parse and render HTML elements
PDFTextElement textElement = new PDFTextElement();
textElement.Text = "Simple text conversion instead of HTML";
textElement.Draw(page, 10, 10);
doc.Save("output.pdf");
doc.Close();
}
}
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Graphics;
using System;
class Program
{
static void Main()
{
PDFDocument doc = new PDFDocument();
doc.Open();
PDFPage page = doc.Pages.Add();
// PDFOne doesn't have directHTML 至 PDFconversion
// You need to use Document Studio for HTML conversion
// Or manually parse and render HTML elements
PDFTextElement textElement = new PDFTextElement();
textElement.Text = "Simple text conversion instead of HTML";
textElement.Draw(page, 10, 10);
doc.Save("output.pdf");
doc.Close();
}
}
Imports Gnostice.PDFOne
Imports Gnostice.PDFOne.Graphics
Imports System
Module Program
Sub Main()
Dim doc As New PDFDocument()
doc.Open()
Dim page As PDFPage = doc.Pages.Add()
' PDFOne doesn't have direct HTML to PDF conversion
' You need to use Document Studio for HTML conversion
' Or manually parse and render HTML elements
Dim textElement As New PDFTextElement()
textElement.Text = "Simple text conversion instead of HTML"
textElement.Draw(page, 10, 10)
doc.Save("output.pdf")
doc.Close()
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello World</h1><p>This is HTML content.</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello World</h1><p>This is HTML content.</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<h1>Hello World</h1><p>This is HTML content.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Class
差異很大:Gnostice PDFOne 無法直接將 HTML 轉換成 PDF,您必須手動建立文字元素並使用座標定位。IronPDF的 ChromePdfRenderer 提供直接 HTML 渲染,並完全支援 CSS3 和 JavaScript。 請參閱 HTML to PDF 文件,以瞭解更多渲染選項。
範例 2:合併 PDF 檔案
之前 (Gnostice PDFOne):
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Document;
using System;
class Program
{
static void Main()
{
PDFDocument doc1 = new PDFDocument();
doc1.Load("document1.pdf");
PDFDocument doc2 = new PDFDocument();
doc2.Load("document2.pdf");
PDFDocument mergedDoc = new PDFDocument();
mergedDoc.Open();
mergedDoc.Append(doc1);
mergedDoc.Append(doc2);
mergedDoc.Save("merged.pdf");
doc1.Close();
doc2.Close();
mergedDoc.Close();
}
}
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Document;
using System;
class Program
{
static void Main()
{
PDFDocument doc1 = new PDFDocument();
doc1.Load("document1.pdf");
PDFDocument doc2 = new PDFDocument();
doc2.Load("document2.pdf");
PDFDocument mergedDoc = new PDFDocument();
mergedDoc.Open();
mergedDoc.Append(doc1);
mergedDoc.Append(doc2);
mergedDoc.Save("merged.pdf");
doc1.Close();
doc2.Close();
mergedDoc.Close();
}
}
Imports Gnostice.PDFOne
Imports Gnostice.PDFOne.Document
Imports System
Module Program
Sub Main()
Dim doc1 As New PDFDocument()
doc1.Load("document1.pdf")
Dim doc2 As New PDFDocument()
doc2.Load("document2.pdf")
Dim mergedDoc As New PDFDocument()
mergedDoc.Open()
mergedDoc.Append(doc1)
mergedDoc.Append(doc2)
mergedDoc.Save("merged.pdf")
doc1.Close()
doc2.Close()
mergedDoc.Close()
End Sub
End Module
After (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(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}
// 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(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}
Imports IronPdf
Imports System
Imports System.Collections.Generic
Module Program
Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End Module
Gnostice PDFOne 方法需要建立新文件、開啟文件、分別載入原始文件、追加每個文件,然後手動關閉所有三個文件。IronPDF的靜態 Merge 方法透過適當的資源管理,只需三行程式碼即可處理此問題。 進一步瞭解 合併與分割 PDF 的相關資訊。
範例 3:在 PDF 上加入水印
之前 (Gnostice PDFOne):
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Graphics;
using System;
using System.Drawing;
class Program
{
static void Main()
{
PDFDocument doc = new PDFDocument();
doc.Load("input.pdf");
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 48);
foreach (PDFPage page in doc.Pages)
{
PDFTextElement watermark = new PDFTextElement();
watermark.Text = "CONFIDENTIAL";
watermark.Font = font;
watermark.Color = Color.FromArgb(128, 255, 0, 0);
watermark.RotationAngle = 45;
watermark.Draw(page, 200, 400);
}
doc.Save("watermarked.pdf");
doc.Close();
}
}
// NuGet: Install-Package Gnostice.PDFOne.DLL
using Gnostice.PDFOne;
using Gnostice.PDFOne.Graphics;
using System;
using System.Drawing;
class Program
{
static void Main()
{
PDFDocument doc = new PDFDocument();
doc.Load("input.pdf");
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 48);
foreach (PDFPage page in doc.Pages)
{
PDFTextElement watermark = new PDFTextElement();
watermark.Text = "CONFIDENTIAL";
watermark.Font = font;
watermark.Color = Color.FromArgb(128, 255, 0, 0);
watermark.RotationAngle = 45;
watermark.Draw(page, 200, 400);
}
doc.Save("watermarked.pdf");
doc.Close();
}
}
Imports Gnostice.PDFOne
Imports Gnostice.PDFOne.Graphics
Imports System
Imports System.Drawing
Module Program
Sub Main()
Dim doc As New PDFDocument()
doc.Load("input.pdf")
Dim font As New PDFFont(PDFStandardFont.Helvetica, 48)
For Each page As PDFPage In doc.Pages
Dim watermark As New PDFTextElement()
watermark.Text = "CONFIDENTIAL"
watermark.Font = font
watermark.Color = Color.FromArgb(128, 255, 0, 0)
watermark.RotationAngle = 45
watermark.Draw(page, 200, 400)
Next
doc.Save("watermarked.pdf")
doc.Close()
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
var watermark = new TextStamper()
{
Text = "CONFIDENTIAL",
FontSize = 48,
Opacity = 50,
Rotation = 45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
};
pdf.ApplyStamp(watermark);
pdf.SaveAs("watermarked.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
var watermark = new TextStamper()
{
Text = "CONFIDENTIAL",
FontSize = 48,
Opacity = 50,
Rotation = 45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
};
pdf.ApplyStamp(watermark);
pdf.SaveAs("watermarked.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Imports System
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
Dim watermark = New TextStamper() With {
.Text = "CONFIDENTIAL",
.FontSize = 48,
.Opacity = 50,
.Rotation = 45,
.VerticalAlignment = VerticalAlignment.Middle,
.HorizontalAlignment = HorizontalAlignment.Center
}
pdf.ApplyStamp(watermark)
pdf.SaveAs("watermarked.pdf")
End Sub
End Module
Gnostice PDFOne 方法需要建立 PDFFont 對象,手動遍歷頁面,計算座標 (200, 400),並設定 PDFTextElement 物件的屬性。IronPDF的 TextStamper 提供宣告式配置,具有自動居中和頁面應用功能-無需座標計算。 請參閱浮水印文件以了解更多選項。
關鍵遷移注意事項
基於座標的 HTML/CSS 排版
這次Gnostice PDFOne遷移中最重要的範式轉換,就是從基於座標的定位轉移至 HTML/CSS 排版:
// Gnostice PDFOne: Manual coordinate positioning
watermark.Draw(page, 200, 400); // X=200, Y=400
// IronPDF: Declarative alignment
watermark.VerticalAlignment = VerticalAlignment.Middle;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
// Gnostice PDFOne: Manual coordinate positioning
watermark.Draw(page, 200, 400); // X=200, Y=400
// IronPDF: Declarative alignment
watermark.VerticalAlignment = VerticalAlignment.Middle;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
' Gnostice PDFOne: Manual coordinate positioning
watermark.Draw(page, 200, 400) ' X=200, Y=400
' IronPDF: Declarative alignment
watermark.VerticalAlignment = VerticalAlignment.Middle
watermark.HorizontalAlignment = HorizontalAlignment.Center
從字體物件到 CSS 造型
// Gnostice PDFOne
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 48);
watermark.Font = font;
//IronPDF- use CSS in HTML content
var html = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 48pt;'>Text</span>";
// Gnostice PDFOne
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 48);
watermark.Font = font;
//IronPDF- use CSS in HTML content
var html = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 48pt;'>Text</span>";
Imports Gnostice.PDFOne
' Gnostice PDFOne
Dim font As New PDFFont(PDFStandardFont.Helvetica, 48)
watermark.Font = font
' IronPDF- use CSS in HTML content
Dim html As String = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 48pt;'>Text</span>"
頁面索引
Gnostice PDFOne 通常使用 1-indexed 頁面,而IronPDF則使用 0-indexed 頁面(標準 .NET 慣例):
// Gnostice PDFOne: May use 1-indexed
var page = doc.Pages[1]; // First page
// IronPDF: 0-indexed
var page = pdf.Pages[0]; // First page
// Gnostice PDFOne: May use 1-indexed
var page = doc.Pages[1]; // First page
// IronPDF: 0-indexed
var page = pdf.Pages[0]; // First page
' Gnostice PDFOne: May use 1-indexed
Dim page = doc.Pages(1) ' First page
' IronPDF: 0-indexed
Dim page = pdf.Pages(0) ' First page
現在可用的功能
從Gnostice PDFOne遷移到IronPDF之後,這些之前有問題或不可能的功能都變得可用: -外部 CSS:先前在Gnostice PDFOne中無法正常運作的樣式表現在可以正確渲染了。
- JavaScript 內容:先前缺少的動態內容現在已顯示。
- RTL 語言:阿拉伯語、希伯來語和其他從右到左的語言都能正常運作。
- CSS Grid 和 Flexbox:完全支援現代佈局技術 -數位簽名:可靠的 X509 憑證簽名
疑難排解
問題 1:PDFTextElement 未找到
問題:IronPDF中不存在 PDFTextElement。
解決方案:使用 HTML 內容或 TextStamper:
// For new documents - render HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Your text here</p>");
// For existing documents - use stampers
var stamper = new TextStamper() { Text = "Added Text" };
pdf.ApplyStamp(stamper);
// For new documents - render HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Your text here</p>");
// For existing documents - use stampers
var stamper = new TextStamper() { Text = "Added Text" };
pdf.ApplyStamp(stamper);
Imports IronPdf
' For new documents - render HTML
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<p>Your text here</p>")
' For existing documents - use stampers
Dim stamper As New TextStamper() With {.Text = "Added Text"}
pdf.ApplyStamp(stamper)
第 2 期:PDFFont 物件
問題:Gnostice PDFOne使用 PDFFont 物件;IronPDF使用 CSS。
解決方案:
// Gnostice PDFOne
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 12);
//IronPDF- use CSS
var html = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 12pt;'>Text</span>";
// Gnostice PDFOne
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 12);
//IronPDF- use CSS
var html = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 12pt;'>Text</span>";
' Gnostice PDFOne
Dim font As New PDFFont(PDFStandardFont.Helvetica, 12)
' IronPDF- use CSS
Dim html = "<span style='font-family: Helvetica, Arial, sans-serif; font-size: 12pt;'>Text</span>"
問題 3:找不到 DocExporter
問題:IronPDF中不存在 DocExporter 類別。
解決方案:使用 ChromePdfRenderer:
// Gnostice PDFOne
DocExporter exporter = new DocExporter();
exporter.Export(doc, "output.pdf", DocumentFormat.PDF);
// IronPDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("input.html");
pdf.SaveAs("output.pdf");
// Gnostice PDFOne
DocExporter exporter = new DocExporter();
exporter.Export(doc, "output.pdf", DocumentFormat.PDF);
// IronPDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("input.html");
pdf.SaveAs("output.pdf");
' Gnostice PDFOne
Dim exporter As New DocExporter()
exporter.Export(doc, "output.pdf", DocumentFormat.PDF)
' IronPDF
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlFileAsPdf("input.html")
pdf.SaveAs("output.pdf")
第 4 期:記憶體改進
問題:Gnostice PDFOne報告有記憶體洩漏。
解決方案:IronPDF提供穩定的記憶體管理。 使用正確的處理模式:
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
// Process PDF
pdf.SaveAs("output.pdf");
} // Automatically disposed
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
// Process PDF
pdf.SaveAs("output.pdf");
} // Automatically disposed
Imports PdfDocument
Using pdf = PdfDocument.FromFile("large.pdf")
' Process PDF
pdf.SaveAs("output.pdf")
End Using
遷移清單
預遷移
- 清點程式碼庫中所有Gnostice PDFOne的使用情況
- 注意之前無法正常運作的功能(CSS、JS、RTL)-現在它們都能正常運作了!
- 文檔記憶體問題,用於比較測試
- 取得IronPDF許可證密鑰
- 在版本控制系統中建立遷移分支
程式碼遷移
- 移除Gnostice PDFOneNuGet 套件
- 安裝 IronPdf NuGet 套件:
dotnet add package IronPdf - 更新命名空間匯入
- 更換許可證密鑰設置
- 將
PDFDocument轉換為PdfDocument - 將
DocExporter轉換為ChromePdfRenderer - 將基於座標的繪圖替換為 HTML 戳記
- 將
PDFFont更新為 CSS 樣式 - 將
doc.Append()轉換為PdfDocument.Merge()
測試
- 測試 HTML 至 PDF 的轉換
- 驗證外部 CSS 現在有效
- 測試依賴 JavaScript 的內容
- 測試 RTL 語言(如有需要)
- 測試數位簽章(現已推出!)
- 測試 PDF 合併
- 測試浮水印
- 比較記憶體使用情況
後遷移
- 移除 Gnostic PDFOne 許可證
- 更新文件
- 移除針對Gnostice PDFOne限制的變通方案
- 訓練團隊使用IronPDFAPI

