I have used iTextSharp to add footer note to existing pdf. Issue is when I access the pdf file and creates another file from its content, the orientation of pages gets changed and the contents get cut off. The code I have used is:
//using itextsharp
string oldFile = dtroldp + strfn;
if (File.Exists(oldFile))
{
string newFile = strpath + "sys_" + docid + strext;
PdfReader reader = new PdfReader(oldFile);
int numberOfPages = reader.NumberOfPages;
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
Document document = new Document();
// open the writer
PdfWriter writer = PdfWriter.GetInstance(document, fs);
writer.PageEvent = new PDFFooter();
document.Open();
for (int i = 1; i <= numberOfPages; i++)
{
document.SetPageSize(reader.GetPageSizeWithRotation(1));
document.NewPage();
PdfContentByte cb = writer.DirectContent;
//// select the font properties
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(bf, 32);
// write the text in the pdf content
cb.BeginText();
cb.EndText();
PdfImportedPage page = writer.GetImportedPage(reader, i);
cb.AddTemplate(page, 0, 0);
}
document.Close();
fs.Close();
writer.Close();
reader.Close();
}
Can anyone suggest me what wrong I have done? Why the orientation automatically gets changed?