【发布时间】:2012-01-20 13:05:05
【问题描述】:
如何在 .NET 中获取 pdf 文档中页面的方向? pdf 文档可能包含纵向页面和横向页面... 对吗?
任何帮助将不胜感激。
【问题讨论】:
-
这个问题对您有帮助吗? stackoverflow.com/questions/1323737/…
-
您是否已经在使用特定的库来阅读 PDF 或者这是您的问题?
如何在 .NET 中获取 pdf 文档中页面的方向? pdf 文档可能包含纵向页面和横向页面... 对吗?
任何帮助将不胜感激。
【问题讨论】:
使用 iTextSharp 你可以很容易地做到这一点:
''//File to test
Dim TestFileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf")
''//Create an object to read the PDF
Dim Reader As New iTextSharp.text.pdf.PdfReader(TestFileName)
''//Get the page size of the first page (iTextSharp page numbers start at 1)
Dim Rect = Reader.GetPageSize(1)
''//Compare the dimensions of the rectangle returned. For simplicity I'm saying that a square object is portraint, too
Dim IsPortrait = Rect.Height >= Rect.Width
【讨论】:
使用直截了当的方法,您将获得大约 95% 的路程。您将需要可以从 MediaBox 获得的页面尺寸,但如果 CropBox 存在,您确实需要它,因为它可以将纵向页面裁剪为横向页面(反之亦然)。此外,您需要查看页面字典中的 Rotation 条目,因为页面可以在任何指南针点中旋转。为了让生活变得特别有趣,页面的内容可以以任何方向呈现。你可以有一个“直立”的纵向页面,其中的文字是上下颠倒的。
【讨论】: