Skip to main content
 首页 » 编程设计

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

2024年02月23日14lori

如何在 .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