C#에서 iTextSharp과 IronPDF 사이의 PDF 분할 비교
Full Comparison
Looking for a detailed feature-by-feature breakdown? See how IronPDF stacks up against Itext on pricing, HTML support, and licensing.
PDF (Portable Document Format) 파일은 문서를 공유하고 표현하는 데 널리 사용되며, PDF를 여러 파일로 분할해야 할 때가 있습니다. 특정 페이지를 추출하거나 대형 문서를 작은 섹션으로 나누거나 각 장에 대해 개별 파일을 생성하려는 경우, PDF 분할은 다양한 시나리오에서 유용한 작업이 될 수 있습니다.
이 기사에서는 C#을 사용하여 PDF를 분할하는 방법을 배웁니다. C#은 다재다능하고 강력한 언어이며, PDF를 비교적 쉽게 조작할 수 있는 여러 라이브러리가 있습니다. PDF를 C#에서 분할하기 위해 다음 두 라이브러리를 탐색합니다.
C#에서 iTextSharp을 사용하여 PDF를 분할하는 방법
- 먼저 iText7 라이브러리를 설치하십시오.
- 입력 PDF 파일에서 PdfReader를 만듭니다.
- PdfDocument를 사용하여 PDF 콘텐츠를 작업하십시오.
- 각 분할 파일의 페이지 수를 계산합니다.
- 초기 페이지 범위 값을 설정합니다.
- 각 분할 파일을 처리하기 위해 루프를 사용합니다.
- 현재 분할 파일에 대한 새로운 PdfDocument를 만듭니다.
- 원본 문서에서 새 문서로 페이지를 복사합니다.
- 다음 반복을 위해 페이지 범위 값을 업데이트합니다.
- 완료된 출력 PDF를 저장합니다.
- 모든 파일이 생성될 때까지 반복합니다.
- 지정된 분할 파일 수에 대해 프로세스를 계속합니다.
IronPDF

IronPDF는 PDF 파일 작업을 위해 설계된 강력한 C# 라이브러리입니다. PDF 문서에서 생성, 수정, 추출 기능을 제공합니다. 개발자는 처음부터 PDF를 생성하거나 기존 PDF를 편집하고 병합 또는 분할할 수 있습니다. 또한, IronPDF는 HTML 콘텐츠를 PDF 형식으로 변환하는 데 뛰어나며, 보고서나 문서를 생성하는 데 유용합니다. 디지털 서명, 보안 기능 및 고품질 출력 지원을 통해 IronPDF는 .NET 애플리케이션에서 PDF 관련 작업을 단순화합니다.
iTextSharp

iTextSharp (iText 7)은 .NET Framework에서 PDF 파일 작업에 널리 사용되는 라이브러리입니다. PDF 문서에서 프로그래밍적으로 콘텐츠를 생성, 수정 및 추출하기 위한 강력한 기능을 제공합니다. 개발자는 iTextSharp를 사용하여 PDF에 텍스트, 이미지, 테이블 및 기타 그래픽 요소를 추가할 수 있습니다. 또한, 문서 조립, 디지털 서명 및 아카이브 및 접근성 표준 준수를 지원합니다. 원래 Java 라이브러리로 시작한 iTextSharp는 .NET으로 포팅되었으며, 활발한 개발자 및 사용자 커뮤니티를 가지고 있습니다.
IronPDF 라이브러리 설치
Visual Studio에서 패키지 관리자 콘솔을 사용하여 IronPDF NuGet 패키지를 설치하려면 다음 단계를 따르세요:
- Visual Studio에서 도구 -> NuGet 패키지 관리자 -> 패키지 관리자 콘솔로 이동하세요.
-
다음 명령을 사용하여 IronPDF NuGet 패키지를 설치하십시오:
Install-Package IronPdf
이는 IronPDF 패키지와 그 종속성을 프로젝트에 다운로드하고 설치할 것입니다. 설치가 완료되면, C# 프로젝트에서 PDF 관련 작업을 위해 IronPDF를 사용할 수 있습니다.
대안으로는 Visual Studio에서 NuGet 패키지 관리자를 사용하거나, 패키지를 직접 프로젝트 파일에 추가할 수 있습니다. 또 다른 방법은 공식 웹사이트에서 패키지를 다운로드하여 프로젝트에 수동으로 추가하는 것입니다. 각 방법은 C# 프로젝트에 PDF 관련 기능을 위한 IronPDF를 통합하는 간단한 방법을 제공합니다.
iTextSharp 라이브러리 설치
Visual Studio에서 패키지 관리자 콘솔을 사용하여 iTextSharp를 설치하려면 다음 단계를 따르시면 됩니다:
- Visual Studio에서 도구 -> NuGet 패키지 관리자 -> 패키지 관리자 콘솔로 이동하세요.
-
다음 명령을 사용하여 iTextSharp NuGet 패키지를 설치하십시오:
Install-Package itext7Install-Package itext7SHELL
이는 iTextSharp 패키지와 그 종속성을 프로젝트에 다운로드하고 설치할 것입니다. 설치가 완료되면, C# 프로젝트에서 PDF 작업을 위해 iTextSharp를 사용할 수 있습니다.
IronPDF를 사용하여 C#에서 PDF 문서 분할
우리는 IronPDF를 사용하여 하나의 PDF 파일을 여러 개의 PDF 파일로 분할할 수 있습니다. 이를 수행하는 간단한 방법을 제공합니다. 다음 코드는 입력용 소스 PDF 파일을 받아 여러 개의 PDF 파일로 분할할 것입니다.
using IronPdf;
class Program
{
static void Main(string[] args)
{
string file = "input.pdf";
// The folder to save the split PDFs
string outputFolder = "output_split";
int numberOfSplitFiles = 3; // Specify how many parts you want to split the PDF into
// Call the SplitPdf method to split the PDF
SplitPdfUsingIronPDF(file, outputFolder, numberOfSplitFiles);
}
static void SplitPdfUsingIronPDF(string inputPdfPath, string outputFolder, int numberOfSplitFiles)
{
// Load the input PDF
PdfDocument sourceFile = PdfDocument.FromFile(inputPdfPath);
// Initialize page range values
int firstPage = 1;
int lastPage = 2;
int totalPageInOneFile = sourceFile.PageCount / numberOfSplitFiles;
for (int i = 1; i <= numberOfSplitFiles; i++)
{
// Copy multiple pages into a new document
PdfDocument newSplitPDF = sourceFile.CopyPages(firstPage, lastPage);
// Generate the output file path
string name = $@"{outputFolder}\SplitPDF_IronPDF_{i}.pdf";
// Save the new split PDF
newSplitPDF.SaveAs(name);
// Update page range values for the next iteration
firstPage = lastPage + 1;
lastPage += totalPageInOneFile;
}
}
}
using IronPdf;
class Program
{
static void Main(string[] args)
{
string file = "input.pdf";
// The folder to save the split PDFs
string outputFolder = "output_split";
int numberOfSplitFiles = 3; // Specify how many parts you want to split the PDF into
// Call the SplitPdf method to split the PDF
SplitPdfUsingIronPDF(file, outputFolder, numberOfSplitFiles);
}
static void SplitPdfUsingIronPDF(string inputPdfPath, string outputFolder, int numberOfSplitFiles)
{
// Load the input PDF
PdfDocument sourceFile = PdfDocument.FromFile(inputPdfPath);
// Initialize page range values
int firstPage = 1;
int lastPage = 2;
int totalPageInOneFile = sourceFile.PageCount / numberOfSplitFiles;
for (int i = 1; i <= numberOfSplitFiles; i++)
{
// Copy multiple pages into a new document
PdfDocument newSplitPDF = sourceFile.CopyPages(firstPage, lastPage);
// Generate the output file path
string name = $@"{outputFolder}\SplitPDF_IronPDF_{i}.pdf";
// Save the new split PDF
newSplitPDF.SaveAs(name);
// Update page range values for the next iteration
firstPage = lastPage + 1;
lastPage += totalPageInOneFile;
}
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim file As String = "input.pdf"
' The folder to save the split PDFs
Dim outputFolder As String = "output_split"
Dim numberOfSplitFiles As Integer = 3 ' Specify how many parts you want to split the PDF into
' Call the SplitPdf method to split the PDF
SplitPdfUsingIronPDF(file, outputFolder, numberOfSplitFiles)
End Sub
Private Shared Sub SplitPdfUsingIronPDF(ByVal inputPdfPath As String, ByVal outputFolder As String, ByVal numberOfSplitFiles As Integer)
' Load the input PDF
Dim sourceFile As PdfDocument = PdfDocument.FromFile(inputPdfPath)
' Initialize page range values
Dim firstPage As Integer = 1
Dim lastPage As Integer = 2
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim totalPageInOneFile As Integer = sourceFile.PageCount / numberOfSplitFiles
For i As Integer = 1 To numberOfSplitFiles
' Copy multiple pages into a new document
Dim newSplitPDF As PdfDocument = sourceFile.CopyPages(firstPage, lastPage)
' Generate the output file path
Dim name As String = $"{outputFolder}\SplitPDF_IronPDF_{i}.pdf"
' Save the new split PDF
newSplitPDF.SaveAs(name)
' Update page range values for the next iteration
firstPage = lastPage + 1
lastPage += totalPageInOneFile
Next i
End Sub
End Class
코드 설명
이 코드의 목적은 주어진 PDF 파일을 IronPDF 라이브러리를 사용하여 여러 개의 작은 PDF 파일로 분할하는 것입니다. SplitPdfUsingIronPDF 메서드는 이 기능을 달성하기 위해 정의됩니다.
메서드 매개변수
inputPdfPath: 입력 PDF 파일의 경로를 나타내는 문자열(예: "input.pdf").outputFolder: 분할된 PDF 파일이 저장될 출력 폴더를 나타내는 문자열(예: "output_split").numberOfSplitFiles: 원본 PDF를 몇 개의 작은 PDF 파일로 분할할지를 나타내는 정수.
분할 프로세스
SplitPdfUsingIronPDF 메서드 내부:
- 지정된
inputPdfPath에서 PDF를 로드하여sourceFile라는 이름의PdfDocument객체가 생성됩니다. - 두 개의 정수 변수
firstPage과lastPage가 초기화됩니다. 이는 분할을 위한 페이지 범위를 나타냅니다. - 원본 PDF의 총 페이지 수를 지정된
numberOfSplitFiles로 나누어totalPageInOneFile이 계산됩니다. - 1부터
numberOfSplitFiles까지 반복문이 실행됩니다. - 새로운
PdfDocument객체가newSplitPDF라는 이름으로 생성됩니다. firstPage에서lastPage(포함)까지의 페이지가sourceFile에서newSplitPDF로 복사됩니다.- 결과적으로 작은 PDF가 "SplitPDF_IronPDF_1.pdf" (첫 번째 분할의 경우)와 같은 파일명으로 지정된 출력 폴더에 저장됩니다.
- 다음 반복을 위해
firstPage과lastPage값이 업데이트됩니다.
참고사항
"input.pdf"를 실제 입력 PDF 파일 경로로 교체해야 합니다. IronPDF 라이브러리가 프로젝트에 제대로 설치되고 참조되어 있는지 확인하세요.
출력 파일은 다음과 같이 생성됩니다:

iTextSharp를 사용하여 C#에서 PDF 분할
이제, 우리는 iTextSharp를 사용하여 PDF 문서를 여러 개의 PDF 파일로 분할할 것입니다. 다음 코드는 소스 파일을 입력으로 받아 PDF 문서를 여러 작은 파일로 분할할 것입니다.
using System;
using iText.Kernel.Pdf;
class Program
{
static void Main(string[] args)
{
string inputPath = "input.pdf";
// Output PDF files path (prefix for the generated files)
string outputPath = "output_split";
int numberOfSplitFiles = 3; // Specify how many parts you want to split the PDF into
// Call the SplitPdf method to split the PDF
SplitPdfUsingiTextSharp(inputPath, outputPath, numberOfSplitFiles);
}
static void SplitPdfUsingiTextSharp(string inputPdfPath, string outputFolder, int numberOfSplitFiles)
{
using (PdfReader reader = new PdfReader(inputPdfPath))
{
using (PdfDocument doc = new PdfDocument(reader))
{
// Calculate the number of pages for each split file
int totalPageInOneFile = doc.GetNumberOfPages() / numberOfSplitFiles;
int firstPage = 1;
int lastPage = totalPageInOneFile;
for (int i = 1; i <= numberOfSplitFiles; i++)
{
// Generate the output file path
string filename = $@"{outputFolder}\SplitPDF_iTextSharp_{i}.pdf";
// Create a new document and attach a writer for the specified output file
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(filename)))
{
// Copy pages from the original document to the new document
doc.CopyPagesTo(firstPage, lastPage, pdfDocument);
}
// Update page range values for the next iteration
firstPage = lastPage + 1;
lastPage += totalPageInOneFile;
}
}
}
}
}
using System;
using iText.Kernel.Pdf;
class Program
{
static void Main(string[] args)
{
string inputPath = "input.pdf";
// Output PDF files path (prefix for the generated files)
string outputPath = "output_split";
int numberOfSplitFiles = 3; // Specify how many parts you want to split the PDF into
// Call the SplitPdf method to split the PDF
SplitPdfUsingiTextSharp(inputPath, outputPath, numberOfSplitFiles);
}
static void SplitPdfUsingiTextSharp(string inputPdfPath, string outputFolder, int numberOfSplitFiles)
{
using (PdfReader reader = new PdfReader(inputPdfPath))
{
using (PdfDocument doc = new PdfDocument(reader))
{
// Calculate the number of pages for each split file
int totalPageInOneFile = doc.GetNumberOfPages() / numberOfSplitFiles;
int firstPage = 1;
int lastPage = totalPageInOneFile;
for (int i = 1; i <= numberOfSplitFiles; i++)
{
// Generate the output file path
string filename = $@"{outputFolder}\SplitPDF_iTextSharp_{i}.pdf";
// Create a new document and attach a writer for the specified output file
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(filename)))
{
// Copy pages from the original document to the new document
doc.CopyPagesTo(firstPage, lastPage, pdfDocument);
}
// Update page range values for the next iteration
firstPage = lastPage + 1;
lastPage += totalPageInOneFile;
}
}
}
}
}
Imports System
Imports iText.Kernel.Pdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim inputPath As String = "input.pdf"
' Output PDF files path (prefix for the generated files)
Dim outputPath As String = "output_split"
Dim numberOfSplitFiles As Integer = 3 ' Specify how many parts you want to split the PDF into
' Call the SplitPdf method to split the PDF
SplitPdfUsingiTextSharp(inputPath, outputPath, numberOfSplitFiles)
End Sub
Private Shared Sub SplitPdfUsingiTextSharp(ByVal inputPdfPath As String, ByVal outputFolder As String, ByVal numberOfSplitFiles As Integer)
Using reader As New PdfReader(inputPdfPath)
Using doc As New PdfDocument(reader)
' Calculate the number of pages for each split file
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim totalPageInOneFile As Integer = doc.GetNumberOfPages() / numberOfSplitFiles
Dim firstPage As Integer = 1
Dim lastPage As Integer = totalPageInOneFile
For i As Integer = 1 To numberOfSplitFiles
' Generate the output file path
Dim filename As String = $"{outputFolder}\SplitPDF_iTextSharp_{i}.pdf"
' Create a new document and attach a writer for the specified output file
Using pdfDocument As New PdfDocument(New PdfWriter(filename))
' Copy pages from the original document to the new document
doc.CopyPagesTo(firstPage, lastPage, pdfDocument)
End Using
' Update page range values for the next iteration
firstPage = lastPage + 1
lastPage += totalPageInOneFile
Next i
End Using
End Using
End Sub
End Class
코드 설명
이 코드는 iTextSharp를 사용하여 큰 PDF 파일을 더 작은 청크로 나누는 방법을 보여줍니다. 각 작은 PDF 문서에는 원본 문서의 일부가 포함됩니다.
iTextSharp를 사용하여 PDF 분할하기
- 주요 기능은
SplitPdfUsingiTextSharp메서드 안에 캡슐화됩니다. - 위의 메서드는 세 가지 매개변수:
inputPdfPath,outputFolder및numberOfSplitFiles를 받습니다.
PdfReader 및 PdfDocument 사용
SplitPdfUsingiTextSharp 메서드 내부:
- 지정된
inputPdfPath에서 PDF를 로드하여reader라는 이름의PdfReader객체가 생성됩니다. reader을 사용하여doc라는 이름의PdfDocument객체가 초기화됩니다.- 원본 PDF의 총 페이지 수를
numberOfSplitFiles로 나누어 각 작은 PDF가 포함할 페이지 수를 결정합니다.
분할 프로세스
1부터 numberOfSplitFiles까지 반복문이 실행됩니다.
- 지정된 출력 폴더에 'SplitPDF_iTextSharp_1.pdf'(첫 번째 분할의 경우)와 같은 파일명으로 새로운 작은 PDF 파일이 생성됩니다.
- 이 새로운 PDF 문서(
pdfDocument) 내에서 원본doc에서 페이지가 복사됩니다. firstPage에서lastPage(포함)까지 복사됩니다.- 작은 PDF가 저장됩니다.
- 다음 반복을 위해
firstPage및lastPage값이 업데이트됩니다.
참고사항
프로젝트에 iTextSharp 라이브러리가 올바르게 설치되고 참조되었는지 확인하십시오. "input.pdf"를 입력 PDF 파일의 실제 경로로 바꾸십시오.

