Foxit PDF SDK에서 IronPDF로 마이그레이션: (.NET 가이드)
Foxit PDF SDK에서 IronPDF로 마이그레이션하면 복잡한 Enterprise 중심의 API를 현대적이고 개발자 친화적인 패턴으로 대체하여 .NET PDF 생성 워크플로우가 간소화됩니다. 이 가이드는 불필요한 코드를 제거하고 코드베이스 전반에 걸쳐 PDF 작업을 보다 쉽게 수행하는 단계별 마이그레이션 경로를 제공합니다.
Foxit PDF SDK에서 IronPDF로 마이그레이션해야 하는 이유
Foxit PDF의 과제들
Foxit PDF SDK는 강력한 Enterprise급 라이브러리이지만, 복잡성이 커서 개발 속도를 저하시킬 수 있습니다:
-
복잡한 라이센스 시스템: 여러 제품, SKU 및 라이센스 유형(개발자별, 서버별, OEM 등)으로 인해 프로젝트에 적합한 옵션을 선택하기 어렵습니다.
-
Enterprise 가격: 가격은 대형 조직을 대상으로 하며 소규모 팀이나 개인 개발자에게는 부담스러울 수 있습니다.
-
무거운 네이티브 패키지: 공개 NuGet 패키지(
Foxit.SDK.Dotnet)는 크기가 큽니다(~240 MB), 이전 프로젝트에서는 여전히 직접 DLL 참조나 개인 피드 구성을 포함할 수 있습니다. -
장황한 API:
Library.Initialize()를 사용한 라이브러리 초기화, 오류 코드 검사, 명시적인Library.Release()호출은 각 작업에 보일러플레이트를 추가합니다. -
별도의 HTML2PDF 엔진: HTML을 PDF로 변환하려면 HTML2PDF 엔진 바이너리가 필요하며, 이것은 Foxit 지원/판매처에서 별도로 배포되며 NuGet 패키지에 포함되지 않습니다.
-
복잡한 구성: 설정은 여러 속성을 사용하여 자세한 객체 구성을 요구합니다(예:
HTML2PDFSettingData). - C++ 유산: API 패턴은 C++ 기원을 반영하며, 현대적인 C# 애플리케이션에서는 덜 자연스러울 수 있습니다.
Foxit PDF vsIronPDF비교
| 측면 | Foxit PDF SDK | IronPDF |
|---|---|---|
| 설치 | Foxit.SDK.Dotnet (~240 MB) + 별도의 HTML2PDF 엔진 |
간단한 NuGet 패키지 |
| 라이센스 | 판매 주도, 개발자별, 플랫폼별 | 투명하고 모든 크기에 적합 |
| 초기화 | Library.Initialize(sn, key) |
라이선스 키 한 번 설정 |
| 오류 처리 | ErrorCode 열거형 | 표준 .NET 예외 |
| HTML to PDF | 별도의 엔진 다운로드 | 내장 Chromium 엔진 |
| API 스타일 | C++ 유산, 장황함 | 현대적인 .NET 패턴 |
| 리소스 정리 | 수동 Release() |
IDisposable/자동 |
| 문서화 | Enterprise 문서 포털 | 공공 튜토리얼 |
비용-효익 분석
Foxit PDF에서 IronPDF로 이동하면 실질적인 개발 이점이 있습니다: 더 간단한 API를 통한 복잡성 감소, 직관적인 메소드로 빠른 개발, 비동기/대기 및 LINQ 지원 등을 포함한 현대 .NET 호환성, 기존 웹 기술을 사용하는 HTML 중심 접근 방법, 별도의 엔진 다운로드 없이 포함된 HTML 변환. IronPDF는 현재 .NET 버전에서 실행되며 현대 C# 패턴과 완벽하게 어울립니다.
시작하기 전에
필수 조건
- .NET 환경: IronPDF는 .NET Framework 4.6.2+, .NET Core 3.1+, .NET 5/6/7/8/9+를 지원합니다.
- NuGet 액세스: NuGet에서 패키지를 설치할 수 있는지 확인하십시오.
- 라이센스 키: ironpdf.com에서 제품 사용을 위한IronPDF라이센스 키를 얻으십시오.
프로젝트 백업하기
# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup beforeFoxit PDF SDKtoIronPDF migration"
# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup beforeFoxit PDF SDKtoIronPDF migration"
모든 Foxit PDF 사용 식별
# Find allFoxit PDF SDKreferences
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .
# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"
# Find allFoxit PDF SDKreferences
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .
# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"
현재 기능 문서화
마이그레이션 전에 카탈로그:
- 사용 중인 Foxit PDF 기능 (HTML 변환, 주석, 양식, 보안)
- 라이선스 키 위치와 초기화 코드
- 커스텀 설정과 환경설정
- ErrorCode 열거형을 사용한 오류 처리 패턴
빠른 시작 마이그레이션
1단계: NuGet 패키지 업데이트
# Remove the Foxit NuGet package
dotnet remove package Foxit.SDK.Dotnet
# Install IronPDF
dotnet add package IronPdf
# Remove the Foxit NuGet package
dotnet remove package Foxit.SDK.Dotnet
# Install IronPDF
dotnet add package IronPdf
이전의 Foxit DLL 참조가 .csproj(이전 빌드) 내에서 있는 경우 수동으로 제거하십시오:
<Reference Include="fsdk_dotnet">
<HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>
<Reference Include="fsdk_dotnet">
<HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>
별도로 풀어 놓인 모든 HTML2PDF 엔진 폴더도 삭제하십시오.
단계 2: 네임스페이스 업데이트
// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Rendering
Imports IronPdf.Editing
3단계:IronPDF초기화
이 Foxit PDF 마이그레이션의 가장 중요한 개선 중 하나는 복잡한 초기화 및 정리 패턴을 제거한 것입니다:
// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release(); // Don't forget this!
// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// That's it! No Release() needed
// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release(); // Don't forget this!
// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// That's it! No Release() needed
Imports System
' Before (Foxit PDF)
Dim sn As String = "YOUR_SERIAL_NUMBER"
Dim key As String = "YOUR_LICENSE_KEY"
Dim error_code As ErrorCode = Library.Initialize(sn, key)
If error_code <> ErrorCode.e_ErrSuccess Then
Throw New Exception("Failed to initialize Foxit PDF SDK")
End If
' ... your code ...
Library.Release() ' Don't forget this!
' After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
' That's it! No Release() needed
4단계: 기본 변환 패턴
// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
Convert.FromHTML(htmlContent, @"C:\Foxit\html2pdf_engine", "",
settings, "output.pdf", 30);
Library.Release();
// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
Convert.FromHTML(htmlContent, @"C:\Foxit\html2pdf_engine", "",
settings, "output.pdf", 30);
Library.Release();
// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
' Before (Foxit PDF)
Library.Initialize(sn, key)
Dim settings As New HTML2PDFSettingData()
settings.page_width = 612.0F
settings.page_height = 792.0F
Convert.FromHTML(htmlContent, "C:\Foxit\html2pdf_engine", "", settings, "output.pdf", 30)
Library.Release()
' After (IronPDF)
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
완전한 API 참조
네임스페이스 매핑
| Foxit PDF 네임스페이스 | IronPDF 동등 |
|---|---|
foxit |
IronPdf |
foxit.common |
IronPdf |
foxit.common.fxcrt |
해당 없음 |
foxit.pdf |
IronPdf |
foxit.pdf.annots |
IronPdf.Editing |
foxit.addon.conversion |
IronPdf.Rendering |
핵심 클래스 매핑
| Foxit PDF SDK클래스 | IronPDF 동등 |
|---|---|
Library |
해당 없음 |
PDFDoc |
PdfDocument |
PDFPage |
PdfDocument.Pages[i] |
HTML2PDF |
ChromePdfRenderer |
TextPage |
pdf.ExtractTextFromPage(i) |
Watermark |
TextStamper / ImageStamper |
Security |
SecuritySettings |
Form |
pdf.Form |
Metadata |
pdf.MetaData |
PDFDoc 메서드
| Foxit PDFDoc | IronPDF PdfDocument |
|---|---|
new PDFDoc(path) |
PdfDocument.FromFile(path) |
doc.LoadW(password) |
PdfDocument.FromFile(path, password) |
doc.GetPageCount() |
pdf.PageCount |
doc.GetPage(index) |
pdf.Pages[index] |
doc.SaveAs(path, flags) |
pdf.SaveAs(path) |
doc.Close() |
pdf.Dispose() 또는 using 구문 |
doc.InsertDocument() |
PdfDocument.Merge() |
HTML2PDF / 변환
| Foxit HTML2PDF | IronPDF 동등 |
|---|---|
new HTML2PDFSettingData() |
new ChromePdfRenderer() |
settings.page_width |
RenderingOptions.PaperSize |
settings.page_height |
RenderingOptions.SetCustomPaperSize() |
Convert.FromHTML(html, engine, ...) |
renderer.RenderHtmlAsPdf(html) |
Convert.FromHTML(url, engine, ...) |
renderer.RenderUrlAsPdf(url) |
워터마크 설정
| Foxit 워터마크 | IronPDF 동등 |
|---|---|
new Watermark(doc, text, font, size, color) |
new TextStamper() |
WatermarkSettings.position |
VerticalAlignment + HorizontalAlignment |
WatermarkSettings.rotation |
Rotation |
WatermarkSettings.opacity |
Opacity |
watermark.InsertToAllPages() |
pdf.ApplyStamp(stamper) |
코드 예제
예제 1: HTML에서 PDF로 변환
이전 (Foxit PDF SDK):
// NuGet: Install-Package Foxit.SDK.Dotnet
// HTML-to-PDF requires the separateFoxit HTML2PDFengine (engine_path),
// obtained from Foxit support/sales — not in the NuGet package.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
Convert.FromHTML(
"<html><body><h1>Hello World</h1></body></html>",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settingData,
"output.pdf",
30); // timeout (seconds)
Library.Release();
}
}
// NuGet: Install-Package Foxit.SDK.Dotnet
// HTML-to-PDF requires the separateFoxit HTML2PDFengine (engine_path),
// obtained from Foxit support/sales — not in the NuGet package.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
Convert.FromHTML(
"<html><body><h1>Hello World</h1></body></html>",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settingData,
"output.pdf",
30); // timeout (seconds)
Library.Release();
}
}
Imports foxit
Imports foxit.common
Imports foxit.addon.conversion
Imports System
Module Program
Sub Main()
Library.Initialize("sn", "key")
Dim settingData As New HTML2PDFSettingData()
settingData.page_width = 612.0F
settingData.page_height = 792.0F
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage
Convert.FromHTML(
"<html><body><h1>Hello World</h1></body></html>",
"C:\Foxit\html2pdf_engine", ' engine_path (separate download)
"", ' cookies path
settingData,
"output.pdf",
30) ' timeout (seconds)
Library.Release()
End Sub
End Module
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>")
pdf.SaveAs("output.pdf")
End Sub
End Class
IronPDF 접근 방식은 구성을 위한 15줄 이상의 코드를 단 4줄로 줄여줍니다. 라이브러리 초기화 없음, 명시적 정리 없음, 복잡한 설정 객체 없음. 더 많은 HTML 렌더링 옵션을 보려면 HTML to PDF 문서를 참조하십시오.
예제 2: URL에서 PDF로 변환
이전 (Foxit PDF SDK):
// NuGet: Install-Package Foxit.SDK.Dotnet
// Convert.FromHTML accepts either a URL or a literal HTML string in the
// first argument; the URL form is what does URL-to-PDF.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
Convert.FromHTML(
"https://www.example.com",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settingData,
"output.pdf",
30); // timeout (seconds)
Library.Release();
}
}
// NuGet: Install-Package Foxit.SDK.Dotnet
// Convert.FromHTML accepts either a URL or a literal HTML string in the
// first argument; the URL form is what does URL-to-PDF.
using foxit;
using foxit.common;
using foxit.addon.conversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
Convert.FromHTML(
"https://www.example.com",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settingData,
"output.pdf",
30); // timeout (seconds)
Library.Release();
}
}
Imports foxit
Imports foxit.common
Imports foxit.addon.conversion
Imports System
Module Program
Sub Main()
Library.Initialize("sn", "key")
Dim settingData As New HTML2PDFSettingData()
settingData.page_width = 612.0F
settingData.page_height = 792.0F
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage
Convert.FromHTML(
"https://www.example.com",
"C:\Foxit\html2pdf_engine", ' engine_path (separate download)
"", ' cookies path
settingData,
"output.pdf",
30) ' timeout (seconds)
Library.Release()
End Sub
End Module
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("output.pdf")
End Sub
End Class
IronPDF의 내장 Chromium 엔진은 JavaScript 실행, CSS 렌더링 및 동적 콘텐츠를 자동으로 처리합니다. URL을 PDF로 변환에 대해 더 알아보세요.
예제 3: 워터마크 추가
이전 (Foxit PDF SDK):
// NuGet: Install-Package Foxit.SDK.Dotnet
using foxit;
using foxit.common;
using foxit.pdf;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.Load("");
WatermarkSettings settings = new WatermarkSettings();
settings.flags = (int)Watermark.Flags.e_FlagASPageContents;
settings.position = Position.e_PosCenter;
settings.rotation = -45.0f;
settings.opacity = 50; // 0-100 in newer SDKs
WatermarkTextProperties props = new WatermarkTextProperties();
props.font = new Font(Font.StandardID.e_StdIDHelvetica);
props.font_size = 48.0f;
props.color = 0xFF0000;
props.alignment = Alignment.e_AlignmentCenter;
Watermark watermark = new Watermark(doc, "Confidential", props, settings);
// No InsertToAllPages helper — iterate pages explicitly.
for (int i = 0; i < doc.GetPageCount(); i++)
{
using (PDFPage page = doc.GetPage(i))
{
watermark.InsertToPage(page);
}
}
doc.SaveAs("output.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
Library.Release();
}
}
// NuGet: Install-Package Foxit.SDK.Dotnet
using foxit;
using foxit.common;
using foxit.pdf;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.Load("");
WatermarkSettings settings = new WatermarkSettings();
settings.flags = (int)Watermark.Flags.e_FlagASPageContents;
settings.position = Position.e_PosCenter;
settings.rotation = -45.0f;
settings.opacity = 50; // 0-100 in newer SDKs
WatermarkTextProperties props = new WatermarkTextProperties();
props.font = new Font(Font.StandardID.e_StdIDHelvetica);
props.font_size = 48.0f;
props.color = 0xFF0000;
props.alignment = Alignment.e_AlignmentCenter;
Watermark watermark = new Watermark(doc, "Confidential", props, settings);
// No InsertToAllPages helper — iterate pages explicitly.
for (int i = 0; i < doc.GetPageCount(); i++)
{
using (PDFPage page = doc.GetPage(i))
{
watermark.InsertToPage(page);
}
}
doc.SaveAs("output.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
Library.Release();
}
}
Imports foxit
Imports foxit.common
Imports foxit.pdf
Imports System
Module Program
Sub Main()
Library.Initialize("sn", "key")
Using doc As New PDFDoc("input.pdf")
doc.Load("")
Dim settings As New WatermarkSettings()
settings.flags = CInt(Watermark.Flags.e_FlagASPageContents)
settings.position = Position.e_PosCenter
settings.rotation = -45.0F
settings.opacity = 50 ' 0-100 in newer SDKs
Dim props As New WatermarkTextProperties()
props.font = New Font(Font.StandardID.e_StdIDHelvetica)
props.font_size = 48.0F
props.color = &HFF0000
props.alignment = Alignment.e_AlignmentCenter
Dim watermark As New Watermark(doc, "Confidential", props, settings)
' No InsertToAllPages helper — iterate pages explicitly.
For i As Integer = 0 To doc.GetPageCount() - 1
Using page As PDFPage = doc.GetPage(i)
watermark.InsertToPage(page)
End Using
Next
doc.SaveAs("output.pdf", CInt(PDFDoc.SaveFlags.e_SaveFlagNoOriginal))
End Using
Library.Release()
End Sub
End Module
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark(new TextStamper()
{
Text = "Confidential",
FontSize = 48,
Opacity = 50,
Rotation = -45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
});
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark(new TextStamper()
{
Text = "Confidential",
FontSize = 48,
Opacity = 50,
Rotation = -45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
});
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
pdf.ApplyWatermark(New TextStamper() With {
.Text = "Confidential",
.FontSize = 48,
.Opacity = 50,
.Rotation = -45,
.VerticalAlignment = VerticalAlignment.Middle,
.HorizontalAlignment = HorizontalAlignment.Center
})
pdf.SaveAs("output.pdf")
End Sub
End Class
IronPDF의 TextStamper는 별도의 설정 객체와 수동 페이지 반복 대신 직관적인 속성 기반 구성을 제공합니다. 추가 옵션을 보려면 전체 워터마킹 문서를 참조하십시오.
예제 4: 헤더와 풋터가 있는 URL에서 PDF로
이전 (Foxit PDF SDK):
using foxit;
using foxit.addon.conversion;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 595.0f; // A4
settings.page_height = 842.0f;
settings.page_margin_top = 100.0f;
settings.page_margin_bottom = 100.0f;
//Foxit PDF SDKhas limited header/footer support
// Often requires post-processing or additional code
Convert.FromHTML(
"https://www.example.com",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settings,
"webpage.pdf",
30); // timeout (seconds)
}
finally
{
Library.Release();
}
}
}
using foxit;
using foxit.addon.conversion;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 595.0f; // A4
settings.page_height = 842.0f;
settings.page_margin_top = 100.0f;
settings.page_margin_bottom = 100.0f;
//Foxit PDF SDKhas limited header/footer support
// Often requires post-processing or additional code
Convert.FromHTML(
"https://www.example.com",
@"C:\Foxit\html2pdf_engine", // engine_path (separate download)
"", // cookies path
settings,
"webpage.pdf",
30); // timeout (seconds)
}
finally
{
Library.Release();
}
}
}
Imports foxit
Imports foxit.addon.conversion
Class Program
Shared Sub Main()
Library.Initialize("sn", "key")
Try
Dim settings As New HTML2PDFSettingData()
settings.page_width = 595.0F ' A4
settings.page_height = 842.0F
settings.page_margin_top = 100.0F
settings.page_margin_bottom = 100.0F
' Foxit PDF SDK has limited header/footer support
' Often requires post-processing or additional code
Convert.FromHTML(
"https://www.example.com",
"C:\Foxit\html2pdf_engine", ' engine_path (separate download)
"", ' cookies path
settings,
"webpage.pdf",
30) ' timeout (seconds)
Finally
Library.Release()
End Try
End Sub
End Class
이후 (IronPDF):
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.WaitFor.RenderDelay(3000); // Wait for JS
// Built-in header/footer support
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
DrawDividerLine = true
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.WaitFor.RenderDelay(3000); // Wait for JS
// Built-in header/footer support
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
DrawDividerLine = true
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PrintHtmlBackgrounds = True
renderer.RenderingOptions.WaitFor.RenderDelay(3000) ' Wait for JS
' Built-in header/footer support
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
.HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
.DrawDividerLine = True
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {
.HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
.DrawDividerLine = True
}
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End Class
IronPDF는 HTML 스타일링 및 동적 페이지 번호 자리 표시기가 포함된 네이티브 헤더와 풋터 지원을 제공합니다.
예제 5: PDF 보안 및 암호화
이전 (Foxit PDF SDK):
using foxit;
using foxit.pdf;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.LoadW("");
// Build the encryption data (cipher, key length, permissions)
using (StdEncryptData encryptData = new StdEncryptData(
true, // is_encrypt_metadata
(int)(PDFDoc.UserPermissions.e_PermPrint |
PDFDoc.UserPermissions.e_PermModify),
SecurityHandler.CipherType.e_CipherAES,
16)) // key length (bytes) -> AES-128
using (StdSecurityHandler securityHandler = new StdSecurityHandler())
{
securityHandler.Initialize(encryptData, "user_password", "owner_password");
doc.SetSecurityHandler(securityHandler);
}
doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
}
finally
{
Library.Release();
}
}
}
using foxit;
using foxit.pdf;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.LoadW("");
// Build the encryption data (cipher, key length, permissions)
using (StdEncryptData encryptData = new StdEncryptData(
true, // is_encrypt_metadata
(int)(PDFDoc.UserPermissions.e_PermPrint |
PDFDoc.UserPermissions.e_PermModify),
SecurityHandler.CipherType.e_CipherAES,
16)) // key length (bytes) -> AES-128
using (StdSecurityHandler securityHandler = new StdSecurityHandler())
{
securityHandler.Initialize(encryptData, "user_password", "owner_password");
doc.SetSecurityHandler(securityHandler);
}
doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
}
finally
{
Library.Release();
}
}
}
Imports foxit
Imports foxit.pdf
Class Program
Shared Sub Main()
Library.Initialize("sn", "key")
Try
Using doc As New PDFDoc("input.pdf")
doc.LoadW("")
' Build the encryption data (cipher, key length, permissions)
Using encryptData As New StdEncryptData(True, CType(PDFDoc.UserPermissions.e_PermPrint Or PDFDoc.UserPermissions.e_PermModify, Integer), SecurityHandler.CipherType.e_CipherAES, 16) ' key length (bytes) -> AES-128
Using securityHandler As New StdSecurityHandler()
securityHandler.Initialize(encryptData, "user_password", "owner_password")
doc.SetSecurityHandler(securityHandler)
End Using
End Using
doc.SaveAs("encrypted.pdf", CType(PDFDoc.SaveFlags.e_SaveFlagNoOriginal, Integer))
End Using
Finally
Library.Release()
End Try
End Sub
End Class
이후 (IronPDF):
using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
// Set passwords
pdf.SecuritySettings.OwnerPassword = "owner_password";
pdf.SecuritySettings.UserPassword = "user_password";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
pdf.SecuritySettings.AllowUserCopyPasteContent = true;
pdf.SecuritySettings.AllowUserAnnotations = true;
pdf.SaveAs("encrypted.pdf");
}
}
using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
// Set passwords
pdf.SecuritySettings.OwnerPassword = "owner_password";
pdf.SecuritySettings.UserPassword = "user_password";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
pdf.SecuritySettings.AllowUserCopyPasteContent = true;
pdf.SecuritySettings.AllowUserAnnotations = true;
pdf.SaveAs("encrypted.pdf");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
' Set passwords
pdf.SecuritySettings.OwnerPassword = "owner_password"
pdf.SecuritySettings.UserPassword = "user_password"
' Set permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll
pdf.SecuritySettings.AllowUserCopyPasteContent = True
pdf.SecuritySettings.AllowUserAnnotations = True
pdf.SaveAs("encrypted.pdf")
End Sub
End Class
성능 고려 사항
ChromePdfRenderer 재사용
Foxit PDF 마이그레이션 중 최적의 성능을 위해 ChromePdfRenderer 인스턴스를 재사용하세요—스레드 안전합니다:
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}
Imports System
Public Class PdfService
Private Shared ReadOnly _renderer As New ChromePdfRenderer()
Public Function Generate(html As String) As Byte()
Return _renderer.RenderHtmlAsPdf(html).BinaryData
End Function
' BAD - Creates new instance each time
Public Function GenerateBad(html As String) As Byte()
Dim renderer As New ChromePdfRenderer() ' Wasteful
Return renderer.RenderHtmlAsPdf(html).BinaryData
End Function
End Class
단위 변환 도우미
Foxit PDF SDK는 포인트를 사용합니다; IronPDF는 밀리미터를 사용합니다. 마이그레이션 중 이 도우미를 사용하십시오:
public static class UnitConverter
{
public static double PointsToMm(double points) => points * 0.352778;
public static double MmToPoints(double mm) => mm / 0.352778;
public static double InchesToMm(double inches) => inches * 25.4;
}
// Usage: Convert Foxit's 72 points (1 inch) toIronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mm
public static class UnitConverter
{
public static double PointsToMm(double points) => points * 0.352778;
public static double MmToPoints(double mm) => mm / 0.352778;
public static double InchesToMm(double inches) => inches * 25.4;
}
// Usage: Convert Foxit's 72 points (1 inch) toIronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mm
Public Module UnitConverter
Public Function PointsToMm(points As Double) As Double
Return points * 0.352778
End Function
Public Function MmToPoints(mm As Double) As Double
Return mm / 0.352778
End Function
Public Function InchesToMm(inches As Double) As Double
Return inches * 25.4
End Function
End Module
' Usage: Convert Foxit's 72 points (1 inch) to IronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72) ' ~25.4mm
적절한 리소스 폐기
// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automatically
// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automatically
Imports PdfDocument
' GOOD - Using block for automatic cleanup
Using pdf = PdfDocument.FromFile("large.pdf")
Dim text As String = pdf.ExtractAllText()
End Using ' pdf is disposed automatically
문제 해결
문제 1: Library.Initialize() 찾을 수 없음
문제: Library.Initialize()는 IronPDF에 존재하지 않습니다.
해결책: IronPDF는 더 간단한 초기화 패턴을 사용합니다:
// Foxit PDF
Library.Initialize(sn, key);
//IronPDF- just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Foxit PDF
Library.Initialize(sn, key);
//IronPDF- just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
문제 2: ErrorCode 처리
문제: 코드가 ErrorCode.e_ErrSuccess를 확인하지만 IronPDF에는 이 기능이 없습니다.
해결책: 표준 .NET 예외 처리를 사용하십시오:
// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }
// IronPDF
try
{
var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
Console.WriteLine($"Failed to load PDF: {ex.Message}");
}
// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }
// IronPDF
try
{
var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
Console.WriteLine($"Failed to load PDF: {ex.Message}");
}
Imports System
Imports System.IO
' Foxit PDF
Dim err As ErrorCode = doc.LoadW("")
If err <> ErrorCode.e_ErrSuccess Then
' handle error
End If
' IronPDF
Try
Dim pdf = PdfDocument.FromFile("input.pdf")
Catch ex As IOException
Console.WriteLine($"Failed to load PDF: {ex.Message}")
End Try
문제 3: PDFDoc.Close() 찾을 수 없음
문제: doc.Close() 메서드는 IronPDF에 존재하지 않습니다.
해결책: Dispose() 또는 using 구문을 사용하세요:
// Foxit PDF
doc.Close();
// IronPDF
pdf.Dispose();
// or better: wrap in using statement
// Foxit PDF
doc.Close();
// IronPDF
pdf.Dispose();
// or better: wrap in using statement
마이그레이션 체크리스트
사전 마이그레이션
- 사용된 모든Foxit PDF SDK기능 인벤토리
- 라이선스 키 위치 기록
- 모든
Library.Initialize()및Library.Release()호출을 기록하세요 - 사용자 지정 설정 목록 (페이지 크기, 여백 등)
- ErrorCode 사용한 오류 처리 패턴 식별
- 프로젝트를 버전 관리에 백업하세요 -IronPDF라이센스 키를 받으세요
패키지 마이그레이션
-Foxit PDF SDKDLL 참조 삭제 .csproj에서
- 모든 개인 NuGet 피드 구성 삭제
-IronPDF NuGet Install-Package:
dotnet add package IronPdf - 네임스페이스 가져오기 업데이트
- 시작 시IronPDF라이센스 키를 설정하세요
코드 마이그레이션
Library.Initialize()및Library.Release()호출 제거ErrorCode검사 대신 try/catch 사용PDFDoc을(를)PdfDocument으로 대체Convert.FromHTML(...)을(를)ChromePdfRenderer으로 대체- 페이지 액세스를
GetPage(i)에서Pages[i]로 업데이트 SaveAs(path, flags)을(를)SaveAs(path)으로 대체Close()을(를)Dispose()또는 using 구문으로 대체- 워터마크 코드를
TextStamper을 사용하도록 업데이트 - 단위를 포인트에서 밀리미터로 변환
테스트
- HTML에서 PDF 출력물이 기대와 일치하는지 확인
- PDF 로딩 및 텍스트 추출 테스트
- 병합 기능 확인
- 워터마크 외관 확인
- 보안/암호화 기능 테스트
- 양식 필드 작업 검증
- 성능 테스트
마이그레이션 이후
-Foxit PDF SDKDLL 삭제
- Foxit 관련 구성 파일 제거
- 문서 업데이트
- 사용하지 않는 도우미 코드 정리

