确定,例如,如果PDF是单面或双面的iTextSharp的性质 [英] Determine properties such as if PDF is Simplex or Duplex in iTextSharp
问题描述
我使用iTextSharp的阅读和管理PDF文档。世事如冲压覆盖的背景或标志和支持者。在PDF的是声明文件,所以我不能举一个例子。我想知道如何查看PDF的设置,看PDF文件是单面或双面,以及诸如此类的信息。任何帮助或建议,将不胜感激。此刻,我测试的第二页的一定的标准,这是可以做到这一点和糟糕的方式。在此先感谢,和快乐编码!
I am using iTextSharp for reading and managing PDF documents. Things such as stamping overlays for the background or logos and backers. The PDF's are statement files, so I cannot give an example. I am wondering how to view the settings of the PDF to see if the PDF file is Simplex or Duplex, and that sort of information. Any help or suggestions would be appreciated. At the moment I test for certain criteria of second page, and this is a poor and bad way to do this. Thanks in advance, and happy coding!
推荐答案
双工模式存储在文档的 / ViewerPreferences
的 /双面
项下字典。它支持三个值, / DuplexFlipLongEdge
, / DuplexFlipShortEdge
和 /单
。您可以使用下面的代码来检查这一点:
The duplex mode is stored in the document's /ViewerPreferences
dictionary under the /Duplex
key. It supports three values, /DuplexFlipLongEdge
, /DuplexFlipShortEdge
, and /Simplex
. You can use the code below to inspect this:
//Assume false by default since this was introduced in PDF 1.7
Boolean isDuplex = false;
//Bind a reader to our file
using (var r = new PdfReader(testFile)) {
//Get the view preferences
var prefs = r.Catalog.GetAsDict(PdfName.VIEWERPREFERENCES);
//Make sure we found something
if (prefs != null) {
//Get the duplex key
var duplex = prefs.Get(PdfName.DUPLEX);
//Make sure we got something and it is one of the duplex modes
isDuplex = (duplex != null && (duplex.Equals(PdfName.DUPLEXFLIPLONGEDGE) || duplex.Equals(PdfName.DUPLEXFLIPSHORTEDGE)));
}
}
这篇关于确定,例如,如果PDF是单面或双面的iTextSharp的性质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!