如何使用iTextsharp获取pdf的页面大小?我正在使用Pdf阅读器获取PDF的页数。请提供用于计算pdf大小的代码
提前谢谢
答案 0 :(得分:3)
查看与来自webified iTextSharp example的PageInformation.cs PageInformation.java对应的chapter 6 iText in Action — 2nd Edition,{{3}}使用iTextSharp输出有关文档的多位信息。中心方法是:
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);
}