在iTextSharp中确定属性,例如PDF是单面还是双面

我正在使用iTextSharp来阅读和管理PDF文档。 诸如为背景或徽标和支持者盖印覆盖物之类的东西。 PDF是声明文件,所以我不能举一个例子。 我想知道如何查看PDF的设置,以查看PDF文件是单面还是双面,以及那种信息。 任何帮助或建议将不胜感激。 目前我测试第二页的某些标准,这是一个糟糕而糟糕的方法。 提前谢谢,快乐编码!

双工模式存储在/Duplex键下的文档/ViewerPreferences字典中。 它支持三个值, /DuplexFlipLongEdge/DuplexFlipShortEdge/Simplex 。 您可以使用以下代码来检查:

 //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))); } } 

我知道它2年后,但我只是花了几个小时搜索,发现这……但最终发现……

我创建了一个运行此脚本的按钮(弹出打印机对话框,如果可用,则选择双面打印…请注意,选择另一台打印机将删除此预选项。如果您翻转,则也会将“Long”更改为“Short”。 .. q8)

var pp = this.getPrintParams(); pp.DuplexType = pp.constants.duplexTypes.DuplexFlipLongEdge; this.print(pp);