Reputation: 156
how to get the page size of the pdf using iTextsharp? i am using Pdf reader to number of pages for getting PDF . please Provide code for calculating the Size of the pdf
thank you in advance
Upvotes: 0
Views: 2234
Reputation: 95908
Have a look at the webified iTextSharp example PageInformation.cs corresponding to PageInformation.java from chapter 6 of iText in Action — 2nd Edition which outputs multiple bits of information about a document using iTextSharp. The central method is this:
public static void Inspect(StringBuilder sb, byte[] pdf, string fileName) {
PdfReader reader = new PdfReader(pdf);
sb.Append(fileName);
sb.Append(Environment.NewLine);
sb.Append("Number of pages: ");
sb.Append(reader.NumberOfPages);
sb.Append(Environment.NewLine);
Rectangle mediabox = reader.GetPageSize(1);
sb.Append("Size of page 1: [");
sb.Append(mediabox.Left);
sb.Append(',');
sb.Append(mediabox.Bottom);
sb.Append(',');
sb.Append(mediabox.Right);
sb.Append(',');
sb.Append(mediabox.Top);
sb.Append("]");
sb.Append(Environment.NewLine);
sb.Append("Rotation of page 1: ");
sb.Append(reader.GetPageRotation(1));
sb.Append(Environment.NewLine);
sb.Append("Page size with rotation of page 1: ");
sb.Append(reader.GetPageSizeWithRotation(1));
sb.Append(Environment.NewLine);
sb.Append("Is rebuilt? ");
sb.Append(reader.IsRebuilt().ToString());
sb.Append(Environment.NewLine);
sb.Append("Is encrypted? ");
sb.Append(reader.IsEncrypted().ToString());
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
}
Upvotes: 3