Hi team,
I written below code to get PDF Page size and its working for A4 but not working for A0, A1, A2 and A3
ERROR : System.IndexOutOfRangeException: ‘At most 4 elements (for any collection) can be viewed in evaluation mode.’
CODE:
// Open document
Document pdfDocument = new Document(PDFCurrentFile);
// Create image stamp
ImageStamp imageStamp = new ImageStamp(ImageCurrentFile);
imageStamp.Background = false;
imageStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Center;
imageStamp.Opacity = 0.2;
// Add stamp to particular page
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
PDFHeight = Convert.ToInt64(pdfDocument.Pages[i].GetPageRect(true).Height);
PDFWidth = Convert.ToInt64(pdfDocument.Pages[i].GetPageRect(true).Width);
//A4 Page - Add default
if (PDFHeight > 700 && PDFHeight < 840) //A3 Page
{
imageStamp.Height = 650;
imageStamp.Width = 470;
}
else if (PDFHeight > 840 && PDFHeight<1185) //A3 Page
{
imageStamp.Height = 800;
imageStamp.Width = 550;
}
else if (PDFHeight > 1185 && PDFHeight < 1680) //A2 Page
{
imageStamp.Height = 1050;
imageStamp.Width = 800;
}
else if (PDFHeight > 1680 && PDFHeight < 2830) //A1 Page
{
imageStamp.Height = 1500;
imageStamp.Width = 1250;
}
else if (PDFHeight > 2830) //A0 Page
{
imageStamp.Height = 2600;
imageStamp.Width = 2300;
}
//Add Image stamp in PDF
pdfDocument.Pages[i].AddStamp(imageStamp);
}
// Save output document
pdfDocument.Save(PDFCurrentFile);
lblMsg.Text = "Image stamp added successfully.\nFile Save at " + PDFCurrentFile;