How To Split Pdf Documents Using ITextSharp in C#

In Today?s life cycle PDF has a important role because it doesn?t require any special package to be installed to view it on system, mobile devices, IPOD or IPAD.

Sometimes pdf documents have scanned images, large text data. We need to extract some of the pages for sharing with someone else i.e. friends or any team members. ItextSharp can help us to achieve this.

Following is the sample code which can split the pdf pages to individual file.

[csharp]
using (PdfReader reader = new PdfReader(pdfFileName))
{
for (int pagenumber = 1; pagenumber <= reader.NumberOfPages; pagenumber++)
{
string filename = pagenumber.ToString() + “.pdf”;

Document document = new Document();
PdfCopy pdfCopy = new PdfCopy(document, new FileStream(@”c:\temp\” + filename, FileMode.Create));

document.Open();

pdfCopy.AddPage(copy.GetImportedPage(reader, pagenumber));

document.Close();
}
}
[/csharp]


Posted

in

by

Tags: