PDFSharp에서 IronPDF로의 마이그레이션 방법 (C#)
PDFsharp에서 IronPDF로 마이그레이션하면 수동 좌표 기반 그리기에서 현대적인 HTML/CSS 템플릿으로 PDF 생성 워크플로가 전환됩니다. 이 가이드는 GDI+ 스타일의 위치 설정을 웹 기술로 대체하는 단계별 전환 경로를 제공하여 개발 시간을 줄이고, HTML/CSS 기술을 통해 PDF 생성이 유지 관리 가능하도록 합니다.
PDFsharp에서 IronPDF로 전환해야 하는 이유
PDFsharp이해하기
PDFsharp는 개발자가 프로그래밍 방식으로 PDF 문서를 생성할 수 있는 저수준의 PDF 생성 라이브러리입니다. MIT 라이선스 하에 릴리스되었으며 PDFsharp-Team(원래 empira Software GmbH)이 유지 관리하며,PDFsharp6.x는 .NET 8/9/10 및 .NET Standard 2.0을 대상으로 하며, Core 빌드를 통해 Windows, Linux 및 macOS에서 플랫폼 간 실행됩니다. PDFsharp는 주로 GDI+ 스타일 API를 사용하여 처음부터 PDF를 그리거나 컴파일하는 도구로 작동하여 프로젝트의 특성에 따라 유익하면서도 제한적일 수 있습니다.
PDFsharp는 HTML-to-PDF 변환기로 잘못 간주되는 경우가 있지만 그렇지 않습니다. 이 라이브러리는 프로그래밍 방식의 PDF 문서 생성에만 전념합니다. 커뮤니티 애드온인 HtmlRenderer.PdfSharp(ArthurHub에 의해 개발)도 있지만 HTML 4.01 / CSS 레벨 2만을 대상으로 하고 있으며, flexbox, grid, JavaScript와 같은 최신 CSS 기능이 없습니다.
좌표 계산 문제
PDFsharp의 GDI+ 접근 방식은 다음을 필요로 합니다:
- 각 구성 요소에 대한 정확한 X,Y 위치를 계산
- 페이지 오버플로에 대한 콘텐츠 높이 수동 추적
- 라인 래핑 및 텍스트 측정을 직접 처리
- 테이블을 셀 별로 그리고 경계 계산
- 수동 페이지 구문을 통한 다중 페이지 문서 관리
PDFsharp의 아키텍처는 좌표를 사용한 위치 설정에 대한 깊은 이해가 필요하며, 복잡한 레이아웃을 만드는 데 어려움을 일으킬 수 있습니다.
PDFsharpvsIronPDF비교
| 기능 | PDFsharp | IronPDF |
|---|---|---|
| 라이선스 | MIT (무료) | 상업적 |
| HTML to PDF 지원 | 아니요 | 예 (HTML5/CSS3 지원) |
| 최신 CSS 지원 | 아니요 (HtmlRenderer 애드온을 통한 HTML 4.01 / CSS 2만 지원) | 예 (전체 CSS3 지원) |
| 문서 생성 | 좌표 기반 드로잉 | HTML/CSS 템플릿 |
| 레이아웃 시스템 | 수동 X,Y 위치 지정 | CSS 흐름/플렉스박스/그리드 |
| 페이지 구문 | 수동 계산 | 자동 + CSS 제어 |
| 테이블 | 셀 개별 드로잉 | HTML <table> |
| 스타일링 | 코드 기반 글꼴/색상 | CSS 스타일시트 |
| 문서 API | 저수준 (좌표 요구) | 고수준 (간소화된 API) |
| 업데이트 | 액티브 (6.x 라인) | 정규 |
IronPDF는 HTML 문서를 PDF로 전체 충실도 변환해야 하는 시나리오에서 빛을 발합니다. 이 .NET 라이브러리는 HTML5 및 CSS3을 지원하여 최신 웹 표준을 충족시킵니다. 그의 네이티브 HTML-to-PDF 기능 덕분에 개발자는 기존 웹 콘텐츠 또는 현대적인 웹 도구로 설계된 템플릿을 활용할 수 있습니다.
현대 .NET을 사용하는 팀의 경우 IronPDF는 웹 개발 기술을 활용하면서 좌표 계산을 제거하는 접근 방식을 제공합니다.
시작하기 전에
필수 조건
- .NET 환경: .NET Framework 4.6.2+ 또는 .NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGet 접근 권한: NuGet 패키지를 설치할 수 있는 능력
- IronPDF 라이선스: ironpdf.com에서 라이선스 키를 획득하세요
NuGet 패키지 변경 사항
# Remove PDFsharp (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
# Remove PDFsharp (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
라이선스 구성
// 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"
PDFsharp사용 식별
# Find all PDFsharp usages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
# Find all PDFsharp usages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
완전한 API 참조
네임스페이스 변경
// 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
핵심 API 매핑
| PDFsharp API | IronPDF API |
|---|---|
new PdfDocument() |
ChromePdfRenderer.RenderHtmlAsPdf() |
document.AddPage() |
자동 |
XGraphics.FromPdfPage() |
필요 없음 |
XGraphics.DrawString() |
HTML <p>, <h1>, 등 |
XGraphics.DrawImage() |
HTML <img> 태그 |
XFont |
CSS font-family, font-size |
XBrush, XPen |
CSS 색상/경계 |
document.Save() |
pdf.SaveAs() |
PdfReader.Open() |
PdfDocument.FromFile() |
코드 마이그레이션 예제
예제 1: HTML에서 PDF로 변환
이전 (PDFsharp):
// NuGet: Install-Package PDFsharp (official PDFsharp-Team package, MIT)
// PDFsharp does 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()
{
// PDFsharp does not have built-in HTML to 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);
// 수동 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-Package PDFsharp (official PDFsharp-Team package, MIT)
// PDFsharp does 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()
{
// PDFsharp does not have built-in HTML to 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);
// 수동 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)
' 수동 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
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
// IronPDF has native HTML to PDF rendering
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello from IronPDF</h1><p>Easy HTML to 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 to PDF rendering
var renderer = new ChromePdfRenderer();
string html = "<h1>Hello from IronPDF</h1><p>Easy HTML to 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
이 예시는 두 라이브러리 간의 가장 큰 차이점을 강조합니다. PDFsharp는 내장 HTML을 PDF로 변환하는 기능을 제공하지 않습니다. 따라서 PdfDocument를 수동으로 생성하고, PdfPage를 추가하고, XGraphics 객체를 얻고, XFont를 생성하고, DrawString()를 XRect 좌표와 함께 사용해야 합니다.
IronPDF는 ChromePdfRenderer을 통해 네이티브 HTML을 PDF로 렌더링합니다. RenderHtmlAsPdf() 메서드는 HTML 문자열을 받아 내부적으로 Chromium 엔진을 사용하여 변환합니다. IronPDF는 HTML5 및 CSS3에 정의된 모든 스타일을 보존하면서 HTML 파일을 PDF로 쉽게 변환하여 좌표 계산의 필요성을 없앱니다. HTML에서 PDF로의 문서에서 포괄적인 예제를 참조하세요.
예제 2: 기존 PDF에 텍스트/워터마크 추가하기
이전 (PDFsharp):
// NuGet: Install-Package PDFsharp (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: in PDFsharp 6.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-Package PDFsharp (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: in PDFsharp 6.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 XFont = 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
이후 (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
PDFsharp는 PdfReader.Open()를 사용하여 PDF를 열고 PdfDocumentOpenMode.Modify을 지정하고, 페이지에 접근하고, XGraphics 객체를 생성하고, 스타일로 XFont를 생성한 후, 정확한 X,Y 좌표(200, 400)를 지정한 XPoint와 함께 DrawString()를 사용해야 합니다.
IronPDF는 PdfDocument.FromFile(), 선언형 속성(Text, FontSize, FontFamily, IsBold, FontColor, VerticalAlignment, HorizontalAlignment)이 있는 TextStamper 객체, 그리고 ApplyStamp()을 사용하여 이를 단순화합니다. IronPDF에서는 정렬만 지정하면 좌표 계산이 필요 없고, IronPDF가 위치를 처리합니다. IronPdf.Editing 네임스페이스가 스탬핑 기능에 필요하다는 것을 유념하세요.
예제 3: 이미지로 PDF 생성하기
이전 (PDFsharp):
// NuGet: Install-Package PDFsharp (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-Package PDFsharp (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
이후 (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
PDFsharp는 새로운 PdfDocument를 생성하고, PdfPage를 추가하고, XGraphics을 얻고, 파일에서 XImage을 로드하고, 가로 및 세로를 계산하고, 정확한 좌표(50, 50, 200, 200)를 함께 사용하여 DrawImage()을 사용한 다음 DrawString()로 텍스트를 별도로 추가해야 합니다.
IronPDF는 표준 HTML과 <img> 태그 및 CSS 스타일링(style='width:200px; height:200px;')을 사용합니다. 좌표 계산이 필요 없으며, CSS가 레이아웃을 처리합니다. IronPDF는 선언형 정렬 속성을 사용하여 기존 PDF에 이미지를 추가하기 위한 ImageStamper도 제공합니다. 더 많은 정보를 보려면 튜토리얼을 참조하세요.
중요한 마이그레이션 노트
패러다임 전환: 좌표에서 HTML/CSS로
가장 큰 변화는 좌표 기반 그림에서 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)
폰트 마이그레이션
// 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>"
문서 로딩 변경
// 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.Save()
document.Save("output.pdf");
// IronPDF: pdf.SaveAs()
pdf.SaveAs("output.pdf");
// PDFsharp: document.Save()
document.Save("output.pdf");
// IronPDF: pdf.SaveAs()
pdf.SaveAs("output.pdf");
' PDFsharp: document.Save()
document.Save("output.pdf")
' IronPDF: pdf.SaveAs()
pdf.SaveAs("output.pdf")
페이지 접근 방식 변경
// PDFsharp: document.Pages[0]
PdfPage page = document.Pages[0];
// IronPDF: 자동 page handling or pdf.Pages[0]
// Pages are created automatically from HTML content
// PDFsharp: document.Pages[0]
PdfPage page = document.Pages[0];
// IronPDF: 자동 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: 자동 page handling or pdf.Pages(0)
' Pages are created automatically from HTML content
이동 후 새로운 기능
IronPDF로 마이그레이션한 후 PDFsharp가 제공하지 못하는 기능을 얻을 수 있습니다:
네이티브 HTML에서 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>")
URL에서 PDF로
var pdf = renderer.RenderUrlAsPdf("https://example.com");
var pdf = renderer.RenderUrlAsPdf("https://example.com");
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
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)
HTML을 사용한 워터마크
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>")
기능 비교 요약
| 기능 | PDFsharp | IronPDF |
|---|---|---|
| 좌표 기반 그리기 | ✓ | ✗(HTML 사용) |
| HTML to PDF | ✗ | ✓ |
| CSS3 지원 | ✗ | ✓ |
| 플렉스박스/그리드 레이아웃 | ✗ | ✓ |
| 텍스트 스탬핑 | 수동 XGraphics | 텍스트스탬퍼 |
| 이미지 스탬핑 | 수동 XImage | 이미지스탬퍼 |
| PDF 병합 | 수동 | ✓ |
| URL을 PDF로 변환 | ✗ | ✓ |
| 모던 웹 렌더링 | ✗ | Chromium 엔진 |
| 자동 페이지 구분 | ✗ | ✓ |
마이그레이션 체크리스트
사전 마이그레이션
- 코드베이스의 모든PDFsharp사용 인벤토리 만들기
- 생성되는 문서 유형 식별 (보고서, 송장, 인증서)
- 사용자 정의 그래픽 또는 그리기 작업 기록 -IronPDF라이선스 키 저장 계획 (환경 변수 권장) -IronPDF체험판 라이선스로 먼저 테스트
패키지 변경 사항
PDFsharpNuGet 패키지 (공식 PDFsharp-Team 패키지)를 제거합니다- 사용된
PDFsharp-WPF,PDFsharp-GDI또는PDFsharp-MigraDoc을 제거합니다 - 커뮤니티 .NET Standard 포트를 사용 중이라면
PdfSharpCore제거 IronPdfNuGet Install-Package:dotnet add package IronPdf
코드 변경 사항
- 네임스페이스 가져오기를 업데이트합니다 (
using PdfSharp.Pdf;→using IronPdf;) - 스탬핑 기능을 위해
using IronPdf.Editing;을 추가합니다 - 좌표 기반 레이아웃을 HTML/CSS로 변환
XFont을 CSS 폰트 속성으로 대체합니다XPen을 CSS 색상/테두리로 대체합니다XGraphics.DrawString()을 HTML 텍스트 요소로 대체합니다XGraphics.DrawImage()을 HTML<img>태그로 대체합니다PdfReader.Open()을PdfDocument.FromFile()으로 대체합니다document.Save()을pdf.SaveAs()으로 대체합니다- 테이블 그리기 코드를 HTML 테이블로 변환
마이그레이션 이후
- 생성된 PDF의 시각적 비교
- 다중 페이지 문서 테스트
- 글꼴 렌더링 확인
- 필요한 경우 새로운 기능 추가 (HTML to PDF, 병합, 워터마크)

