2012-01-20 42 views
1

如何在.NET中的pdf文檔中獲取頁面的方向? pdf文檔可能包含縱向和橫向頁面... Rigth?如何在.NET中的pdf文檔中獲取頁面的方向?

任何幫助將不勝感激。

+0

這個問題可以幫助你嗎? http://stackoverflow.com/questions/1323737/pdfsharp-wrong-pdf-page-settings-when-document-is-opened-in-acrobat – Niklas

+2

你是否已經在使用特定的庫來閱讀PDF文件或者是你的問題? –

回答

3

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

隨着直線前進接近,你會得到的方式出現約95%。您需要頁面尺寸,您可以從MediaBox中獲得這些尺寸,但是如果它存在的話,確實需要CropBox,因爲它可以將縱向頁面裁剪爲橫向頁面(反之亦然)。此外,您需要查看頁面字典中的旋轉條目,因爲可以在任何指南針點中旋轉頁面。只是爲了讓生活特別有趣,頁面的內容可以呈現任何方向。你可以有一個「直立」的肖像頁面,並將文本上下顛倒。

相關問題