Thursday, 12 September 2013

Split PDF into multiple PDFs using iTextsharp

Split PDF into multiple PDFs using iTextsharp

public int SplitAndSave(string inputPath, string outputPath)
{
FileInfo file = new FileInfo(inputPath);
string name = file.Name.Substring(0, file.Name.LastIndexOf("."));
using (PdfReader reader = new PdfReader(inputPath))
{
for (int pagenumber = 1; pagenumber <= reader.NumberOfPages;
pagenumber++)
{
string filename = pagenumber.ToString() + ".pdf";
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new
FileStream(outputPath + "\\" + filename,
FileMode.Create));
document.Open();
copy.AddPage(copy.GetImportedPage(reader, pagenumber));
document.Close();
}
return reader.NumberOfPages;
}
}
I want to split the Pdf in to multiple PDFs with 50 pages
interval.(Suppoose If there are 400 pages PDF, I want 8 pdfs). The above
code is splitting every page into a pdf. Please help me...I'm using
asp.net with iTextSharp.

No comments:

Post a Comment