如何在 .NET 中获取 pdf 文档中页面的方向?

发布于 2024-12-28 02:19:34 字数 76 浏览 0 评论 0原文

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

任何帮助将不胜感激。

How can i get the orientation of a page within a pdf document in .NET?
A pdf document may contain portrait and landscape pages... Rigth?

Any help would be gratefully appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒尘 2025-01-04 02:19:34

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

Using iTextSharp you can do this pretty easily:

''//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
你没皮卡萌 2025-01-04 02:19:34

通过直接的方法,您将完成大约 95% 的工作。您将需要页面尺寸,您可以从 MediaBox 获取该尺寸,但实际上您需要 CropBox(如果存在),因为它可以将纵向页面裁剪为横向页面(反之亦然)。此外,您需要查看页面字典中的“旋转”条目,因为页面可以在任何罗盘点上旋转。为了让生活变得特别有趣,页面的内容可以以任何方向呈现。您可以有一个“直立”的纵向页面,其中文本倒置。

With straight forward approaches, you'll get about 95% of the way there. You'll need the page dimensions, which you can get from the MediaBox, but really you want the CropBox if it exists because it can crop a portrait page into a landscape page (or vice versa). In addition, you need to look at the Rotation entry in the page dictionary because a page could be rotated in any of the compass points. And just to make life particularly interesting, the content of the page could be rendered in any orientation. You could have an "upright" portrait page with the text drawn upside down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文