Pdf 使用ghostscript为postscript文件中的某些页面添加双面打印选项

Pdf 使用ghostscript为postscript文件中的某些页面添加双面打印选项,pdf,printing,ghostscript,postscript,Pdf,Printing,Ghostscript,Postscript,我有一个3页的pdf文件。我想把第一页打印为单面打印,第二页和第三页打印为双面打印(双面打印-第二页在前面,第三页在后面)。如何使用ghostscript生成所需的postscript 我在互联网上找到了下面的解决方案,它可以工作,但它使整个文档成为双面文件 gswin64c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=output.ps -c "<</PSDocOptions (<&

我有一个3页的pdf文件。我想把第一页打印为单面打印,第二页和第三页打印为双面打印(双面打印-第二页在前面,第三页在后面)。如何使用ghostscript生成所需的postscript

我在互联网上找到了下面的解决方案,它可以工作,但它使整个文档成为双面文件

gswin64c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=output.ps -c "<</PSDocOptions (<</Duplex true>> setpagedevice)>> setdistillerparams" -f input.pdf
gswin64c.exe-q-dSAFER-dNOPAUSE-dBATCH-sDEVICE=ps2write-sOutputFile=output.ps-c“setdiverterparams”-f input.pdf
上面一个是文档级选项,我在下面链接的Ghostscript文档页面上找到了页面级选项。

但我找不到PSPageOptions参数的任何示例代码。我试过用下面的命令,但没有运气

gswin64c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out.ps -c "<</PSPageOptions [(/Duplex false)(/Duplex true)(/Duplex true)] /LockDistillerParams true>>setdistillerparams" -f input.pdf
gswin64c.exe-q-dSAFER-dNOPAUSE-dBATCH-sDEVICE=ps2write-sOutputFile=out.ps-c“setdiverterparams”-f input.pdf

我错过什么了吗?有人,请帮帮我。

来自Postscript语言参考手册第三版,第6.1.1节:

 Note: setpagedevice is a page-oriented operator used to control the output process-
  ing of one or more pages of a page description. Any call to setpagedevice implicitly
  invokes erasepage and initgraphics, and thus must precede the descriptions of the
  pages to be affected. If the current device is not a page device, the effect of invoking
  setpagedevice is device-dependent.
因此,请尝试在文本编辑器中打开PostScript文件,并在第1页代码的开头插入“setpagedevice”,在第2页代码的开头插入“setpagedevice”。如6.2.3所述,还有可能需要的选项:

Duplex           boolean       A flag determining whether the output is to be printed duplex (on both sides
                               of the physical medium) or simplex (on one side of the medium only). If this
                               flag is true, pairs of consecutive page images will be printed on opposite sides
                               of a single sheet of medium; if false, each page will be printed on a separate
                               sheet.
                               On device activation, a duplex device always prints the first page on a new
                               sheet of medium; on deactivation, it automatically delivers the last sheet of
                               medium if it has been printed on only one side.
Tumble           boolean      A flag specifying the relative orientation of page images on opposite sides of a
                              sheet of medium in duplex output (that is, when Duplex is true). If Tumble is
                              false, the default user spaces of the two pages are oriented suitably for binding
                              at the left or right, with vertical (y) coordinates in the two spaces increasing
                              toward the same edge of the physical medium. If Tumble is true, the default
                              user spaces are oriented suitably for binding at the top or bottom, with verti-
                              cal coordinates increasing toward opposite edges of the medium. If Duplex is
                              false, the Tumble parameter has no effect.
                               Note that Tumble is defined in terms of default user space—the user space
                               established by setpagedevice. The orientation of default user space with re-
                               spect to the medium is determined by the PageSize and Orientation
                               parameters, possibly altered by the Install procedure. Consistent results are
                               obtained across all devices that support duplexing, regardless of how the me-
                               dium moves through the printing mechanism. However, if a page description
                               alters user space by invoking operators such as rotate, the visual orientation
                               of the material printed on the page may differ from the orientation of default
                               user space.
编辑:现在我明白了。我可以修改您的方法,将字符串插入postscript,但无法使用单工打印机检查双面打印。重影脚本确实按预期将正确的字符串插入%%BeginPageSetup:

-c "<</PSPageOptions [ ( (page +1) print) (<</Duplex true>> setpagedevice) ( (page 2+) print) ] /LockDistillerParams true>> setdistillerparams"
-c“设置蒸馏器参数”
第一个和第三个页面发出页面字符串,我发现setpagedevice位于页面+2的正确位置,所以我希望一切正常。你的第一次尝试非常接近,我也学到了一些东西

page +1>>showpage, press <return> to continue<<
>>showpage, press <return> to continue<<
page 2+>>showpage, press <return> to continue<<
page +1>>showpage, press <return> to continue<<
>>showpage, press <return> to continue<<
page 2+>>showpage, press <return> to continue<<
page +1>>showpage, press <return> to continue<<

page+1>>showpage,按继续>showpage,按继续>showpage,按继续>showpage,按继续>showpage,按继续>showpage,按继续>showpage,按继续作为命令从外部传递,而不是直接编辑ps文件吗?就像我们在文档级别“gswin64c.exe-q-dSAFER-dNOPAUSE-dBATCH-sDEVICE=ps2write-sOutputFile=output.ps-c“setDifferParams”-f input.pdf”中所做的一样,非常接近。我用更好的信息编辑了上面的答案。添加了用于文档中所有3页的命令,以制作单工和双工。“gswin32c.exe-q-dSAFER-dNOPAUSE-dBATCH-sDEVICE=output.ps-c”setDifferParams“-f input.pdf”上述命令仅适用于Windows 32位重影脚本,不适用于64位重影脚本,不确定原因?。同样适用于Linux 64位ghostscript。需要您的输入。我已经在上面的解决方案中添加了双面打印参数,并通过打印出页面进行了验证,无论我将双面打印放在何处,都会按照预期进行背靠背打印。现在,我为2个pdf文件添加了duplex参数,并将其转换为2个单独的postscript,问题是,当我将这些pdf与Ghostscript合并时,它丢失了我们在转换为ps时传递的页面级参数。我尝试了下面建议的合并postscript的答案。为什么它在合并时会丢失附加参数?有什么想法吗?