S
Sudip_inn
Guest
I have many large pdf files which has many pages. i have to split those large pdf into small multiple pdf files.
i have a code which i can use to split large pdf into small multiple pdf files. below code i am using for splitting.
private void SplitAndSaveInterval(string pdfFilePath, string outputPath, int startPage, int interval, string pdfFileName)
{
using (PdfReader reader = new PdfReader(pdfFilePath))
{
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileStream(outputPath + "\\" + pdfFileName + ".pdf", FileMode.Create));
document.Open();
for (int pagenumber = startPage; pagenumber < (startPage + interval); pagenumber++)
{
if (reader.NumberOfPages >= pagenumber)
{
copy.AddPage(copy.GetImportedPage(reader, pagenumber));
}
else
{
break;
}
}
document.Close();
}
}
code taken from Splitting PDF File In C# Using iTextSharp
i got a routine which add page number. routine attached
void AddPageNumber(string fileIn, string fileOut)
{
byte[] bytes = File.ReadAllBytes(fileIn);
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_RIGHT, new Phrase(i.ToString(), blackFont), 568f, 15f, 0);
}
}
bytes = stream.ToArray();
}
File.WriteAllBytes(fileOut, bytes);
}
Now my question is how to incorporate or call AddPageNumber() routine from SplitAndSaveInterval() routine to finally add page number on each page at top right portion of newly generated pdf file.
looking for help and suggestion. thanks
Continue reading...
i have a code which i can use to split large pdf into small multiple pdf files. below code i am using for splitting.
private void SplitAndSaveInterval(string pdfFilePath, string outputPath, int startPage, int interval, string pdfFileName)
{
using (PdfReader reader = new PdfReader(pdfFilePath))
{
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileStream(outputPath + "\\" + pdfFileName + ".pdf", FileMode.Create));
document.Open();
for (int pagenumber = startPage; pagenumber < (startPage + interval); pagenumber++)
{
if (reader.NumberOfPages >= pagenumber)
{
copy.AddPage(copy.GetImportedPage(reader, pagenumber));
}
else
{
break;
}
}
document.Close();
}
}
code taken from Splitting PDF File In C# Using iTextSharp
i got a routine which add page number. routine attached
void AddPageNumber(string fileIn, string fileOut)
{
byte[] bytes = File.ReadAllBytes(fileIn);
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_RIGHT, new Phrase(i.ToString(), blackFont), 568f, 15f, 0);
}
}
bytes = stream.ToArray();
}
File.WriteAllBytes(fileOut, bytes);
}
Now my question is how to incorporate or call AddPageNumber() routine from SplitAndSaveInterval() routine to finally add page number on each page at top right portion of newly generated pdf file.
looking for help and suggestion. thanks
Continue reading...