跳至頁尾內容
影片

如何使用 IronPDF 在 C# 中平坦化 PDF 圖像

從Gnostice PDFOne遷移到IronPDF會將您的.NET PDF工作流程從基於座標的平台分裂方法轉變為統一的HTML/CSS驅動解決方案,完全支持現代網頁標準。 本指南提供了一個全面的、逐步的遷移路徑,消除了專業.NET開發人員圍繞CSS、JavaScript和記憶體穩定性的限制。

為什麼從Gnostice PDFOne遷移到IronPDF

Gnostice PDFOne的挑戰

Gnostice PDFOne和Document Studio .NET有記錄在案的限制,影響生產應用。 遺留的PDFOne.NET NuGet套件現在也已被淘汰(最後版本24.1.60,2024年7月1日),供應商將新工作指向Gnostice.DocumentStudio.*套件:

  1. 不支持外部CSS: Gnostice PDFOne的文件明確說明它不支持外部CSS樣式表——這是現代網頁到PDF轉換的基本要求。

  2. 不支持JavaScript執行:需要JavaScript的動態內容無法渲染,使得準確地轉換現代網頁應用成為不可能。

  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支持
圖像處理 已知問題 可靠

對於計劃採用.NET 10和C# 14的團隊,IronPDF提供了一個在所有.NET平台上都能一致工作的統一程式庫。


遷移複雜性評估

功能的預估努力程度

功能 遷移複雜性
載入/保存PDF 非常低
合併PDF 非常低
拆分PDF
文字提取
浮水印
頁眉/頁腳
HTML轉PDF
加密
表單欄位
數位簽名

您獲得的功能

遷移從Gnostice PDFOne到IronPDF後,以前無法實現的功能現在可用:

  • 外部CSS樣式表
  • JavaScript執行
  • 支持的RTL語言(阿拉伯語、希伯來語)
  • CSS Grid 和 Flexbox
  • 可靠的數位簽名
  • 更好的記憶體管理
  • 使用單一程式碼庫的跨平台支持

開始之前

前提條件

  1. .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" .
SHELL

NuGet包變更

# Remove Gnostice packages (PDFOne.NET is the legacy, deprecated package)
dotnet remove package PDFOne.NET
dotnet remove package Gnostice.DocumentStudio.WinForms
dotnet remove package Gnostice.DocumentStudio.WPF
dotnet remove package Gnostice.DocumentStudio.ASP
dotnet remove package Gnostice.DocumentStudio.ASP.Core
dotnet remove package Gnostice.DocumentStudio.Xamarin

# Install IronPDF
dotnet add package IronPdf
# Remove Gnostice packages (PDFOne.NET is the legacy, deprecated package)
dotnet remove package PDFOne.NET
dotnet remove package Gnostice.DocumentStudio.WinForms
dotnet remove package Gnostice.DocumentStudio.WPF
dotnet remove package Gnostice.DocumentStudio.ASP
dotnet remove package Gnostice.DocumentStudio.ASP.Core
dotnet remove package Gnostice.DocumentStudio.Xamarin

# Install IronPDF
dotnet add package IronPdf
SHELL

快速開始遷移

步驟1:更新授權配置

之前(Gnostice PDFOne):

//Gnostice PDFOnelicense is set via the static PDFOne class
Gnostice.PDFOne.PDFOne.LicenseKey = "YOUR-GNOSTICE-LICENSE";
//Gnostice PDFOnelicense is set via the static PDFOne class
Gnostice.PDFOne.PDFOne.LicenseKey = "YOUR-GNOSTICE-LICENSE";
Imports Gnostice.PDFOne

' Gnostice PDFOnelicense is set via the static PDFOne class
PDFOne.LicenseKey = "YOUR-GNOSTICE-LICENSE"
$vbLabelText   $csharpLabel

