Jak przejść z GdPicture.NET SDK na IronPDF w języku C#
Przejście zGdPicture.NET SDKnaIronPDFoferuje programistom .NET ukierunkowane i usprawnione podejście do generowania plików PDF. Niniejszy przewodnik przedstawia kompleksową, krok po kroku ścieżkę migracji, która zastępuje złożone wzorce SDK do przetwarzania obrazów dokumentów nowoczesnymi interfejsami API przeznaczonymi specjalnie dla formatu PDF, zaprojektowanymi z myślą o współczesnym programowaniu w środowisku .NET.
Dlaczego warto przejść zGdPicture.NET SDKna IronPDF
Wyzwania związane z GdPicture.NET SDK
GdPicture.NET SDK (obecnie pod nową nazwą Nutrient) to kompleksowy zestaw SDK do przetwarzania obrazów dokumentów, który stawia kilka wyzwań przed programistami skupiającymi się na plikach PDF:
-
Zbyt rozbudowane rozwiązanie dla projektów opartych wyłącznie na plikach PDF:GdPicture.NET SDKto kompletna Suite do przetwarzania obrazów dokumentów, obejmująca OCR, rozpoznawanie BarCode, skanowanie i przetwarzanie obrazów. Jeśli potrzebujesz tylko funkcji PDF, płacisz za funkcje, z których nigdy nie skorzystasz.
-
Złożony system licencjonowania: wiele poziomów produktów (GdPicture.NET 14, GdPicture.API, Ultimate, Professional) z mylącymi kombinacjami numerów katalogowych (SKU) i wymogąmi dotyczącymi rocznej subskrypcji.
-
Ceny dla przedsiębiorstw: Koszt licencji zaczyna się od 2999 USD za samą wtyczkę PDF, a w przypadku wersji Ultimate wynosi ponad 10 000 USD. Licencjonowanie na programistę powoduje znaczne obciążenie dla rozwijających się zespołów.
-
Stroma krzywa uczenia się: API zostało zaprojektowane w oparciu o koncepcje obrazówania dokumentów, a nie nowoczesne wzorce .NET. Metody takie jak
LicenseManager.RegisterKEY(), sprawdzanie enumówGdPictureStatusoraz strony indeksowane od 1 wydają się przestarzałe w porównaniu ze współczesnymi konwencjami języka C#. -
Wzorzec kodu statusu: Każda operacja zwraca wyliczenie
GdPictureStatus, które należy sprawdzić — w przypadku błędów nie są zgłaszane wyjątki, co sprawia, że obsługa błędów jest rozbudowana i powtarzalna. -
Ręczne zarządzanie zasobami: Wymaga wyraźnych wywołań
Dispose()lubRelease(). SDK nie stosuje się ściśle do standardowych wzorców usuwania w .NET Standard. -
Uzależnienie od wersji: Przestrzeń nazw
GdPicture14zawiera numer wersji, co sprawia, że poważne aktualizacje wersji wymagają zmian przestrzeni nazw w całym kodzie źródłowym. - Zamieszanie związane ze zmianą marki: Niedawna zmiana marki na "Nutrient" powoduje fragmentację dokumentacji między gdpicture.com a nutrient.io, co komplikuje wsparcie techniczne i naukę.
PorównanieGdPicture.NET SDKi IronPDF
| Aspekt | GdPicture.NET SDK | IronPDF |
|---|---|---|
| Skup się na | Suite do przetwarzania obrazów dokumentów (zbyt rozbudowana jak na PDF) | Biblioteka przeznaczona dla formatu PDF |
| Ceny | 2 999–10 000+ USD – poziom Enterprise | Konkurencyjny, skalowalny wraz z rozwojem firmy |
| Styl API | Kody statusu, zarządzanie ręczne | Wyjątki, IDisposable, nowoczesny .NET |
| Krzywa uczenia się | Steep (koncepcje SDK do przetwarzania obrazów) | Prosty (znajomość HTML/CSS) |
| Renderowanie HTML | Podstawowy, wewnętrzny silnik | Najnowsza wersja Chromium z CSS3/JS |
| Indeksowanie stron | 1-indeksowane | 0-indeksowane (standard .NET Standard) |
| Bezpieczeństwo wątków | Wymagana ręczna synchronizacja | Zabezpieczone przed współbieżnością już w fazie projektowania |
| Przestrzeń nazw | Specyficzne dla wersji (GdPicture14) |
Stable (IronPdf) |
Dla zespołów planujących wdrożenie .NET 10 i C# 14 w latach 2025 i 2026,IronPDFzapewnia przyszłościową podstawę, która jest zgodna z nowoczesnymi wzorcami i konwencjami .NET.
Ocena złożoności migracji
Szacowany nakład pracy według funkcji
| Funkcja | Złożoność migracji |
|---|---|
| HTML do PDF | Low |
| URL do pliku PDF | Low |
| Łączenie plików PDF | Low |
| Podział plików PDF | Low |
| Znaki wodne | Low |
| Ekstrakcja tekstu | Low |
| Ochrona hasłem | Medium |
| Pola formularza | Medium |
| Podpisy cyfrowe | Średnio-wysoki |
| OCR | High |
| Rozpoznawanie kodów kreskowych | Nie dotyczy |
Macierz decyzji dotyczących migracji
| Twoja sytuacja | Zalecenie |
|---|---|
| Operacje dostępne wyłącznie w formacie PDF | Migracja — znaczne uproszczenie i oszczędność kosztów |
| Intensywne wykorzystanieOCR | Rozważ IronOCR jako produkt towarzyszący |
| BarCode/skanowanie | ZachowajGdPicture.NET SDKdla tych funkcji, użyjIronPDFdla plików PDF |
| Pełne obrazówanie dokumentów | Oceń, czy faktycznie korzystasz ze wszystkich funkcji |
Zanim zaczniesz
Wymagania wstępne
- Wersja .NET:IronPDFobsługuje .NET Framework 4.6.2+ oraz .NET Core 2.0+ / .NET 5/6/7/8/9+
- Klucz licencyjny: Uzyskaj klucz licencyjnyIronPDFna stronie ironpdf.com
- Kopia zapasowa: Utwórz gałąź do prac migracyjnych
Zidentyfikuj wszystkie przypadki użycia GdPicture.NET SDK
# Find allGdPicture.NET SDKreferences in your codebase
grep -r "GdPicture14\|GdPicturePDF\|GdPictureDocumentConverter\|GdPictureStatus\|LicenseManager\.RegisterKEY" --include="*.cs" .
# Find all GdPicture package references
grep -r "GdPicture" --include="*.csproj" .
# Find allGdPicture.NET SDKreferences in your codebase
grep -r "GdPicture14\|GdPicturePDF\|GdPictureDocumentConverter\|GdPictureStatus\|LicenseManager\.RegisterKEY" --include="*.cs" .
# Find all GdPicture package references
grep -r "GdPicture" --include="*.csproj" .
Zmiany w pakiecie NuGet
# RemoveGdPicture.NET SDKpackages
dotnet remove package GdPicture.NET.14
dotnet remove package GdPicture.NET.14.API
dotnet remove package GdPicture
dotnet remove package GdPicture.API
# Install IronPDF
dotnet add package IronPdf
# RemoveGdPicture.NET SDKpackages
dotnet remove package GdPicture.NET.14
dotnet remove package GdPicture.NET.14.API
dotnet remove package GdPicture
dotnet remove package GdPicture.API
# Install IronPDF
dotnet add package IronPdf
Szybki start – migracja
Krok 1: Zaktualizuj konfigurację licencji
Przed (GdPicture.NET SDK):
// Must be called before anyGdPicture.NET SDKoperations
LicenseManager.RegisterKEY("YOUR-GDPICTURE-LICENSE-KEY");
// Must be called before anyGdPicture.NET SDKoperations
LicenseManager.RegisterKEY("YOUR-GDPICTURE-LICENSE-KEY");
' Must be called before any GdPicture.NET SDK operations
LicenseManager.RegisterKEY("YOUR-GDPICTURE-LICENSE-KEY")
Po (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" }
Krok 2: Zaktualizuj importy przestrzeni nazw
// Before (GdPicture.NET SDK)
using GdPicture14;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
// Before (GdPicture.NET SDK)
using GdPicture14;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Editing
Krok 3: Podstawowy wzorzec konwersji
Najważniejszą zmianą w migracjiGdPicture.NET SDKjest wyeliminowanie rozbudowanego schematu sprawdzania stanu:
Przed (GdPicture.NET SDK):
using GdPicture14;
LicenseManager.RegisterKEY("LICENSE-KEY");
using (GdPictureDocumentConverter converter = new GdPictureDocumentConverter())
{
GdPictureStatus status = converter.LoadFromHTMLString("<h1>Hello World</h1>");
if (status == GdPictureStatus.OK)
{
status = converter.SaveAsPDF("output.pdf");
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"Error: {status}");
}
}
else
{
Console.WriteLine($"Load error: {status}");
}
}
using GdPicture14;
LicenseManager.RegisterKEY("LICENSE-KEY");
using (GdPictureDocumentConverter converter = new GdPictureDocumentConverter())
{
GdPictureStatus status = converter.LoadFromHTMLString("<h1>Hello World</h1>");
if (status == GdPictureStatus.OK)
{
status = converter.SaveAsPDF("output.pdf");
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"Error: {status}");
}
}
else
{
Console.WriteLine($"Load error: {status}");
}
}
Imports GdPicture14
LicenseManager.RegisterKEY("LICENSE-KEY")
Using converter As New GdPictureDocumentConverter()
Dim status As GdPictureStatus = converter.LoadFromHTMLString("<h1>Hello World</h1>")
If status = GdPictureStatus.OK Then
status = converter.SaveAsPDF("output.pdf")
If status <> GdPictureStatus.OK Then
Console.WriteLine($"Error: {status}")
End If
Else
Console.WriteLine($"Load error: {status}")
End If
End Using
Po (IronPDF):
using IronPdf;
IronPdf.License.LicenseKey = "LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
using IronPdf;
IronPdf.License.LicenseKey = "LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
Imports IronPdf
IronPdf.License.LicenseKey = "LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
pdf.SaveAs("output.pdf")
Kluczowe różnice:
- Brak sprawdzania stanu — wyjątki w przypadku błędów
- Nie jest wymagane jawne usuwanie renderera
- Nowoczesny, płynny interfejs API
- Renderowanie oparte na silniku Chromium zapewniające lepszą obsługę HTML/CSS
Kompletna dokumentacija API
Mapowanie przestrzeni nazw
| GdPicture.NET SDK | IronPDF |
|---|---|
GdPicture14 |
IronPdf |
GdPicture14.PDF |
IronPdf |
GdPicture14.Imaging |
Nie dotyczy (nie dotyczy) |
Mapowanie klas podstawowych
| GdPicture.NET SDK | IronPDF | Opis |
|---|---|---|
GdPicturePDF |
PdfDocument |
Główna klasa dokumentu PDF |
GdPictureDocumentConverter |
ChromePdfRenderer |
Konwersja HTML/URL do formatu PDF |
LicenseManager |
IronPdf.License |
Zarządzanie licencjami |
GdPictureStatus |
Wyjątki | Obsługa błędów |
Metody ładowania dokumentów
| GdPicture.NET SDK | IronPDF |
|---|---|
pdf.LoadFromFile(path, loadInMemory) |
PdfDocument.FromFile(path) |
pdf.LoadFromFile(path, password, loadInMemory) |
PdfDocument.FromFile(path, password) |
converter.LoadFromHTMLString(html) |
renderer.RenderHtmlAsPdf(html) |
converter.LoadFromURL(url) |
renderer.RenderUrlAsPdf(url) |
Operacje na stronach
| GdPicture.NET SDK | IronPDF |
|---|---|
pdf.GetPageCount() |
pdf.PageCount |
pdf.SelectPage(pageNo) |
pdf.Pages[index] |
pdf.GetPageWidth() |
pdf.Pages[i].Width |
pdf.GetPageHeight() |
pdf.Pages[i].Height |
Operacje scalania i dzielenia
| GdPicture.NET SDK | IronPDF |
|---|---|
pdf1.MergePages(pdf2) |
PdfDocument.Merge(pdf1, pdf2) |
pdf.ExtractPages(start, end) |
pdf.CopyPages(indices) |
Operacje związane z znakami wodnymi
| GdPicture.NET SDK | IronPDF |
|---|---|
pdf.DrawText(...) pętla |
pdf.ApplyWatermark(html) |
pdf.SetTextColor(color) |
Stylizacja CSS |
pdf.SetTextSize(size) |
Stylizacja CSS |
Przykłady migracji kodu
Przykład 1: Konwersja HTML do PDF
Przed (GdPicture.NET SDK):
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
class Program
{
static void Main()
{
using (GdPictureDocumentConverter converter = new GdPictureDocumentConverter())
{
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
GdPictureStatus status = converter.LoadFromHTMLString(htmlContent);
if (status == GdPictureStatus.OK)
{
converter.SaveAsPDF("output.pdf");
}
}
}
}
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
class Program
{
static void Main()
{
using (GdPictureDocumentConverter converter = new GdPictureDocumentConverter())
{
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
GdPictureStatus status = converter.LoadFromHTMLString(htmlContent);
if (status == GdPictureStatus.OK)
{
converter.SaveAsPDF("output.pdf");
}
}
}
}
Imports GdPicture14
Imports System
Class Program
Shared Sub Main()
Using converter As New GdPictureDocumentConverter()
Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
Dim status As GdPictureStatus = converter.LoadFromHTMLString(htmlContent)
If status = GdPictureStatus.OK Then
converter.SaveAsPDF("output.pdf")
End If
End Using
End Sub
End Class
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
End Sub
End Class
ChromePdfRenderer firmyIronPDFwykorzystuje nowoczesny silnik Chromium do dokładnego renderowania HTML/CSS, eliminując potrzebę sprawdzania kodów statusu. Aby uzyskać więcej informacji na temat opcji renderowania HTML, zapoznaj się z dokumentacją dotyczącą konwersji HTML do PDF.
Przykład 2: Scalanie wielu plików PDF
Przed (GdPicture.NET SDK):
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
class Program
{
static void Main()
{
using (GdPicturePDF pdf1 = new GdPicturePDF())
using (GdPicturePDF pdf2 = new GdPicturePDF())
{
pdf1.LoadFromFile("document1.pdf", false);
pdf2.LoadFromFile("document2.pdf", false);
pdf1.MergePages(pdf2);
pdf1.SaveToFile("merged.pdf");
}
}
}
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
class Program
{
static void Main()
{
using (GdPicturePDF pdf1 = new GdPicturePDF())
using (GdPicturePDF pdf2 = new GdPicturePDF())
{
pdf1.LoadFromFile("document1.pdf", false);
pdf2.LoadFromFile("document2.pdf", false);
pdf1.MergePages(pdf2);
pdf1.SaveToFile("merged.pdf");
}
}
}
Imports GdPicture14
Imports System
Class Program
Shared Sub Main()
Using pdf1 As New GdPicturePDF(), pdf2 As New GdPicturePDF()
pdf1.LoadFromFile("document1.pdf", False)
pdf2.LoadFromFile("document2.pdf", False)
pdf1.MergePages(pdf2)
pdf1.SaveToFile("merged.pdf")
End Using
End Sub
End Class
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
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");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
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");
}
}
Imports IronPdf
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(New List(Of PdfDocument) From {pdf1, pdf2})
merged.SaveAs("merged.pdf")
End Sub
End Class
Metoda statyczna Merge bibliotekiIronPDFprzyjmuje listę dokumentów, co ułatwia łączenie wielu plików PDF w ramach jednej operacji. Dowiedz się więcej o łączeniu i dzieleniu plików PDF.
Przykład 3: Dodaj znak wodny do wszystkich stron
Przed (GdPicture.NET SDK):
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
using System.Drawing;
class Program
{
static void Main()
{
using (GdPicturePDF pdf = new GdPicturePDF())
{
pdf.LoadFromFile("input.pdf", false);
for (int i = 1; i <= pdf.GetPageCount(); i++)
{
pdf.SelectPage(i);
pdf.SetTextColor(Color.Red);
pdf.SetTextSize(48);
pdf.DrawText("CONFIDENTIAL", 200, 400);
}
pdf.SaveToFile("watermarked.pdf");
}
}
}
// NuGet: Install-Package GdPicture.NET
using GdPicture14;
using System;
using System.Drawing;
class Program
{
static void Main()
{
using (GdPicturePDF pdf = new GdPicturePDF())
{
pdf.LoadFromFile("input.pdf", false);
for (int i = 1; i <= pdf.GetPageCount(); i++)
{
pdf.SelectPage(i);
pdf.SetTextColor(Color.Red);
pdf.SetTextSize(48);
pdf.DrawText("CONFIDENTIAL", 200, 400);
}
pdf.SaveToFile("watermarked.pdf");
}
}
}
Imports GdPicture14
Imports System
Imports System.Drawing
Module Program
Sub Main()
Using pdf As New GdPicturePDF()
pdf.LoadFromFile("input.pdf", False)
For i As Integer = 1 To pdf.GetPageCount()
pdf.SelectPage(i)
pdf.SetTextColor(Color.Red)
pdf.SetTextSize(48)
pdf.DrawText("CONFIDENTIAL", 200, 400)
Next
pdf.SaveToFile("watermarked.pdf")
End Using
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark("<h1 style='color:red;'>CONFIDENTIAL</h1>", 50, VerticalAlignment.Middle, HorizontalAlignment.Center);
pdf.SaveAs("watermarked.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark("<h1 style='color:red;'>CONFIDENTIAL</h1>", 50, VerticalAlignment.Middle, HorizontalAlignment.Center);
pdf.SaveAs("watermarked.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
pdf.ApplyWatermark("<h1 style='color:red;'>CONFIDENTIAL</h1>", 50, VerticalAlignment.Middle, HorizontalAlignment.Center)
pdf.SaveAs("watermarked.pdf")
End Sub
End Class
MigracjaGdPicture.NET SDKz rysowania tekstu opartego na współrzędnych do znakowania wodnego opartego na HTML znacznie upraszcza kod. Metoda ApplyWatermark firmyIronPDFwykorzystuje stylizację HTML/CSS, eliminując potrzebę ręcznego iterowania stron i obliczania współrzędnych. Aby zapoznać się z dodatkowymi opcjami, zapoznaj się z pełną dokumentacją dotyczącą znaków wodnych.
Przykład 4: Ochrona hasłem i bezpieczeństwo
Przed (GdPicture.NET SDK):
using GdPicture14;
class Program
{
static void Main()
{
LicenseManager.RegisterKEY("LICENSE-KEY");
using (GdPicturePDF pdf = new GdPicturePDF())
{
GdPictureStatus status = pdf.LoadFromFile("document.pdf", false);
if (status != GdPictureStatus.OK) return;
// Save with encryption - many boolean parameters
status = pdf.SaveToFile(
"protected.pdf",
PdfEncryption.PdfEncryption256BitAES,
"user123", // User password
"owner456", // Owner password
true, // Can print
false, // Cannot copy
false, // Cannot modify
false, // Cannot add notes
true, // Can fill forms
false, // Cannot extract
false, // Cannot assemble
true // Can print high quality
);
}
}
}
using GdPicture14;
class Program
{
static void Main()
{
LicenseManager.RegisterKEY("LICENSE-KEY");
using (GdPicturePDF pdf = new GdPicturePDF())
{
GdPictureStatus status = pdf.LoadFromFile("document.pdf", false);
if (status != GdPictureStatus.OK) return;
// Save with encryption - many boolean parameters
status = pdf.SaveToFile(
"protected.pdf",
PdfEncryption.PdfEncryption256BitAES,
"user123", // User password
"owner456", // Owner password
true, // Can print
false, // Cannot copy
false, // Cannot modify
false, // Cannot add notes
true, // Can fill forms
false, // Cannot extract
false, // Cannot assemble
true // Can print high quality
);
}
}
}
Imports GdPicture14
Class Program
Shared Sub Main()
LicenseManager.RegisterKEY("LICENSE-KEY")
Using pdf As New GdPicturePDF()
Dim status As GdPictureStatus = pdf.LoadFromFile("document.pdf", False)
If status <> GdPictureStatus.OK Then Return
' Save with encryption - many boolean parameters
status = pdf.SaveToFile(
"protected.pdf",
PdfEncryption.PdfEncryption256BitAES,
"user123", ' User password
"owner456", ' Owner password
True, ' Can print
False, ' Cannot copy
False, ' Cannot modify
False, ' Cannot add notes
True, ' Can fill forms
False, ' Cannot extract
False, ' Cannot assemble
True ' Can print high quality
)
End Using
End Sub
End Class
Po (IronPDF):
using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Configure security settings with clear property names
pdf.SecuritySettings.OwnerPassword = "owner456";
pdf.SecuritySettings.UserPassword = "user123";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;
pdf.SaveAs("protected.pdf");
}
}
using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Configure security settings with clear property names
pdf.SecuritySettings.OwnerPassword = "owner456";
pdf.SecuritySettings.UserPassword = "user123";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;
pdf.SaveAs("protected.pdf");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Configure security settings with clear property names
pdf.SecuritySettings.OwnerPassword = "owner456"
pdf.SecuritySettings.UserPassword = "user123"
' Set permissions
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserFormData = True
pdf.SaveAs("protected.pdf")
End Sub
End Class
Właściwość SecuritySettings wIronPDFzapewnia nazwane, samodokumentujące się właściwości zamiast pozycyjnych parametrów logicznych.
Ważne uwagi dotyczące migracji
Konwersja indeksowania stron
Jedną z najważniejszych zmian w migracjiGdPicture.NET SDKjest różnica w indeksowaniu stron:
// GdPicture.NET SDK: 1-indeksowane pages
for (int i = 1; i <= pdf.GetPageCount(); i++)
{
pdf.SelectPage(i);
// process page
}
// IronPDF: 0-indexed pages (standard .NET)
for (int i = 0; i < pdf.PageCount; i++)
{
var page = pdf.Pages[i];
// process page
}
// GdPicture.NET SDK: 1-indeksowane pages
for (int i = 1; i <= pdf.GetPageCount(); i++)
{
pdf.SelectPage(i);
// process page
}
// IronPDF: 0-indexed pages (standard .NET)
for (int i = 0; i < pdf.PageCount; i++)
{
var page = pdf.Pages[i];
// process page
}
' GdPicture.NET SDK: 1-indexed pages
For i As Integer = 1 To pdf.GetPageCount()
pdf.SelectPage(i)
' process page
Next
' IronPDF: 0-indexed pages (standard .NET)
For i As Integer = 0 To pdf.PageCount - 1
Dim page = pdf.Pages(i)
' process page
Next
Kody statusu a wyjątki
Zastąp rozbudowane sprawdzanie statusu standardowym try-catch:
// GdPicture.NET SDK
GdPictureStatus status = converter.LoadFromHTMLString(html);
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"Error: {status}");
return;
}
// IronPDF
try
{
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
// GdPicture.NET SDK
GdPictureStatus status = converter.LoadFromHTMLString(html);
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"Error: {status}");
return;
}
// IronPDF
try
{
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
' GdPicture.NET SDK
Dim status As GdPictureStatus = converter.LoadFromHTMLString(html)
If status <> GdPictureStatus.OK Then
Console.WriteLine($"Error: {status}")
Return
End If
' IronPDF
Try
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Catch ex As Exception
Console.WriteLine($"Error: {ex.Message}")
End Try
Przeliczanie jednostek
GdPicture.NET SDK używa cali jako jednostki miary dla marginesów;IronPDFużywa milimetrów:
// GdPicture.NET SDK: 0.5 inches margin
converter.HtmlSetMargins(0.5f, 0.5f, 0.5f, 0.5f);
// IronPDF: 0.5 inches = 12.7 mm
renderer.RenderingOptions.MarginTop = 12.7;
renderer.RenderingOptions.MarginBottom = 12.7;
renderer.RenderingOptions.MarginLeft = 12.7;
renderer.RenderingOptions.MarginRight = 12.7;
// GdPicture.NET SDK: 0.5 inches margin
converter.HtmlSetMargins(0.5f, 0.5f, 0.5f, 0.5f);
// IronPDF: 0.5 inches = 12.7 mm
renderer.RenderingOptions.MarginTop = 12.7;
renderer.RenderingOptions.MarginBottom = 12.7;
renderer.RenderingOptions.MarginLeft = 12.7;
renderer.RenderingOptions.MarginRight = 12.7;
' GdPicture.NET SDK: 0.5 inches margin
converter.HtmlSetMargins(0.5F, 0.5F, 0.5F, 0.5F)
' IronPDF: 0.5 inches = 12.7 mm
renderer.RenderingOptions.MarginTop = 12.7
renderer.RenderingOptions.MarginBottom = 12.7
renderer.RenderingOptions.MarginLeft = 12.7
renderer.RenderingOptions.MarginRight = 12.7
Formuła konwersji: millimeters = inches × 25.4
Bezpieczeństwo wątków
GdPicture.NET SDK wymaga ręcznej synchronizacji w przypadku operacji wykonywanych jednocześnie. ChromePdfRenderer firmyIronPDFjest z założenia bezpieczny dla wątków, co upraszcza wielowątkowe generowanie plików PDF.
Kwestie związane z wydajnością
Ponowne użycie ChromePdfRenderer
Aby uzyskać optymalną wydajność, należy ponownie wykorzystać instancję renderera:
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}
Imports System
Public Class PdfService
Private Shared ReadOnly _renderer As New ChromePdfRenderer()
Public Function Generate(html As String) As Byte()
Return _renderer.RenderHtmlAsPdf(html).BinaryData
End Function
' BAD - Creates new instance each time
Public Function GenerateBad(html As String) As Byte()
Dim renderer As New ChromePdfRenderer() ' Wasteful
Return renderer.RenderHtmlAsPdf(html).BinaryData
End Function
End Class
Właściwa utylizacja zasobów
// Use using statements for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automatically
// Use using statements for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automatically
Imports PdfDocument
' Use Using blocks for automatic cleanup
Using pdf = PdfDocument.FromFile("large.pdf")
Dim text As String = pdf.ExtractAllText()
End Using ' pdf is disposed automatically
Lista kontrolna migracji
Przed migracją
- Sporządź spis wszystkich miejsc użyciaGdPicture.NET SDKw kodzie źródłowym
- Określ, które funkcje są faktycznie używane (PDF vsOCRvs BarCode)
- Sprawdź, czy potrzebne są funkcje OCR/kodów kreskowych (rozważ IronOCR/IronBarcode)
- Przejrzyj aktualne warunki licencji i porównaj je z cennikiem IronPDF
- Uzyskaj klucz licencyjny IronPDF
- Utwórz gałąź migracji w systemie kontroli wersji
Migracja kodu
- Usuń pakiety NuGet GdPicture.NET SDK:
dotnet remove package GdPicture.NET - Zainstaluj pakiet IronPdf NuGet:
dotnet add package IronPdf - Zaktualizuj importy przestrzeni nazw (
GdPicture14→IronPdf) - Zastąp
LicenseManager.RegisterKEY()przezIronPdf.License.LicenseKey - Przekształć sprawdzanie kodów statusu w bloki try-catch
- Aktualizacja indeksowania stron (indeksowanie 1 → indeksowanie 0)
- Zastąp
GdPicturePDFprzezPdfDocument - Zastąp
GdPictureDocumentConverterprzezChromePdfRenderer - Konwersja tekstu opartego na współrzędnych na znaczniki HTML
- Zaktualizuj przeliczniki jednostek (cale → milimetry)
Testowanie
- Przeprowadź testy jednostkowe wszystkich ścieżek generowania plików PDF
- Sprawdź, czy jakość renderowania HTML jest co najmniej taka sama jak
- Przetestuj wszystkie scenariusze związane z bezpieczeństwem/szyfrowaniem
- Sprawdź działanie funkcji wypełniania formularzy
- Testowanie operacji scalania/dzielenia
- Sprawdź wygląd znaku wodnego
- Ścieżki krytyczne testów wydajności
Po migracji
- Usuń pliki licencyjne/klucze GdPicture.NET SDK
- Aktualizacja dokumentacji
- Przeprowadź szkolenie zespołu w zakresie wzorców API IronPDF
- Monitoruj produkcję pod kątem wszelkich problemów

