C#에서 PDF로 내보내는 방법 | IronPDF
Sumatra PDF에서 IronPDF로의 마이그레이션은 데스크톱 뷰어 응용 프로그램을 통한 외부 프로세스 관리에서 완전한 PDF 생성, 조작 및 추출 기능을 갖춘 네이티브 .NET 라이브러리 통합으로 PDF 워크플로를 변환합니다. 이 가이드는 외부 종속성, AGPLv3 카피레프트 의무 및 Sumatra PDF가 뷰어/프린터이며 개발 라이브러리가 아니라는 근본적인 제한을 제거하는 완전한 단계별 마이그레이션 경로를 제공합니다.
왜 Sumatra PDF에서 IronPDF로 마이그레이션해야 하는가
Sumatra PDF이해하기
Sumatra PDF는 그 단순성과 속도로 유명한 경량 오픈소스 WindowsPDF 리더/프린터입니다. 또한 EPUB, MOBI, CBZ/CBR, FB2, CHM, XPS 및 DjVu 파일도 표시합니다. 그러나 Sumatra PDF는 추적 및 인쇄 이상의 PDF 파일 생성이나 조작에 필요한 기능을 제공하지 않으며, 공식 .NET SDK나 NuGet 패키지가 없습니다 — 커뮤니티 래퍼는 단순히 SumatraPDF.exe에 의존합니다.
Sumatra PDF는 독립 실행형 Windows데스크톱 뷰어/프린터 애플리케이션이지 개발 라이브러리가 아닙니다. .NET 응용 프로그램에서 Sumatra PDF를 사용하고 있다면, 다음 스스로 일 것이 분명합니다:
- PDF를 표시하기 위해 외부 프로세스로
SumatraPDF.exe실행 - 커맨드 라인을 통해 PDF 인쇄 (
-print-to-default,-print-to "<printer>") - 사용자가 설치해야 하는 종속성으로 의존
Sumatra PDF통합의 주요 문제
| 문제 | 영향 |
|---|---|
| 라이브러리가 아님 | 프로그래밍 방식으로 PDF를 생성하거나 편집할 수 없음 |
| 외부 프로세스 | SumatraPDF.exe;를 생성해야 합니다. 프로세스 내 API 없음 |
| AGPLv3 라이선스 | 강한 카피레프트 (일부 파일은 BSD 라이선스); bundling into closed-source products imposes obligations most commercial vendors avoid |
| 사용자 의존성 | 사용자 (또는 설치 프로그램)이 SumatraPDF.exe를 디스크에 놓아야 함 |
| CLI 전용 | 문서화된 명령줄 인수로 제한됨 |
| 보기 / 인쇄 전용 | PDF를 생성, 편집, 조작할 수 없음 |
| Windows 전용 | Linux 또는 macOS빌드 없음 |
Sumatra PDFvsIronPDF비교
| 기능 | Sumatra PDF | IronPDF |
|---|---|---|
| 유형 | 애플리케이션 | 라이브러리 |
| PDF 읽기 | 예 | 예 |
| PDF 생성 | 아니요 | 예 |
| PDF 편집 | 아니요 | 예 |
| 통합 | 제한됨 (독립 실행형) | 애플리케이션 내 완전한 통합 |
| 라이선스 | AGPLv3 (일부 파일 BSD) | 상업적 |
| PDF 생성 | 아니요 | 예 |
| PDF 편집 | 아니요 | 예 |
| HTML to PDF | 아니요 | 예 |
| 병합/분할 | 아니요 | 예 |
| 워터마크 | 아니요 | 예 |
| 디지털 서명 | 아니요 | 예 |
| 양식 채우기 | 아니요 | 예 |
| 텍스트 추출 | 아니요 | 예 |
| .NET 통합 | None | 내부 지원 |
| 웹 애플리케이션 | 아니요 | 예 |
IronPDF는 Sumatra PDF와 달리 특정 데스크톱 응용 프로그램이나 외부 프로세스에 구속되지 않습니다. 개발자가 C#에서 PDF 문서를 동적으로 생성, 편집 및 조작할 수 있는 유연한 라이브러리를 제공합니다. 외부 프로세스에서 분리됨으로써 눈에 띄는 이점을 제공합니다—단순하고 적응성이 뛰어나며, 단지 보기만 사용하는 것 이상의 다양한 응용 프로그램에 적합합니다.
모던 .NET을 목표로 하는 팀에게 IronPDF는 Sumatra PDF의 외부 프로세스 오버헤드와 AGPLv3 카피레프트 의무를 제거하는 네이티브 라이브러리 통합을 제공합니다.
시작하기 전에
필수 조건
- .NET 환경: .NET Framework 4.6.2+ 또는 .NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGet 접근 권한: NuGet 패키지를 설치할 수 있는 능력
- IronPDF 라이선스: ironpdf.com에서 라이선스 키를 획득하세요
설치
# Install IronPDF
dotnet add package IronPdf
라이선스 구성
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";' Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"완전한 API 참조
네임스페이스 변경
// Before:Sumatra PDF(external process)
using System.Diagnostics;
using System.IO;
// After: IronPDF
using IronPdf;Imports System.Diagnostics
Imports System.IO
Imports IronPdf핵심 기능 매핑
| Sumatra PDF 접근 방식 | IronPDF 동등 | 노트 |
|---|---|---|
Process.Start("SumatraPDF.exe", pdfPath) | PdfDocument.FromFile() | PDF 로드 |
| 명령줄 인수 | 네이티브 API 메서드 | CLI 필요 없음 |
외부 pdftotext.exe | pdf.ExtractAllText() | 텍스트 추출 |
외부 wkhtmltopdf.exe | renderer.RenderHtmlAsPdf() | HTML to PDF |
-print-to-default 인수 | pdf.Print() | 인쇄 |
| 불가능 | PdfDocument.Merge() | PDF 병합 |
| 불가능 | pdf.ApplyWatermark() | 워터마크 |
| 불가능 | pdf.SecuritySettings | 암호 보호 |
코드 마이그레이션 예제
예제 1: HTML에서 PDF로 변환
이전 (Sumatra PDF):
//Sumatra PDFis a standalone Windowsapp (AGPLv3) — there is NO official NuGet package.
// Download SumatraPDF.exe from https://www.sumatrapdfreader.org/and shell out to it.
// Sumatra is a viewer/printer only; it cannot convert HTML to PDF, so you must use a
// separate HTML-to-PDF tool (e.g. wkhtmltopdf) and then view/print with Sumatra.
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFcannot directly convert HTML to PDF
// You'd need to use wkhtmltopdf or similar, then view in Sumatra
string htmlFile = "input.html";
string pdfFile = "output.pdf";
// Using wkhtmltopdf as intermediary
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "wkhtmltopdf.exe",
Arguments = $"{htmlFile} {pdfFile}",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
// Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile);
}
}
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlContent = "<h1>Hello World</h1><p>This isHTML to PDFconversion.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
이 예제는 근본적인 아키텍처 차이를 보여줍니다. Sumatra PDF는 HTML을 직접 PDF로 변환할 수 없습니다—중간자로 wkhtmltopdf 같은 외부 도구를 사용한 다음, Sumatra를 별도의 프로세스로 실행해야 결과를 볼 수 있습니다. 여기에는 두 개의 외부 실행 파일과 여러 프로세스 실행이 필요합니다.
IronPDF는 세 줄의 코드만으로 ChromePdfRenderer와 RenderHtmlAsPdf()를 사용합니다. 외부 도구 없음, 프로세스 관리 없음, 중간 파일 없음. PDF는 메모리에서 직접 생성되고 SaveAs()로 저장됩니다. HTML에서 PDF로의 문서에서 포괄적인 예제를 참조하세요.
예제 2: PDF 열기 및 표시
이전 (Sumatra PDF):
//Sumatra PDFis a standalone Windowsapp (AGPLv3) — no official NuGet package.
// Download SumatraPDF.exe from https://www.sumatrapdfreader.org/and call it via Process.Start.
// Useful CLI flags: -page <n>, -print-to-default, -print-to "<printer>", -print-settings, -silent.
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string pdfPath = "document.pdf";
//Sumatra PDFexcels at viewing PDFs
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "SumatraPDF.exe",
Arguments = $"\"{pdfPath}\"",
UseShellExecute = true
};
Process.Start(startInfo);
// Optional: Open specific page
// Arguments = $"-page 5 \"{pdfPath}\""
}
}
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}");
//IronPDF can manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf");
// Open with default PDF viewer
Process.Start(new ProcessStartInfo("modified.pdf") { UseShellExecute = true });
}
}
Sumatra PDF는 PDF 보기에서 우수하지만, 명령줄 인수를 사용한 외부 프로세스 실행에 제한되어 있습니다. 프로그램적으로 PDF 내용을 액세스할 수 없습니다—단지 표시할 수 있을 뿐입니다.
IronPDF는 PdfDocument.FromFile()을 사용하여 PDF를 로드하여 완전한 프로그래밍 접근을 제공합니다. 문서의 속성을 읽고, 문서를 조작하며, 변경 사항을 저장하고, 시스템의 기본 PDF 뷰어로 열 수 있습니다. 핵심 차이점은 IronPDF가 단순한 프로세스 인수만이 아니라 실제 API를 제공한다는 것입니다. 더 많은 정보를 보려면 튜토리얼을 참조하세요.
예제 3: PDF에서 텍스트 추출하기
이전 (Sumatra PDF):
//Sumatra PDFis a standalone Windowsviewer (AGPLv3) — no official NuGet package
// and no programmatic text-extraction API. To extract text you must shell out to a
// separate tool such as pdftotext (Xpdf / Poppler).
using System;
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFis a viewer, not a text extraction library
// You'd need to use PDFBox, iTextSharp, or similar for extraction
string pdfFile = "document.pdf";
// This would require external tools like pdftotext
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "pdftotext.exe",
Arguments = $"{pdfFile} output.txt",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
string extractedText = File.ReadAllText("output.txt");
Console.WriteLine(extractedText);
}
}
이후 (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);
// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst Page Text:\n{pageText}");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Extract text from all pages
Dim allText As String = pdf.ExtractAllText()
Console.WriteLine("Extracted Text:")
Console.WriteLine(allText)
' Extract text from specific page
Dim pageText As String = pdf.ExtractTextFromPage(0)
Console.WriteLine(vbCrLf & "First Page Text:" & vbCrLf & pageText)
End Sub
End ModuleSumatra PDF는 텍스트 추출 라이브러리가 아닌 뷰어입니다. 텍스트를 추출하려면 pdftotext.exe와 같은 외부 커맨드 라인 도구를 사용하고, 프로세스를 생성하고, 완료될 때까지 기다리고, 출력 파일을 읽고, 관련된 모든 파일 I/O 및 정리를 처리해야 합니다.
IronPDF는 문서 전체를 위한 ExtractAllText() 또는 특정 페이지를 위한 ExtractTextFromPage(0)로 네이티브 텍스트 추출을 제공합니다. 외부 프로세스 없음, 임시 파일 없음, 정리 필요 없음.
기능 비교
| 기능 | Sumatra PDF | IronPDF |
|---|---|---|
| :생성: | ||
| URL을 PDF로 변환 | 아니요 | 예 |
| 텍스트에서 PDF로 | 아니요 | 예 |
| 이미지에서 PDF로 | 아니요 | 예 |
| :조작: | ||
| PDF 분할 | 아니요 | 예 |
| 페이지 회전 | 아니요 | 예 |
| 페이지 삭제 | 아니요 | 예 |
| 페이지 재정렬 | 아니요 | 예 |
| :콘텐츠: | ||
| 머리글/바닥글 추가 | 아니요 | 예 |
| 텍스트 스탬프 | 아니요 | 예 |
| 이미지 스탬프 | 아니요 | 예 |
| :보안: | ||
| 디지털 서명 | 아니요 | 예 |
| 암호화 | 아니요 | 예 |
| 권한 설정 | 아니요 | 예 |
| :추출: | ||
| 이미지 추출 | 아니요 | 예 |
| :플랫폼: | ||
| Linux | 아니요 | 예 |
| macOS | 아니요 | 예 |
| 웹 앱 | 아니요 | 예 |
| Azure/AWS | 아니요 | 예 |
이동 후 새로운 기능
IronPDF로 마이그레이션 후, Sumatra PDF가 제공할 수 없는 기능을 얻습니다:
HTML로부터 PDF 생성
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>");
pdf.SaveAs("invoice.pdf");Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>")
pdf.SaveAs("invoice.pdf")PDF 병합
var pdf1 = PdfDocument.FromFile("chapter1.pdf");
var pdf2 = PdfDocument.FromFile("chapter2.pdf");
var pdf3 = PdfDocument.FromFile("chapter3.pdf");
var book = PdfDocument.Merge(pdf1, pdf2, pdf3);
book.SaveAs("complete_book.pdf");Dim pdf1 = PdfDocument.FromFile("chapter1.pdf")
Dim pdf2 = PdfDocument.FromFile("chapter2.pdf")
Dim pdf3 = PdfDocument.FromFile("chapter3.pdf")
Dim book = PdfDocument.Merge(pdf1, pdf2, pdf3)
book.SaveAs("complete_book.pdf")워터마크
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(@"
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>");
pdf.SaveAs("watermarked.pdf");Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>")
pdf.SaveAs("watermarked.pdf")비밀번호 보호
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>");
pdf.SecuritySettings.OwnerPassword = "owner123";
pdf.SecuritySettings.UserPassword = "user456";
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SaveAs("protected.pdf");Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>")
pdf.SecuritySettings.OwnerPassword = "owner123"
pdf.SecuritySettings.UserPassword = "user456"
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SaveAs("protected.pdf")마이그레이션 체크리스트
사전 마이그레이션
- 모든 Sumatra 프로세스 실행 식별 (
Process.Start("SumatraPDF.exe", ...)) - 문서 인쇄 워크플로우 (
-print-to-default인수) - 사용된 Sumatra 명령줄 인수 주석 달기
- ironpdf.com에서IronPDF라이선스 키 획득
코드 업데이트
IronPdfNuGet Install-Package- Sumatra 프로세스 코드 제거
Process.Start("SumatraPDF.exe", pdfPath)를PdfDocument.FromFile(pdfPath)로 대체- 외부
wkhtmltopdf.exe호출을ChromePdfRenderer.RenderHtmlAsPdf()로 대체 - 외부
pdftotext.exe호출을pdf.ExtractAllText()로 대체 -print-to-default프로세스 호출을pdf.Print()로 대체- 애플리케이션 시작 시 라이선스 초기화 추가
테스트
- PDF 생성 품질 테스트
- 출력 기능 확인
- 모든 대상 플랫폼에서 테스트
- Sumatra 종속성이 남아 있지 않음 확인
정리
- 설치자에서 Sumatra 제거
- 문서 업데이트
- 시스템 요구 사항에서 Sumatra 제거

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.