之後(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" }
$vbLabelText   $csharpLabel

步驟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
$vbLabelText   $csharpLabel

完整API參考

核心類映射

Gnostice PDFOne IronPDF 說明
PDFDocument PdfDocument 主PDF文件類
PDFPage PdfDocument.Pages[i] 頁面表示
PDFFont CSS 樣式 字體規範
PDFTextElement HTML 內容 文字內容
PDFImageElement HTML <img> 標籤 圖像內容
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 PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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 PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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
$vbLabelText   $csharpLabel

之後(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
$vbLabelText   $csharpLabel

差異顯著:Gnostice PDFOne無法直接轉換HTML到PDF——您必須手動建立文字元素並用坐標定位它們。 IronPDF的ChromePdfRenderer 提供直接的HTML渲染,完整的CSS3和JavaScript支持。 請參閱HTML到PDF文件以獲取更多渲染選項。

例2:合併PDF文件

之前(Gnostice PDFOne):

// NuGet: Install-Package PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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 PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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
$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(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
$vbLabelText   $csharpLabel

Gnostice PDFOne的方法需要建立新文件、打開它、分別載入源文件、附加每一個,並手動關閉所有三個文件。 IronPDF的靜態Merge 方法正確資源管理,僅需三行即可處理。 瞭解更多合併和拆分PDF的資訊。

範例3:將水印新增到PDF

之前(Gnostice PDFOne):

// NuGet: Install-Package PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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 PDFOne.NET (deprecated; vendor recommends Gnostice.DocumentStudio.WinForms)
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
$vbLabelText   $csharpLabel

之後(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
$vbLabelText   $csharpLabel

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
$vbLabelText   $csharpLabel

字體物件到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>"
$vbLabelText   $csharpLabel

頁面索引

Gnostice PDFOne經常使用1-索引頁面,而IronPDF使用0-索引(標準.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
$vbLabelText   $csharpLabel

現在可用的功能

從Gnostice PDFOne遷移到IronPDF之後,以前出現問題或無法實現的功能現在可用:

  • 外部CSS: 在Gnostice PDFOne中不起作用的樣式表現在渲染正確
  • JavaScript內容: 缺少的動態內容現在出現
  • RTL語言: 阿拉伯語、希伯來語和其他從右到左的語言正常工作
  • CSS Grid 和 Flexbox: 現代佈局技術得到充分支持
  • 數位簽名: 可靠的X509證書簽名

故障排除

問題1: PDFTextElement找不到

問題: PDFTextElement 在IronPDF中不存在。

解決方案: 使用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)
$vbLabelText   $csharpLabel

問題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>"
$vbLabelText   $csharpLabel

問題3: DocExporter找不到

問題: DocExporter 類在IronPDF中不存在。

解決方案: 使用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")
$vbLabelText   $csharpLabel

問題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
$vbLabelText   $csharpLabel

遷移檢查表

遷移前

  • 清點程式庫中Gnostice PDFOne的所有使用
  • 記下以前無法正常工作的功能(CSS, JS, RTL)—它們現在能正常工作!
  • 記錄記憶體問題以便對比測試
  • 獲得IronPDF授權金鑰
  • 在版本控制中建立遷移分支

程式碼遷移

  • 移除Gnostice PDFOne的NuGet套件
  • 安裝IronPDF NuGet套件:dotnet add package IronPdf
  • 更新命名空間導入
  • 替換授權金鑰設置
  • PDFDocument 轉換為PdfDocument
  • DocExporter 轉換為ChromePdfRenderer
  • 用HTML加蓋取代基於座標的繪圖
  • 更新PDFFont 至CSS樣式
  • doc.Append() 轉換為PdfDocument.Merge()

測試

  • 測試 HTML 到 PDF 的轉換
  • 驗證外部CSS現在可以工作
  • 測試依賴JavaScript的內容
  • 測試RTL語言(如果需要)
  • 測試數位簽名(現在可用!)
  • 測試PDF合併
  • 測試水印
  • 比較記憶體使用情況

遷移後

  • 移除Gnostice PDFOne的授權
  • 更新文件
  • 移除對Gnostice PDFOne限制的變通辦法
  • 培訓團隊使用IronPDF API

請注意Gnostice是其各自所有者的註冊商標。 本站與Gnostice Information Technologies無關,未獲其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,反映撰寫時公開可用的資訊。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

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