Comment migrer de GemBox PDF vers IronPDF en C#
La migration de GemBox.Pdf vers IronPDF transforme votre flux de travail PDF .NET, passant de la construction documentaire programmatique basée sur des coordonnées à un rendu moderne basé sur HTML/CSS. Ce guide fournit une voie de migration complète et étape par étape qui élimine la limite de mode gratuit de 2 pages et simplifie la création de documents pour les développeurs professionnels .NET.
Pourquoi migrer de GemBox.Pdf vers IronPDF
Les défis de GemBox.Pdf
GemBox.Pdf est un composant PDF .NET performant, mais il a des limites qui valent la peine d'être pesées pour le développement réel :
-
Limite du mode libre à 2 pages : La version gratuite génère
FreeLimitReachedExceptionlors du chargement ou de l'enregistrement d'un PDF de plus de 2 pages, donc tout ce qui dépasse un reçu d'une page ou une facture de deux pages nécessite une licence payante. (Source: gemboxsoftware.com/pdf/free-version.) -
Aucune conversion HTML en PDF : GemBox.Pdf ne peut pas rendre HTML —
PdfDocument.Loadouvre uniquement des fichiers PDF existants. Pour convertir HTML en PDF, vous devez acheter le produit distinct GemBox.Document (SKU différent, licence différente). -
Mise en page basée sur des coordonnées : GemBox.Pdf est une API de flux de contenu PDF à bas niveau. Pour placer du texte, vous calculez X/Y en unités de l'espace utilisateur PDF et appelez
page.Content.DrawText(formattedText, new PdfPoint(x, y)). Il n'y a pas de mise en page fluide. -
Conversion Office en PDF nécessite d'autres SKU : Word→PDF nécessite GemBox.Document, Excel→PDF nécessite GemBox.Spreadsheet, chacun étant licencié séparément ; le GemBox.Bundle couvre tous ces besoins mais coûte plus cher.
-
Programmation uniquement : Chaque modification de conception nécessite des modifications de code. Modifier l'espacement ? Recalculer les coordonnées. Changer une taille de police ? Ajuster les positions Y en dessous.
-
Tarification de la licence commerciale : Licence pour un seul développeur 890 $ (renouvellement 534 $), petite équipe (10 développeurs) 4 450 $, grande équipe (50 développeurs) 13 350 $. (Source : gemboxsoftware.com/pdf/pricing.)
- Courbe d'apprentissage pour le design : Les développeurs doivent penser en termes de coordonnées plutôt qu'en flux de document, rendant les tâches simples comme "ajouter un paragraphe" étonnamment complexes.
Comparaison GemBox.Pdf vs IronPDF
| Aspect | GemBox.Pdf | IronPDF |
|---|---|---|
| Limites de la version gratuite | Limite de 2 pages (FreeLimitReachedException) | Filigrane seulement, pas de limite de page |
| HTML vers PDF | Non supporté (besoin de GemBox.Document) | Moteur Chromium complet |
| Word/Excel → PDF | SKU séparés (GemBox.Document / GemBox.Spreadsheet) | Rendu via pipeline HTML |
| Approche de la mise en page | Basé sur les coordonnées, manuel | Mise en page HTML/CSS |
| CSS moderne | Sans objet | Flexbox, grille, animations CSS3 |
| Support JavaScript | Sans objet | Exécution complète de JavaScript |
| Modifications de la conception | Recalculer les coordonnées | Édition de HTML/CSS |
| Courbe d'apprentissage | Système de coordonnées PDF | HTML/CSS (familier du web) |
IronPDF exploite des technologies web familières pour la génération de PDF sur les environnements .NET modernes.
Évaluation de la complexité de la migration
Estimation de l'effort par fonctionnalité
| Fonction | Complexité de la migration |
|---|---|
| Charger/Enregistrer des PDF | Très faible |
| Fusionner des PDF | Très faible |
| Diviser les PDF | Faible |
| Extraction de texte | Très faible |
| Ajouter du texte | Moyen |
| Tableaux | Faible |
| Images | Faible |
| Filigranes | Faible |
| Protection par mot de passe | Moyen |
| Champs de formulaire | Moyen |
Changement de paradigme
Le plus grand changement dans cette migration de GemBox.Pdf est le passage de la mise en page basée sur des coordonnées à la mise en page HTML/CSS :
GemBox.Pdf : "Dessiner du texte à la position (100, 700)"
IronPDF : "Rendre ce HTML avec un style CSS"
Ce changement de paradigme est généralement plus facile pour les développeurs familiarisés avec les technologies web, mais il nécessite de penser les PDF différemment.
Avant de commencer
Prérequis
- Version .NET :IronPDF prend en charge .NET Framework 4.6.2+ et .NET Core 2.0+ / .NET 5+
- Clé de licence : Obtenez votre clé de licence IronPDF sur IronPDF
- Sauvegarde : Créer une branche pour les travaux de migration
- Connaissances HTML/CSS : Une familiarité de base est un atout, mais n'est pas obligatoire.
Identifier toute utilisation de 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" .
Modifications du paquet 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
Migration rapide
Étape 1 : Mise à jour de la configuration de la licence
Avant (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")
Après (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" }
Étape 2 : mise à jour des importations de l'espace de noms
// 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
Étape 3 : Modèle de conversion de base
Avant (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
Après (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")
Différences Clés :
- Aucun calcul de coordonnées n'est nécessaire
- HTML/CSS au lieu de la mise en page programmatique
- Pas de limite de mode gratuit de 2 pages
- Un code plus simple et plus lisible
Référence API complète
Cartographie des espaces de noms
| GemBox.Pdf | IronPDF |
|---|---|
GemBox.Pdf |
IronPdf |
GemBox.Pdf.Content |
IronPdf (le contenu est du HTML) |
GemBox.Pdf.Security |
IronPdf (SecuritySettings) |
GemBox.Pdf.Forms |
IronPdf.Forms |
Mappage des classes de base
| GemBox.Pdf | IronPDF | Description du projet |
|---|---|---|
PdfDocument |
PdfDocument |
Classe du document PDF principal |
PdfPage |
PdfDocument.Pages[i] |
Représentation des pages |
PdfContent |
N/A (utiliser HTML) | Contenu de la page |
PdfFormattedText |
N/A (utiliser HTML) | Texte formaté |
PdfPoint |
N/A (utiliser le positionnement CSS) | Coordonner le positionnement |
ComponentInfo.SetLicense() |
IronPdf.License.LicenseKey |
Gestion des licences |
Opérations documentaires
| 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 (renvoie byte[]) |
Opérations de la page
| GemBox.Pdf | IronPDF |
|---|---|
document.Pages.Add() |
Création via le rendu HTML |
document.Pages.Count |
pdf.PageCount |
document.Pages[index] |
pdf.Pages[index] |
document.Pages.AddClone(pages) |
PdfDocument.Merge() |
Opérations de texte et de contenu
| GemBox.Pdf | IronPDF |
|---|---|
new PdfFormattedText() |
Chaîne HTML |
formattedText.Append(text) |
Inclure dans HTML |
formattedText.AppendLine(text) |
Inclure dans 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) |
Exemples de migration de code
Exemple 1 : Conversion HTML vers PDF
Avant (GemBox.Pdf) — non pris en charge par GemBox.Pdf ; nécessite le SKU distinct 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
Après (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
L'ChromePdfRenderer d'IronPDF utilise un moteur Chromium moderne pour le rendu HTML/CSS/JavaScript, donc un seul package NuGet couvre directement la conversion HTML en PDF — pas de SKU séparé. Voir la documentation HTML vers PDF pour plus d'options de rendu.
Exemple 2 : Fusionner des fichiers PDF
Avant (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
Après (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
La méthode statique Merge d'IronPDF simplifie l'opération : pas besoin de créer un document vide et de cloner les pages individuellement. En savoir plus sur la fusion et la division de PDF.
Exemple 3 : ajouter du texte à un PDF
Avant (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
Après (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
Pour ajouter du texte aux PDF existants,IronPDF fournit la classe TextStamper qui offre un contrôle de positionnement précis. Pour les nouveaux documents, il suffit d'inclure le texte dans votre modèle HTML. Consultez la documentation relative à l'estampage pour connaître les options supplémentaires.
Exemple 4 : Création de tableaux (la plus grande amélioration !)
Avant (GemBox.Pdf) — mise en page basée sur les coordonnées, limitée à 2 pages en mode gratuit :
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
Après (IronPDF) — pas de limite de pages, tableaux HTML appropriés :
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")
C'est l'amélioration la plus significative dans la migration de GemBox.Pdf. Les tableaux qui feraient dépasser une GemBox.Pdf en mode gratuit la limite de 2 pages se rendent sans cette limite dans IronPDF, avec un support complet de style CSS.
Notes de migration essentielles
Coordonner au positionnement CSS
Si vous avez besoin d'un positionnement précis (similaire au système de coordonnées de GemBox.Pdf), utilisez le positionnement absolu 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>
Indexation des pages
Tant GemBox.Pdf qu'IronPDF utilisent des pages indexées à 0, rendant cet aspect de la migration direct :
// 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)
Paramètres de sécurité
// 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"
Dépannage
Édition 1 : PdfFormattedText introuvable
Problème : PdfFormattedText n'existe pas dans IronPDF.
Solution : Utiliser HTML avec style 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)
Sujet 2 : Méthode DrawText introuvable
Problème : page.Content.DrawText() non disponible.
Solution : Créez du contenu via le rendu HTML ou utilisez des tampons :
// 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)
Enjeu 3 : Différences de chargement des documents
Problème : PdfDocument.Load() introuvable.
Solution: Use PdfDocument.FromFile() or 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")
Edition 4 : Différences entre les méthodes d'enregistrement
Problème : La signature de la méthode document.Save() diffère.
Solution: Use SaveAs():
// GemBox.Pdf
document.Save("output.pdf");
// IronPDF
pdf.SaveAs("output.pdf");
// GemBox.Pdf
document.Save("output.pdf");
// IronPDF
pdf.SaveAs("output.pdf");
Liste de contrôle de la migration
Pré-migration
- Inventaire de toute utilisation de GemBox.Pdf dans la base de code
- Identifier les mises en page basées sur des coordonnées qui nécessitent une conversion HTML
- Évaluez où la limite de mode gratuit de 2 pages affecte votre code
- Obtenir une clé de licence IronPDF
- Créer une branche de migration dans le système de contrôle de version
Migration de code
- Supprimez le package NuGet GemBox.Pdf :
dotnet remove package GemBox.Pdf - Installez le package NuGet IronPDF:
dotnet add package IronPdf - Mettre à jour les importations d'espace de noms
- Remplacez
ComponentInfo.SetLicense()parIronPdf.License.LicenseKey - Convertissez
PdfDocument.Load()enPdfDocument.FromFile() - Convertissez
document.Save()enpdf.SaveAs() - Remplacer le texte basé sur des coordonnées par du contenu HTML
- Convertissez
PdfFormattedTexten HTML avec un style CSS - Mettez à jour les opérations de fusion pour utiliser
PdfDocument.Merge()
Essai
- Vérifiez que tous les documents sont générés correctement.
- Vérifier que l'apparence du document correspond aux attentes
- Tester la sortie multi-pages (précédemment limitée à 2 pages en mode gratuit)
- Vérifier que l'extraction de texte fonctionne correctement
- Opérations de fusion et de division de test
- Valider les fonctionnalités de sécurité/chiffrement
Après la migration
- Retirer les clés de licence GemBox.Pdf
- Mise à jour de la documentation
- Former l'équipe à l'approche HTML/CSS pour les PDF
- Profitez d'un nombre illimité de pages sans limite de mode gratuit !

