using IronPdf;
// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
// Advanced Example with HTML Assets
// Load external html assets: Images, CSS and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Migracja zPDFsharpdo IronPDF przeksztalca twoj przeplyw pracy generowania PDF z recznego rysowania opartego na wspolrzednych do nowoczesnych szablonow HTML/CSS. Ten przewodnik zapewnia szczegolowy szlak migracji, ktory zastepuje pozycjonowanie w stylu GDI+ technologiami internetowymi, skracajac czas rozwijania i czyniac generowanie PDF utrzymywalnym dzieki standardowym umiejetnosciom HTML/CSS.
Dlaczego migrowac zPDFsharpdo IronPDF
Przeglad PDFsharp
PDFsharp to niskopoziomowa biblioteka do tworzenia PDF, ktora pozwala programistom generowac dokumenty PDF programowo. Wydana na licencji MIT i utrzymywana przez zespol PDFsharp-Team (pierwotnie empira Software GmbH),PDFsharp6.x celuje w .NET 8/9/10 i .NET Standard 2.0 oraz dziala miedzyplatformowo na Windows, Linux i macOS za pomoca kompilacji Core.PDFsharpglownie dziala jako narzedzie do rysowania i kompilowania PDF od podstaw za pomoca API w stylu GDI+, co moze byc korzystne lub ograniczajace w zaleznosci od natury projektu.
CzasamiPDFsharpjest mylnie uwazane za konwerter HTML-to-PDF, czym nie jest. Jego przeznaczeniem jest wyłącznie programowe tworzenie dokumentów PDF. Podczas gdy istnieje dodatek z spolecznosci HtmlRenderer.PdfSharp (od ArthurHub), majacy na celu dostarczenie mozliwosci renderowania HTML, obejmuje on tylko HTML 4.01 / poziom CSS 2 — brak nowoczesnych funkcji CSS, takich jak flexbox, grid czy JavaScript.
Problem obliczeń współrzędnych
Podejscie GDI+PDFsharpoznacza, ze musisz:
Oblicz dokładne pozycje X, Y dla każdego elementu
Ręczne śledzenie wysokości treści w przypadku przepełnienia strony
Samodzielnie zadbaj o zawijanie linii i wymiarowanie tekstu
Rysuj tabele komórka po komórce z obliczeniami obramowań
Zarządzaj dokumentami wielostronicowymi z ręcznymi podziałami stron
ArchitekturaPDFsharpwymaga glebokiego zrozumienia pozycjonowania przy uzyciu wspolrzednych, co czesto stanowi wyzwanie przy tworzeniu skomplikowanych ukladow.
PorownaniePDFsharpvs IronPDF
Funkcja
PDFsharp
IronPDF
Licencja
MIT (bezpłatne)
Komercjalne
Obsługa konwersji HTML do PDF
Nie
Tak (obsługa HTML5/CSS3)
Obsługa nowoczesnego CSS
Nie (HTML 4.01 / CSS 2 przez dodatek HtmlRenderer)
Tak (pełna obsługa CSS3)
Tworzenie dokumentów
Rysowanie oparte na współrzędnych
Szablony HTML/CSS
System układu
Ręczne pozycjonowanie X, Y
Przepływ CSS/Flexbox/Grid
Podziały stron
Obliczenia ręczne
Automatyczne + sterowanie CSS
Tabele
Rysuj komórki pojedynczo
HTML
Stylizacja
Czcionki/kolory oparte na kodzie
Arkusze stylów CSS
Dokumentacja API
Niski poziom (wymaga współrzędnych)
Poziom wysokiego poziomu (uproszczone API)
Aktualizacje
Aktywny (linia 6.x)
Regularny
IronPDF sprawdza się doskonale w sytuacjach, gdy dokumenty HTML wymagają konwersji do formatu PDF z zachowaniem pełnej wierności. Ta biblioteka .NET obsługuje HTML5 i CSS3, zapewniając zgodność z nowoczesnymi standardami internetowymi. Dzięki wbudowanym funkcjom konwersji HTML do PDF programiści mogą wykorzystywać istniejące treści internetowe lub szablony zaprojektowane przy użyciu nowoczesnych narzędzi internetowych.
Dla zespolow na nowoczesnym .NET,IronPDF oferuje podejscie, ktore eliminuje obliczenia wspolrzednych, korzystajac z umiejetnosci rozwoju webowego.
Dostęp do NuGet: Możliwość instalowania pakietów NuGet
Licencja IronPDF: Uzyskaj klucz licencyjny na stronie ironpdf.com
Zmiany w pakiecie NuGet
# RemovePDFsharp(official PDFsharp-Team package IDs; case-sensitive on case-sensitive feeds)
dotnet remove package PDFsharp
# dotnet remove package PDFsharp-WPF # if you used the WPF build
# dotnet remove package PDFsharp-GDI # if you used the GDI build
# dotnet remove package PDFsharp-MigraDoc # if you used MigraDoc on top
# dotnet remove package PdfSharpCore # community .NET Standard port
# Add IronPDF
dotnet add package IronPdf
# RemovePDFsharp(official PDFsharp-Team package IDs; case-sensitive on case-sensitive feeds)
dotnet remove package PDFsharp
# dotnet remove package PDFsharp-WPF # if you used the WPF build
# dotnet remove package PDFsharp-GDI # if you used the GDI build
# dotnet remove package PDFsharp-MigraDoc # if you used MigraDoc on top
# dotnet remove package PdfSharpCore # community .NET Standard port
# Add IronPDF
dotnet add package IronPdf
SHELL
Konfiguracja licencji
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText $csharpLabel
Identyfikacja uzycia PDFsharp
# Find allPDFsharpusages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
# Find allPDFsharpusages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
SHELL
Kompletna dokumentacija API
Zmiany w przestrzeni nazw
// Before: PDFsharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;
// After: IronPDF
using IronPdf;
using IronPdf.Editing;
// Before: PDFsharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;
// After: IronPDF
using IronPdf;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Editing
$vbLabelText $csharpLabel
Mapowania podstawowych interfejsów API
APIPDFsharp
IronPDF API
new PdfDocument()
ChromePdfRenderer.RenderHtmlAsPdf()
document.AddPage()
Automatyczne
XGraphics.FromPdfPage()
Nie jest potrzebne
XGraphics.DrawString()
HTML , , itp.
XGraphics.DrawImage()
Tag HTML
XFont
CSS font-family, font-size
XBrush, XPen
Kolory/obramowania CSS
document.Save()
pdf.SaveAs()
PdfReader.Open()
PdfDocument.FromFile()
Przykłady migracji kodu
Przykład 1: Konwersja HTML do PDF
Before (PDFsharp):
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
//PDFsharpdoes NOT support HTML-to-PDF natively. The community add-on
// HtmlRenderer.PdfSharp covers HTML 4.01 / CSS level 2 only (no flexbox, grid, JS).
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
//PDFsharpdoes not have built-in HTML do PDF conversion
// You need to manually parse HTML and render content
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Arial", 12);
// Podręcznik text rendering (no HTML support)
gfx.DrawString("Hello from PDFsharp", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.TopLeft);
document.Save("output.pdf");
}
}
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
//PDFsharpdoes NOT support HTML-to-PDF natively. The community add-on
// HtmlRenderer.PdfSharp covers HTML 4.01 / CSS level 2 only (no flexbox, grid, JS).
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
//PDFsharpdoes not have built-in HTML do PDF conversion
// You need to manually parse HTML and render content
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Arial", 12);
// Podręcznik text rendering (no HTML support)
gfx.DrawString("Hello from PDFsharp", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.TopLeft);
document.Save("output.pdf");
}
}
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports System
Module Program
Sub Main()
' PDFsharp does not have built-in HTML to PDF conversion
' You need to manually parse HTML and render content
Dim document As New PdfDocument()
Dim page As PdfPage = document.AddPage()
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
Dim font As New XFont("Arial", 12)
' Podręcznik text rendering (no HTML support)
gfx.DrawString("Hello from PDFsharp", font, XBrushes.Black,
New XRect(0, 0, page.Width, page.Height),
XStringFormats.TopLeft)
document.Save("output.pdf")
End Sub
End Module
$vbLabelText $csharpLabel
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
//IronPDF has native HTML do PDF rendering
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello from IronPDF</h1><p>Easy HTML do PDF conversion</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
//IronPDF has native HTML do PDF rendering
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello from IronPDF</h1><p>Easy HTML do PDF conversion</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
' IronPDF has native HTML to PDF rendering
Dim renderer As New ChromePdfRenderer()
Dim html As String = "<h1>Hello from IronPDF</h1><p>Easy HTML to PDF conversion</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Class
$vbLabelText $csharpLabel
Ten przykład podkreśla najważniejszą różnicę między tymi dwiema bibliotekami.PDFsharpnie zapewnia wbudowanej konwersji HTML do PDF—należy ręcznie utworzyć PdfDocument, dodać PdfPage, uzyskać obiekt XGraphics, utworzyć XFont i użyć DrawString() z współrzędnymi XRect.
IronPDF zapewnia natywne renderowanie HTML do PDF przez ChromePdfRenderer. Metoda RenderHtmlAsPdf() akceptuje ciągi HTML i konwertuje je wewnętrznie za pomocą silnika Chromium.IronPDF z łatwością konwertuje pliki HTML do formatu PDF, zachowując wszystkie style zdefiniowane w HTML5 i CSS3, co eliminuje konieczność wykonywania obliczeń współrzędnych. Kompleksowe przykłady można znaleźć w dokumentacji dotyczącej konwersji HTML do PDF.
Przykład 2: Dodawanie tekstu/znaku wodnego do istniejącego pliku PDF
Before (PDFsharp):
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
// Open existing PDF
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
PdfPage page = document.Pages[0];
// Get graphics object
XGraphics gfx = XGraphics.FromPdfPage(page);
// Note: inPDFsharp6.x, XFontStyle was renamed to XFontStyleEx
XFont font = new XFont("Arial", 20, XFontStyleEx.Bold);
// Draw text at specific position
gfx.DrawString("Watermark Text", font, XBrushes.Red,
new XPoint(200, 400));
document.Save("modified.pdf");
}
}
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
// Open existing PDF
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
PdfPage page = document.Pages[0];
// Get graphics object
XGraphics gfx = XGraphics.FromPdfPage(page);
// Note: inPDFsharp6.x, XFontStyle was renamed to XFontStyleEx
XFont font = new XFont("Arial", 20, XFontStyleEx.Bold);
// Draw text at specific position
gfx.DrawString("Watermark Text", font, XBrushes.Red,
new XPoint(200, 400));
document.Save("modified.pdf");
}
}
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports PdfSharp.Drawing
Imports System
Module Program
Sub Main()
' Open existing PDF
Dim document As PdfDocument = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify)
Dim page As PdfPage = document.Pages(0)
' Get graphics object
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
' Note: in PDFsharp 6.x, XFontStyle was renamed to XFontStyleEx
Dim font As New XFont("Arial", 20, XFontStyleEx.Bold)
' Draw text at specific position
gfx.DrawString("Watermark Text", font, XBrushes.Red, New XPoint(200, 400))
document.Save("modified.pdf")
End Sub
End Module
$vbLabelText $csharpLabel
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Open existing PDF
var pdf = PdfDocument.FromFile("existing.pdf");
// Add text stamp/watermark
var textStamper = new TextStamper()
{
Text = "Watermark Text",
FontSize = 20,
FontFamily = "Arial",
IsBold = true,
FontColor = IronSoftware.Drawing.Color.Red,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
};
pdf.ApplyStamp(textStamper);
pdf.SaveAs("modified.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Open existing PDF
var pdf = PdfDocument.FromFile("existing.pdf");
// Add text stamp/watermark
var textStamper = new TextStamper()
{
Text = "Watermark Text",
FontSize = 20,
FontFamily = "Arial",
IsBold = true,
FontColor = IronSoftware.Drawing.Color.Red,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
};
pdf.ApplyStamp(textStamper);
pdf.SaveAs("modified.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Imports System
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
' Open existing PDF
Dim pdf = PdfDocument.FromFile("existing.pdf")
' Add text stamp/watermark
Dim textStamper = New TextStamper() With {
.Text = "Watermark Text",
.FontSize = 20,
.FontFamily = "Arial",
.IsBold = True,
.FontColor = IronSoftware.Drawing.Color.Red,
.VerticalAlignment = VerticalAlignment.Middle,
.HorizontalAlignment = HorizontalAlignment.Center
}
pdf.ApplyStamp(textStamper)
pdf.SaveAs("modified.pdf")
End Sub
End Module
$vbLabelText $csharpLabel
PDFsharp wymaga otwarcia PDF z PdfReader.Open() podając PdfDocumentOpenMode.Modify, uzyskania dostępu do strony, utworzenia obiektu XGraphics, utworzenia XFont ze stylem i użycia DrawString() z XPoint określającym dokładne współrzędne X,Y (200, 400).
IronPDF upraszcza to za pomocą PdfDocument.FromFile(), obiektu TextStamper z deklaratywnymi właściwościami (Text, FontSize, FontFamily, IsBold, FontColor, VerticalAlignment, HorizontalAlignment) i ApplyStamp(). Nie są potrzebne żadne obliczenia współrzędnych — wystarczy określić wyrównanie, a IronPDF zajmie się pozycjonowaniem. Należy pamiętać, że przestrzeń nazw IronPdf.Editing jest wymagana do funkcji stemplowania.
Przykład 3: Tworzenie pliku PDF z obrazami
Before (PDFsharp):
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
// Create new PDF document
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
// Load and draw image
XImage image = XImage.FromFile("image.jpg");
// Calculate size to fit page
double width = 200;
double height = 200;
gfx.DrawImage(image, 50, 50, width, height);
// Add text
XFont font = new XFont("Arial", 16);
gfx.DrawString("Image in PDF", font, XBrushes.Black,
new XPoint(50, 270));
document.Save("output.pdf");
}
}
// NuGet: Install-PackagePDFsharp (official PDFsharp-Team package, MIT)
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;
class Program
{
static void Main()
{
// Create new PDF document
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
// Load and draw image
XImage image = XImage.FromFile("image.jpg");
// Calculate size to fit page
double width = 200;
double height = 200;
gfx.DrawImage(image, 50, 50, width, height);
// Add text
XFont font = new XFont("Arial", 16);
gfx.DrawString("Image in PDF", font, XBrushes.Black,
new XPoint(50, 270));
document.Save("output.pdf");
}
}
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports System
Class Program
Shared Sub Main()
' Create new PDF document
Dim document As New PdfDocument()
Dim page As PdfPage = document.AddPage()
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
' Load and draw image
Dim image As XImage = XImage.FromFile("image.jpg")
' Calculate size to fit page
Dim width As Double = 200
Dim height As Double = 200
gfx.DrawImage(image, 50, 50, width, height)
' Add text
Dim font As New XFont("Arial", 16)
gfx.DrawString("Image in PDF", font, XBrushes.Black, New XPoint(50, 270))
document.Save("output.pdf")
End Sub
End Class
$vbLabelText $csharpLabel
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Create PDF from HTML with image
var renderer = new ChromePdfRenderer();
string html = @"
<h1>Image in PDF</h1>
<img src='image.jpg' style='width:200px; height:200px;' />
<p>Easy image embedding with HTML</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// Alternative: Add image to existing PDF
var existingPdf = new ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>");
var imageStamper = new IronPdf.Editing.ImageStamper(new Uri("image.jpg"))
{
VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
};
existingPdf.ApplyStamp(imageStamper);
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Create PDF from HTML with image
var renderer = new ChromePdfRenderer();
string html = @"
<h1>Image in PDF</h1>
<img src='image.jpg' style='width:200px; height:200px;' />
<p>Easy image embedding with HTML</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// Alternative: Add image to existing PDF
var existingPdf = new ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>");
var imageStamper = new IronPdf.Editing.ImageStamper(new Uri("image.jpg"))
{
VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
};
existingPdf.ApplyStamp(imageStamper);
}
}
Imports IronPdf
Imports System
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
' Create PDF from HTML with image
Dim renderer As New ChromePdfRenderer()
Dim html As String = "
<h1>Image in PDF</h1>
<img src='image.jpg' style='width:200px; height:200px;' />
<p>Easy image embedding with HTML</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
' Alternative: Add image to existing PDF
Dim existingPdf = New ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>")
Dim imageStamper = New IronPdf.Editing.ImageStamper(New Uri("image.jpg")) With {
.VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
}
existingPdf.ApplyStamp(imageStamper)
End Sub
End Module
$vbLabelText $csharpLabel
PDFsharp wymaga utworzenia nowego PdfDocument, dodania PdfPage, uzyskania XGraphics, załadowania XImage z pliku, obliczenia szerokości i wysokości, użycia DrawImage() z dokładnymi współrzędnymi (50, 50, 200, 200), a następnie osobno dodania tekstu za pomocą DrawString().
IronPDF używa standardowego HTML z tagiem i stylizacją CSS (style='width:200px; height:200px;'). Nie są potrzebne żadne obliczenia współrzędnych — układ strony obsługuje CSS.IronPDF także zapewnia ImageStamper do dodawania obrazów do istniejących PDF z deklaratywnymi właściwościami wyrównania. Dowiedz się więcej z naszych samouczków.
Ważne uwagi dotyczące migracji
Zmiana paradygmatu: współrzędne do HTML/CSS
Najważniejszą zmianą jest przejście z rysowania opartego na współrzędnych na HTML/CSS:
// PDFsharp: manual positioning
gfx.DrawString("Invoice", titleFont, XBrushes.Black, new XPoint(50, 50));
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, new XPoint(50, 80));
// IronPDF: let CSS handle layout
var html = @"
<div style='padding: 50px;'>
<h1>Invoice</h1>
<p>Customer: John</p>
</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
// PDFsharp: manual positioning
gfx.DrawString("Invoice", titleFont, XBrushes.Black, new XPoint(50, 50));
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, new XPoint(50, 80));
// IronPDF: let CSS handle layout
var html = @"
<div style='padding: 50px;'>
<h1>Invoice</h1>
<p>Customer: John</p>
</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
Imports PdfSharp.Drawing
Imports IronPdf
' PDFsharp: manual positioning
gfx.DrawString("Invoice", titleFont, XBrushes.Black, New XPoint(50, 50))
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, New XPoint(50, 80))
' IronPDF: let CSS handle layout
Dim html As String = "
<div style='padding: 50px;'>
<h1>Invoice</h1>
<p>Customer: John</p>
</div>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
$vbLabelText $csharpLabel
Migracja czcionek
// PDFsharp: XFont objects (PDFsharp 6.x renamed XFontStyle to XFontStyleEx)
var titleFont = new XFont("Arial", 24, XFontStyleEx.Bold);
var bodyFont = new XFont("Times New Roman", 12);
// IronPDF: CSS font properties
var html = @"
<style>
h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>";
// PDFsharp: XFont objects (PDFsharp 6.x renamed XFontStyle to XFontStyleEx)
var titleFont = new XFont("Arial", 24, XFontStyleEx.Bold);
var bodyFont = new XFont("Times New Roman", 12);
// IronPDF: CSS font properties
var html = @"
<style>
h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>";
' PDFsharp: XFont objects (PDFsharp 6.x renamed XFontStyle to XFontStyleEx)
Dim titleFont As New XFont("Arial", 24, XFontStyleEx.Bold)
Dim bodyFont As New XFont("Times New Roman", 12)
' IronPDF: CSS font properties
Dim html As String = "
<style>
h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>"
$vbLabelText $csharpLabel
Zmiana w ładowaniu dokumentów
// PDFsharp: PdfReader.Open()
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("existing.pdf");
// PDFsharp: PdfReader.Open()
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("existing.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports IronPdf
' PDFsharp: PdfReader.Open()
Dim document As PdfDocument = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify)
' IronPDF: PdfDocument.FromFile()
Dim pdf As PdfDocument = PdfDocument.FromFile("existing.pdf")
// PDFsharp: document.Pages[0]
PdfPage page = document.Pages[0];
// IronPDF: Automatyczne page handling or pdf.Pages[0]
// Pages are created automatically from HTML content
// PDFsharp: document.Pages[0]
PdfPage page = document.Pages[0];
// IronPDF: Automatyczne page handling or pdf.Pages[0]
// Pages are created automatically from HTML content
' PDFsharp: document.Pages(0)
Dim page As PdfPage = document.Pages(0)
' IronPDF: Automatyczne page handling or pdf.Pages(0)
' Pages are created automatically from HTML content
$vbLabelText $csharpLabel
Nowe możliwości po migracji
Po migracji do IronPDF zyskujesz mozliwosci, ktorePDFsharpnie moze zapewnic:
Natywny HTML do PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>");
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>")
$vbLabelText $csharpLabel
URL do pliku PDF
var pdf = renderer.RenderUrlAsPdf("https://example.com");
var pdf = renderer.RenderUrlAsPdf("https://example.com");
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
$vbLabelText $csharpLabel
Łączenie plików PDF
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
Zaktualizuj import przestrzeni nazw (using PdfSharp.Pdf; → using IronPdf;)
Dodaj using IronPdf.Editing; do funkcji stemplowania
Konwersja układów opartych na współrzędnych do HTML/CSS
Zastąp XFont właściwościami fontów CSS
Zastąp XPen kolorami/obramowaniami CSS
Zastąp XGraphics.DrawString() elementami tekstowymi HTML
Zastąp XGraphics.DrawImage() tagami HTML
Zastąp PdfReader.Open() przez PdfDocument.FromFile()
Zastąp document.Save() przez pdf.SaveAs()
Przekształć kod rysowania tabel w tabele HTML
Po migracji
Wizualne porównanie wygenerowanych plików PDF
Testowanie dokumentów wielostronicowych
Sprawdź renderowanie czcionek
W razie potrzeby dodaj nowe funkcje (konwersja HTML do PDF, scałanie, znaki wodne)
Zwróć uwagęPDFsharp jest znakiem towarowym swojego wlasciciela. Ta strona nie jest powiazana, zatwierdzona ani sponsorowana przez zespol PDFsharp-Team ani empira Software GmbH. Wszystkie nazwy produktów, logo i marki są własnością ich odpowiednich właścicieli. Porównania mają charakter wyłącznie informacyjny i odzwierciedlają informacje dostępne publicznie w momencie pisania.
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podrę...