Jak przeprowadzić migrację z GemBox PDF do IronPDF w języku C#
Migracja z GemBox.Pdf do IronPDF przekształca Twój przepływ przemiany PDF .NET z opartej na współrzędnych, programistycznej konstrukcji dokumentów na nowoczesne renderowanie oparte na HTML/CSS. Ten przewodnik zapewnia wszechstronną, krok po kroku ścieżkę migracji, która usuwa ograniczenie bezpłatnego trybu 2-stronicowego i upraszcza tworzenie dokumentów dla profesjonalnych deweloperów .NET.
Dlaczego migrować z GemBox.Pdf do IronPDF
Wyzwania GemBox.Pdf
GemBox.Pdf to zdolny komponent PDF .NET, ale ma ograniczenia, które warto rozważyć w rzeczywistym rozwoju:
-
Limit darmowego trybu do 2 stron: Darmowa wersja zgłasza
FreeLimitReachedExceptionprzy ładowaniu lub zapisywaniu PDF przekraczającego 2 strony, więc wszystko poza jednostronicowym paragonem lub dwustronicową fakturą wymaga płatnej licencji. (Source: gemboxsoftware.com/pdf/free-version.) -
Brak konwersji HTML do PDF: GemBox.Pdf nie potrafi renderować HTML —
PdfDocument.Loadotwiera tylko istniejące pliki PDF. Aby przekonwertować HTML na PDF, musisz kupić osobny produkt GemBox.Document (inne SKU, inna licencja). -
Układ oparty na współrzędnych: GemBox.Pdf to niskopoziomowe API dla strumienia treści PDF. Aby umieścić tekst, obliczasz jednostki X/Y w przestrzeni użytkownika PDF i wywołujesz
page.Content.DrawText(formattedText, new PdfPoint(x, y)). Nie ma układu przepływu. -
Office-to-PDF wymaga innych SKU: Word→PDF potrzebuje GemBox.Document, Excel→PDF potrzebuje GemBox.Spreadsheet, każdy licencjonowany osobno; GemBox.Bundle pokrywa je wszystkie, ale kosztuje więcej.
-
Wyłącznie programowo: Każda zmiana projektu wymaga zmian w kodzie. Dopasować odstępy? Przelicz współrzędne. Zmienić rozmiar czcionki? Dostosować pozycje Y poniżej.
-
Ceny z licencją komercyjną: Licencja na jednego dewelopera kosztuje 890 $ (odnowienie 534 $), mały zespół (10 deweloperów) 4 450 $, duży zespół (50 deweloperów) 13 350 $. (Źródło: gemboxsoftware.com/pdf/pricing.)
- Krzywa nauki dla projektowania: Deweloperzy muszą myśleć w kategoriach współrzędnych, a nie przepływu dokumentów, co sprawia, że proste zadania jak "dodaj akapit" są zaskakująco skomplikowane.
Porównanie GemBox.Pdf vs IronPDF
| Aspekt | GemBox.Pdf | IronPDF |
|---|---|---|
| Ograniczenia wersji darmowej | 2-stronicowe maximum (FreeLimitReachedException) | Tylko znak wodny, brak limitu stron |
| HTML do PDF | Nieobsługiwane (wymaga GemBox.Document) | Pełny silnik Chromium |
| Word/Excel → PDF | Oddzielne SKU (GemBox.Document / GemBox.Spreadsheet) | Renderuj za pośrednictwem pipeline HTML |
| Podejście do układu graficznego | Ręczne, oparte na współrzędnych | Układ HTML/CSS |
| Nowoczesny CSS | Nie dotyczy | Flexbox, Grid, animacje CSS3 |
| Obsługa JavaScript | Nie dotyczy | Pełne wykonywanie kodu JavaScript |
| Zmiany w projekcie | Przelicz współrzędne | Edytuj HTML/CSS |
| Krzywa uczenia się | Układ współrzędnych PDF | HTML/CSS (znajomość sieci) |
IronPDF wykorzystuje znane technologie webowe do generowania PDF-ów na nowoczesnym .NET.
Ocena złożoności migracji
Szacowany nakład pracy według funkcji
| Funkcja | Złożoność migracji |
|---|---|
| Wczytywanie/zapisywanie plików PDF | Bardzo niski |
| Łączenie plików PDF | Bardzo niski |
| Podział plików PDF | Niski |
| Ekstrakcja tekstu | Bardzo niski |
| Dodaj tekst | Medium |
| Tabele | Niski |
| Obrazy | Niski |
| Znaki wodne | Niski |
| Ochrona hasłem | Medium |
| Pola formularza | Medium |
Zmiana paradygmatu
Największą zmianą podczas migracji GemBox.Pdf jest przejście z układu opartego na współrzędnych do układu HTML/CSS:
GemBox.Pdf: "Rysuj tekst na pozycji (100, 700)"
IronPDF: "Renderuj ten kod HTML ze stylami CSS"
Ta zmiana paradygmatu jest zazwyczaj łatwiejsza dla programistów zaznajomionych z technologiami internetowymi, ale wymaga innego podejścia do plików PDF.
Zanim zaczniesz
Wymagania wstępne
- Wersja .NET:IronPDF obsługuje .NET Framework 4.6.2+ i .NET Core 2.0+ / .NET 5+
- Klucz licencyjny: Uzyskaj klucz licencyjny IronPDF na stronie ironpdf.com
- Kopia zapasowa: Utwórz gałąź do prac migracyjnych
- Znajomość HTML/CSS: Podstawowa znajomość jest pomocna, ale nie jest wymagana
Zidentyfikuj wszystkie użycia GemBox.Pdf
# Find all GemBox.Pdf references
grep -r "GemBox\.Pdf\|PdfDocument\|PdfPage\|PdfFormattedText\|ComponentInfo\.SetLicense" --include="*.cs" .
# Find package references
grep -r "GemBox\.Pdf" --include="*.csproj" .
# Find all GemBox.Pdf references
grep -r "GemBox\.Pdf\|PdfDocument\|PdfPage\|PdfFormattedText\|ComponentInfo\.SetLicense" --include="*.cs" .
# Find package references
grep -r "GemBox\.Pdf" --include="*.csproj" .
Zmiany w pakiecie NuGet
# Remove GemBox.Pdf
dotnet remove package GemBox.Pdf
# Install IronPDF
dotnet add package IronPdf
# Remove GemBox.Pdf
dotnet remove package GemBox.Pdf
# Install IronPDF
dotnet add package IronPdf
Szybki start – migracja
Krok 1: Zaktualizuj konfigurację licencji
Before (GemBox.Pdf):
// Must call before any GemBox.Pdf operations
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Or for professional:
ComponentInfo.SetLicense("YOUR-PROFESSIONAL-LICENSE");
// Must call before any GemBox.Pdf operations
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Or for professional:
ComponentInfo.SetLicense("YOUR-PROFESSIONAL-LICENSE");
' Must call before any GemBox.Pdf operations
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' Or for professional:
ComponentInfo.SetLicense("YOUR-PROFESSIONAL-LICENSE")
Po (IronPDF):
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
Imports IronPdf
' Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
' Or in appsettings.json:
' { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
Krok 2: Zaktualizuj importy przestrzeni nazw
// Before (GemBox.Pdf)
using GemBox.Pdf;
using GemBox.Pdf.Content;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
// Before (GemBox.Pdf)
using GemBox.Pdf;
using GemBox.Pdf.Content;
// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Editing
Krok 3: Podstawowy wzorzec konwersji
Before (GemBox.Pdf):
using GemBox.Pdf;
using GemBox.Pdf.Content;
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
// PdfFormattedText has no Text property; use Append/AppendLine.
var formattedText = new PdfFormattedText();
formattedText.FontSize = 24;
formattedText.Append("Hello World");
page.Content.DrawText(formattedText, new PdfPoint(100, 700));
document.Save("output.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
// PdfFormattedText has no Text property; use Append/AppendLine.
var formattedText = new PdfFormattedText();
formattedText.FontSize = 24;
formattedText.Append("Hello World");
page.Content.DrawText(formattedText, new PdfPoint(100, 700));
document.Save("output.pdf");
}
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document As New PdfDocument()
Dim page = document.Pages.Add()
' PdfFormattedText has no Text property; use Append/AppendLine.
Dim formattedText As New PdfFormattedText()
formattedText.FontSize = 24
formattedText.Append("Hello World")
page.Content.DrawText(formattedText, New PdfPoint(100, 700))
document.Save("output.pdf")
End Using
Po (IronPDF):
using IronPdf;
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1 style='font-size:24px;'>Hello World</h1>");
pdf.SaveAs("output.pdf");
using IronPdf;
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1 style='font-size:24px;'>Hello World</h1>");
pdf.SaveAs("output.pdf");
Imports IronPdf
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1 style='font-size:24px;'>Hello World</h1>")
pdf.SaveAs("output.pdf")
Kluczowe różnice:
- Nie są wymagane obliczenia współrzędnych
- HTML/CSS zamiast układu programowego
- Brak pułapu w trybie wolnym na 2-strony
- Prostszy, bardziej czytelny kod
Kompletna dokumentacija API
Mapowanie przestrzeni nazw
| GemBox.Pdf | IronPDF |
|---|---|
GemBox.Pdf |
IronPdf |
GemBox.Pdf.Content |
IronPdf (zawartość to HTML) |
GemBox.Pdf.Security |
IronPdf (SecuritySettings) |
GemBox.Pdf.Forms |
IronPdf.Forms |
Mapowanie klas podstawowych
| GemBox.Pdf | IronPDF | Opis |
|---|---|---|
PdfDocument |
PdfDocument |
Główna klasa dokumentu PDF |
PdfPage |
PdfDocument.Pages[i] |
Przedstawienie strony |
PdfContent |
Nie dotyczy (użyj HTML) | Treść strony |
PdfFormattedText |
Nie dotyczy (użyj HTML) | Tekst sformatowany |
PdfPoint |
Nie dotyczy (użyj pozycjonowania CSS) | Współrzędne pozycjonowania |
ComponentInfo.SetLicense() |
IronPdf.License.LicenseKey |
Zarządzanie licencjami |
Operacje na dokumentach
| GemBox.Pdf | IronPDF |
|---|---|
new PdfDocument() |
new PdfDocument() |
PdfDocument.Load(path) |
PdfDocument.FromFile(path) |
PdfDocument.Load(stream) |
PdfDocument.FromStream(stream) |
document.Save(path) |
pdf.SaveAs(path) |
document.Save(stream) |
pdf.BinaryData (zwraca byte[]) |
Operacje na stronach
| GemBox.Pdf | IronPDF |
|---|---|
document.Pages.Add() |
Utwórz poprzez renderowanie HTML |
document.Pages.Count |
pdf.PageCount |
document.Pages[index] |
pdf.Pages[index] |
document.Pages.AddClone(pages) |
PdfDocument.Merge() |
Operacje związane z tekstem i treścią
| GemBox.Pdf | IronPDF |
|---|---|
new PdfFormattedText() |
Ciąg znaków HTML |
formattedText.Append(text) |
Uwzględnij w HTML |
formattedText.AppendLine(text) |
Uwzględnij w HTML |
formattedText.FontSize = 12 |
CSS font-size: 12pt |
formattedText.Font = ... |
CSS font-family: ... |
page.Content.DrawText(text, point) |
renderer.RenderHtmlAsPdf(html) |
page.Content.GetText() |
pdf.ExtractTextFromPage(i) |
Przykłady migracji kodu
Przykład 1: Konwersja HTML do PDF
Przed (GemBox.Pdf) — nieobsługiwane przez GemBox.Pdf; wymaga osobnego SKU GemBox.Document:
// NuGet: Install-Package GemBox.Document
// NOTE: GemBox.Pdf does NOT support HTML-to-PDF. PdfDocument.Load only opens
// existing PDF files. To convert HTML to PDF you must use the separate
// GemBox.Document product (different SKU, different license).
using GemBox.Document;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// GemBox.Document loads HTML and saves as PDF.
var document = DocumentModel.Load("input.html");
document.Save("output.pdf");
}
}
// NuGet: Install-Package GemBox.Document
// NOTE: GemBox.Pdf does NOT support HTML-to-PDF. PdfDocument.Load only opens
// existing PDF files. To convert HTML to PDF you must use the separate
// GemBox.Document product (different SKU, different license).
using GemBox.Document;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// GemBox.Document loads HTML and saves as PDF.
var document = DocumentModel.Load("input.html");
document.Save("output.pdf");
}
}
Imports GemBox.Document
Module Program
Sub Main()
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' GemBox.Document loads HTML and saves as PDF.
Dim document = DocumentModel.Load("input.html")
document.Save("output.pdf")
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
pdf.SaveAs("output.pdf")
End Sub
End Class
ChromePdfRendererIronPDF używa nowoczesnego silnika Chromium do renderowania HTML/CSS/JavaScript, więc pojedynczy pakiet NuGet bezpośrednio obsługuje HTML do PDF — bez osobnego SKU. Więcej opcji renderowania można znaleźć w dokumentacji dotyczącej konwersji HTML do PDF.
Przykład 2: Łączenie plików PDF
Before (GemBox.Pdf):
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using System.Linq;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var source1 = PdfDocument.Load("document1.pdf");
var source2 = PdfDocument.Load("document2.pdf");
document.Pages.AddClone(source1.Pages);
document.Pages.AddClone(source2.Pages);
document.Save("merged.pdf");
}
}
}
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using System.Linq;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var source1 = PdfDocument.Load("document1.pdf");
var source2 = PdfDocument.Load("document2.pdf");
document.Pages.AddClone(source1.Pages);
document.Pages.AddClone(source2.Pages);
document.Save("merged.pdf");
}
}
}
Imports GemBox.Pdf
Imports System.Linq
Module Program
Sub Main()
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document As New PdfDocument()
Dim source1 = PdfDocument.Load("document1.pdf")
Dim source2 = PdfDocument.Load("document2.pdf")
document.Pages.AddClone(source1.Pages)
document.Pages.AddClone(source2.Pages)
document.Save("merged.pdf")
End Using
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
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;
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
Class Program
Shared 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 Class
Statyczna metoda MergeIronPDF upraszcza operację – nie ma potrzeby tworzenia pustego dokumentu i klonowania stron indywidualnie. Dowiedz się więcej o łączeniu i dzieleniu plików PDF.
Przykład 3: Dodaj tekst do pliku PDF
Before (GemBox.Pdf):
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
// PdfFormattedText has no Text property; use Append/AppendLine.
var formattedText = new PdfFormattedText();
formattedText.FontSize = 24;
formattedText.Append("Hello World");
page.Content.DrawText(formattedText, new PdfPoint(100, 700));
document.Save("output.pdf");
}
}
}
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;
class Program
{
static void Main()
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
// PdfFormattedText has no Text property; use Append/AppendLine.
var formattedText = new PdfFormattedText();
formattedText.FontSize = 24;
formattedText.Append("Hello World");
page.Content.DrawText(formattedText, new PdfPoint(100, 700));
document.Save("output.pdf");
}
}
}
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
Module Program
Sub Main()
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document As New PdfDocument()
Dim page = document.Pages.Add()
' PdfFormattedText has no Text property; use Append/AppendLine.
Dim formattedText As New PdfFormattedText()
formattedText.FontSize = 24
formattedText.Append("Hello World")
page.Content.DrawText(formattedText, New PdfPoint(100, 700))
document.Save("output.pdf")
End Using
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Original Content</p>");
var stamper = new TextStamper()
{
Text = "Hello World",
FontSize = 24,
HorizontalOffset = 100,
VerticalOffset = 700
};
pdf.ApplyStamp(stamper);
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<p>Original Content</p>");
var stamper = new TextStamper()
{
Text = "Hello World",
FontSize = 24,
HorizontalOffset = 100,
VerticalOffset = 700
};
pdf.ApplyStamp(stamper);
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<p>Original Content</p>")
Dim stamper = New TextStamper() With {
.Text = "Hello World",
.FontSize = 24,
.HorizontalOffset = 100,
.VerticalOffset = 700
}
pdf.ApplyStamp(stamper)
pdf.SaveAs("output.pdf")
End Sub
End Class
Aby dodać tekst do istniejących PDF,IronPDF dostarcza klasę TextStamper, która oferuje precyzyjny kontrolę pozycjonowania. W przypadku nowych dokumentów wystarczy umieścić tekst w szablonie HTML. Dodatkowe opcje można znaleźć w dokumentacji dotyczącej stemplowania.
Przykład 4: Tworzenie tabel (największa poprawa!)
Przed (GemBox.Pdf) — układ oparty na współrzędnych, ograniczony do 2 stron w trybie wolnym:
using GemBox.Pdf;
using GemBox.Pdf.Content;
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
double y = 700;
double[] xPositions = { 50, 200, 300, 400 };
// Headers
var headers = new[] { "Product", "Price", "Qty", "Total" };
for (int i = 0; i < headers.Length; i++)
{
var text = new PdfFormattedText();
text.FontSize = 12;
text.Append(headers[i]);
page.Content.DrawText(text, new PdfPoint(xPositions[i], y));
}
y -= 20;
// Data rows — each row requires manual Y advancement,
// and free mode caps the saved file at 2 pages total.
document.Save("products.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
double y = 700;
double[] xPositions = { 50, 200, 300, 400 };
// Headers
var headers = new[] { "Product", "Price", "Qty", "Total" };
for (int i = 0; i < headers.Length; i++)
{
var text = new PdfFormattedText();
text.FontSize = 12;
text.Append(headers[i]);
page.Content.DrawText(text, new PdfPoint(xPositions[i], y));
}
y -= 20;
// Data rows — each row requires manual Y advancement,
// and free mode caps the saved file at 2 pages total.
document.Save("products.pdf");
}
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document As New PdfDocument()
Dim page = document.Pages.Add()
Dim y As Double = 700
Dim xPositions As Double() = {50, 200, 300, 400}
' Headers
Dim headers = New String() {"Product", "Price", "Qty", "Total"}
For i As Integer = 0 To headers.Length - 1
Dim text As New PdfFormattedText()
text.FontSize = 12
text.Append(headers(i))
page.Content.DrawText(text, New PdfPoint(xPositions(i), y))
Next
y -= 20
' Data rows — each row requires manual Y advancement,
' and free mode caps the saved file at 2 pages total.
document.Save("products.pdf")
End Using
Po (IronPDF) — brak limitu stron, właściwe tabele HTML:
using IronPdf;
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var html = @"
<html>
<head>
<style>
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #4CAF50; color: white; }
tr:nth-child(even) { background-color: #f2f2f2; }
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr><td>Widget A</td><td>$19.99</td><td>5</td><td>$99.95</td></tr>
<tr><td>Widget B</td><td>$29.99</td><td>3</td><td>$89.97</td></tr>
</tbody>
</table>
</body>
</html>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("products.pdf");
using IronPdf;
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var html = @"
<html>
<head>
<style>
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #4CAF50; color: white; }
tr:nth-child(even) { background-color: #f2f2f2; }
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr><td>Widget A</td><td>$19.99</td><td>5</td><td>$99.95</td></tr>
<tr><td>Widget B</td><td>$29.99</td><td>3</td><td>$89.97</td></tr>
</tbody>
</table>
</body>
</html>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("products.pdf");
Imports IronPdf
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim html As String = "
<html>
<head>
<style>
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #4CAF50; color: white; }
tr:nth-child(even) { background-color: #f2f2f2; }
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr><td>Widget A</td><td>$19.99</td><td>5</td><td>$99.95</td></tr>
<tr><td>Widget B</td><td>$29.99</td><td>3</td><td>$89.97</td></tr>
</tbody>
</table>
</body>
</html>"
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("products.pdf")
To najważniejsza poprawa w migracji GemBox.Pdf. Tabele, które w darmowym trybie GemBox.Pdf przekraczałyby limit 2 stron, renderują się bez tego limitu w IronPDF z pełnym wsparciem dla stylizacji CSS.
Ważne uwagi dotyczące migracji
Dostosowanie do pozycjonowania CSS
Jeśli potrzebujesz precyzyjnego pozycjonowania (podobnie jak w systemie współrzędnych GemBox.Pdf), użyj absolutnego pozycjonowania CSS:
<div style="position:absolute; left:50px; top:750px; font-size:24px;">
Text positioned at specific coordinates
</div>
<div style="position:absolute; left:50px; top:750px; font-size:24px;">
Text positioned at specific coordinates
</div>
Indeksowanie stron
Zarówno GemBox.Pdf, jak i IronPDF używają stron indeksowanych od zera, co sprawia, że ten aspekt migracji jest prosty:
// GemBox.Pdf
var page = document.Pages[0];
// IronPDF
var page = pdf.Pages[0];
// GemBox.Pdf
var page = document.Pages[0];
// IronPDF
var page = pdf.Pages[0];
' GemBox.Pdf
Dim page = document.Pages(0)
' IronPDF
Dim page = pdf.Pages(0)
Ustawienia zabezpieczeń
// GemBox.Pdf
var encryption = document.SaveOptions.SetPasswordEncryption();
encryption.DocumentOpenPassword = "userPassword";
encryption.PermissionsPassword = "ownerPassword";
// IronPDF
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
// GemBox.Pdf
var encryption = document.SaveOptions.SetPasswordEncryption();
encryption.DocumentOpenPassword = "userPassword";
encryption.PermissionsPassword = "ownerPassword";
// IronPDF
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
' GemBox.Pdf
Dim encryption = document.SaveOptions.SetPasswordEncryption()
encryption.DocumentOpenPassword = "userPassword"
encryption.PermissionsPassword = "ownerPassword"
' IronPDF
pdf.SecuritySettings.UserPassword = "userPassword"
pdf.SecuritySettings.OwnerPassword = "ownerPassword"
Rozwiązywanie problemów
Problem 1: Nie znaleziono PdfFormattedText
Problem: PdfFormattedText nie istnieje w IronPDF.
Rozwiązanie: Użyj kodu HTML ze stylami CSS:
// GemBox.Pdf
var text = new PdfFormattedText();
text.FontSize = 24;
text.Append("Hello");
// IronPDF
var html = "<p style='font-size:24px;'>Hello</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// GemBox.Pdf
var text = new PdfFormattedText();
text.FontSize = 24;
text.Append("Hello");
// IronPDF
var html = "<p style='font-size:24px;'>Hello</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
Imports GemBox.Pdf
Imports IronPDF
Dim text As New PdfFormattedText()
text.FontSize = 24
text.Append("Hello")
Dim html As String = "<p style='font-size:24px;'>Hello</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
Problem 2: Nie znaleziono metody DrawText
Problem: page.Content.DrawText() niedostępny.
Rozwiązanie: Tworzenie treści poprzez renderowanie HTML lub użycie szablonów:
// For new documents - render HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>");
// 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("<h1>Content</h1>");
// For existing documents - use stampers
var stamper = new TextStamper() { Text = "Added Text" };
pdf.ApplyStamp(stamper);
Imports System
' For new documents - render HTML
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>")
' For existing documents - use stampers
Dim stamper As New TextStamper() With {.Text = "Added Text"}
pdf.ApplyStamp(stamper)
Problem 3: Różnice w ładowaniu dokumentów
Problem: PdfDocument.Load() nie znaleziono.
Rozwiązanie: Użyj PdfDocument.FromFile() lub FromStream():
// GemBox.Pdf
var doc = PdfDocument.Load("input.pdf");
// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");
// GemBox.Pdf
var doc = PdfDocument.Load("input.pdf");
// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");
Imports GemBox.Pdf
Imports IronPdf
Dim doc = PdfDocument.Load("input.pdf")
Dim pdf = PdfDocument.FromFile("input.pdf")
Problem 4: Różnice w metodach zapisywania
Problem: Podpis metody document.Save() różni się.
Rozwiązanie: Użyj SaveAs():
// GemBox.Pdf
document.Save("output.pdf");
// IronPDF
pdf.SaveAs("output.pdf");
// GemBox.Pdf
document.Save("output.pdf");
// IronPDF
pdf.SaveAs("output.pdf");
Lista kontrolna migracji
Przed migracją
- Zrób inwentaryzację wszystkich użyć GemBox.Pdf w kodzie
- Zidentyfikuj układy oparte na współrzędnych, które wymagają konwersji do HTML
- Oceń, gdzie limit 2 stron w darmowym trybie wpływa na twój kod
- Uzyskaj klucz licencyjny IronPDF
- Utwórz gałąź migracji w systemie kontroli wersji
Migracja kodu
- Usuń pakiet NuGet GemBox.Pdf:
dotnet remove package GemBox.Pdf - Zainstaluj pakiet NuGet IronPDF:
dotnet add package IronPdf - Zaktualizuj importy przestrzeni nazw
- Zastąp
ComponentInfo.SetLicense()przezIronPdf.License.LicenseKey - Przekonwertuj
PdfDocument.Load()naPdfDocument.FromFile() - Przekonwertuj
document.Save()napdf.SaveAs() - Zastąp tekst oparty na współrzędnych treścią HTML
- Przekonwertuj
PdfFormattedTextna HTML z CSS styling - Zaktualizuj operacje scalania, aby używać
PdfDocument.Merge()
Testowanie
- Sprawdź, czy wszystkie dokumenty generują się poprawnie
- Sprawdź, czy wygląd dokumentu jest zgodny z oczekiwaniami
- Przetestuj wynikowy plik wielostronicowy (uprzednio ograniczony do 2 stron w darmowym trybie)
- Sprawdź, czy wyodrębnianie tekstu działa poprawnie
- Testowanie operacji scałania i dzielenia
- Sprawdź działanie funkcji bezpieczeństwa/szyfrowania
Po migracji
- Usuń klucze licencyjne GemBox.Pdf
- Aktualizacja dokumentacji
- Przeszkol zespół w zakresie podejścia HTML/CSS do plików PDF
- Ciesz się nieograniczoną liczbą stron bez limitu darmowego trybu!