비교
iTextSharp와 IronPDF를 사용하여 두 분할 방법을 비교하기 위해 여러 요소에 따라 평가해 봅시다:
- 사용 용이성:
- iTextSharp: iTextSharp 방법은 PdfReader, PdfDocument, 및 PdfWriter를 생성하는 것을 포함합니다. 페이지 범위를 계산하고 페이지를 새 문서로 복사합니다. 이 접근법은 iTextSharp API의 이해가 필요합니다.
- IronPDF: IronPDF 방법은 소스 파일에서 PdfDocument를 생성하고, 페이지를 복사하여 새 파일에 저장하는 것을 포함합니다. 더 간단한 API를 가지고 있습니다.
- 코드 가독성:
- iTextSharp: 코드는 더 많은 단계가 포함되어 있어 읽기에 약간 길고 복잡할 수 있습니다.
- IronPDF: 더 적은 단계와 메서드 호출로 인해 코드가 간결하고 더 읽기 쉽습니다.
- 성능:
- iTextSharp: PdfDocument 인스턴스를 반복적으로 생성하고 삭제함으로 인해 성능이 영향을 받을 수 있습니다.
- IronPDF: 효율적인 페이지 복사로 인해 단계가 적고 성능이 더 좋습니다.
- 메모리 사용:
- iTextSharp: 여러 PdfDocument 인스턴스를 생성하면 더 많은 메모리가 소비됩니다.
- IronPDF: 단순화된 접근법으로 인해 메모리 효율이 더 좋습니다.
결론
결론적으로, iTextSharp와 IronPDF 모두 C#에서 PDF 파일을 나누는 데 있어 강력한 솔루션을 제공합니다. 각각 장점이 있습니다. IronPDF는 단순성, 가독성, 및 더 간단한 접근법으로 인한 잠재적인 우수한 성능으로 두드러집니다.
다양성과 사용 용이성 사이의 균형을 찾는 개발자는 IronPDF를 매력적인 선택으로 발견할 수 있습니다. 또한, IronPDF는 무료 체험판을 제공합니다. 궁극적으로 iTextSharp와 IronPDF 간의 선택은 개별 프로젝트 요구 사항과 선호하는 개발 스타일에 따라 달라집니다.
자주 묻는 질문
C#에서 원래의 서식을 유지하며 PDF를 어떻게 분할할 수 있나요?
C#에서 IronPDF를 사용하여 서식을 보존하면서 PDF를 분할할 수 있습니다. IronPDF는 PDF를 로드하고 분할할 페이지 범위를 지정할 수 있는 간단한 API를 제공하여 결과 PDF에서도 원본 서식이 유지되도록 합니다.
C#에서 PDF를 분할할 때 iTextSharp과 IronPDF 간의 주요 차이점은 무엇인가요?
주요 차이점은 사용의 용이성과 성능에 있습니다. IronPDF는 더 적은 단계의 간단한 API를 제공하여 서식을 잃지 않고 PDF를 분할하기 쉽게 만듭니다. 반면에 iTextSharp은 PdfReader, PdfDocument, PdfWriter 등 여러 인스턴스를 생성해야 하므로 더 복잡할 수 있습니다.
C#을 사용하여 PDF에서 특정 페이지를 추출할 수 있나요?
네, IronPDF를 사용하면 C#에서 PDF의 특정 페이지를 쉽게 추출할 수 있습니다. PDF를 로드하고 원하는 페이지 번호를 지정하면 IronPDF가 이 페이지를 새 PDF 문서로 추출하여 저장할 수 있습니다.
IronPDF는 다른 PDF 라이브러리와 비교하여 코드 가독성을 어떻게 개선하나요?
IronPDF는 명확하고 간결한 API를 제공함으로써 코드 가독성을 개선하여 여러 클래스나 객체에 대한 필요성을 줄입니다. 이로 인해 분할과 같은 PDF 조작 작업에 필요한 코드가 간소화되고 유지보수가 용이해집니다.
라이브러리를 구매하기 전에 C#에서 PDF 분할 기능을 테스트할 수 있나요?
네, IronPDF는 무료 체험판을 제공하여 PDF 분할 기능 및 기타 기능을 테스트할 수 있습니다. 이 체험 기간 동안 기능과 성능을 평가한 후 구매 결정을 내릴 수 있습니다.
문서를 분할할 PDF 라이브러리를 선택할 때 고려해야 할 요소는 무엇인가요?
PDF 라이브러리를 선택할 때 사용의 용이성, API의 간단함, 성능, 원본 문서 서식 유지 능력 등을 고려하세요. IronPDF는 사용자 친화적인 API와 효율적인 성능 덕분에 종종 선호됩니다.
IronPDF를 Visual Studio C# 프로젝트에 어떻게 설치하나요?
Visual Studio C# 프로젝트에서 IronPDF를 설치하려면 NuGet 패키지 관리자 콘솔에서 Install-Package IronPdf 명령을 사용하세요. 또한 NuGet 패키지 관리자 UI를 통해 추가하거나 IronPDF의 공식 웹사이트에서 다운로드할 수도 있습니다.
PDF를 분할하면 품질이나 서식에 영향을 미칠 수 있나요?
IronPDF로 PDF를 분할하면 원본 문서의 품질과 서식이 보존됩니다. IronPDF의 효율적인 처리로 인해 원본 콘텐츠의 무결성이 유지됩니다.



