【问题标题】:How can i get the orientation of a page within a pdf document in .NET?如何在 .NET 中获取 pdf 文档中页面的方向?
【发布时间】:2012-01-20 13:05:05
【问题描述】:

如何在 .NET 中获取 pdf 文档中页面的方向? pdf 文档可能包含纵向页面和横向页面... 对吗?

任何帮助将不胜感激。

【问题讨论】:

标签: c# .net vb.net pdf


【解决方案1】:

使用 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

【讨论】:

    【解决方案2】:

    使用直截了当的方法,您将获得大约 95% 的路程。您将需要可以从 MediaBox 获得的页面尺寸,但如果 CropBox 存在,您确实需要它,因为它可以将纵向页面裁剪为横向页面(反之亦然)。此外,您需要查看页面字典中的 Rotation 条目,因为页面可以在任何指南针点中旋转。为了让生活变得特别有趣,页面的内容可以以任何方向呈现。你可以有一个“直立”的纵向页面,其中的文字是上下颠倒的。

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 1970-01-01
      • 2020-06-27
      • 2010-10-14
      • 2017-12-14
      • 2010-12-28
      • 2011-01-02
      • 2012-03-14
      • 1970-01-01
      相关资源
      最近更新 更多