When I execute the code below, a new Pdf file with the header is generated successfully.
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
pdf1.Save(@“E:\Pdf1.pdf”);
FileStream fs1 = new FileStream(@“E:\Pdf1.pdf”, FileMode.Open);
FileStream fs2 = new FileStream(@“E:\Pdf2.pdf”, FileMode.OpenOrCreate);
//create PdfPageEditor object
PdfPageEditor pEdit = new PdfPageEditor();
//bind pdf file
pEdit.BindPdf(fs1);
//and assign it to PageSize property of the PdfPageEditor class
pEdit.PageSize = Aspose.Pdf.Kit.PageSize.A4;
pEdit.Alignment = AlignmentType.Center;
pEdit.VerticalAlignment = VerticalAlignmentType.Center;
//save the file
pEdit.Save(fs2);
pEdit = null;
fs1.Close();
fs1.Dispose();
fs2.Close();
fs2.Dispose();
PdfFileStamp fileStamp = new PdfFileStamp(@“E:\Pdf2.pdf”, @“E:\Pdf3.pdf”);
//for version 6.0.0.0 with Pdf.Kit
fileStamp.AddHeader(@“E:\headerimg.gif”, 10, 50, -800);
//for version 6.3.0.0 with Pdf.Facades
//fileStamp.AddHeader(@“E:\headerimg.gif”, 10, 50, 535);
FormattedText HeaderText = new FormattedText(“Header Text”, System.Drawing.Color.Black, System.Drawing.Color.White, Aspose.Pdf.Kit.FontStyle.TimesRoman, EncodingType.Winansi, false, 12);
//for version 6.0.0.0 with Pdf.Kit
fileStamp.AddHeader(HeaderText, 10, 70, 300);
//for version 6.3.0.0 with Pdf.Facades
//fileStamp.AddHeader(HeaderText, 10, 70, 300);
FormattedText HeaderText1 = new FormattedText(DateTime.Now.ToString(“dd-MMM-yyyy”), System.Drawing.Color.Black, System.Drawing.Color.White, Aspose.Pdf.Kit.FontStyle.TimesRoman, EncodingType.Winansi, false, 12);
fileStamp.AddHeader(HeaderText1, 15, 485, 5);
//close PdfFileStamp
fileStamp.Close();
}
catch (Exception ex)
{
}
}
But when I open the File and scroll or try to close it in ADOBE READER 8, I get the following error:
“An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.”
Also when setting the image in the Header, for different versions of DLLs the rightmargin position needs to be changed. Why is it so?
Please let me know as to where I am going wrong.