【问题标题】:Add Duplex option for certain pages in postscript file using ghostscript使用 ghostscript 为 postscript 文件中的某些页面添加 Duplex 选项
【发布时间】:2021-01-15 11:08:45
【问题描述】:

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

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

gswin64c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=output.ps -c "<</PSDocOptions (<</Duplex true>> setpagedevice)>> setdistillerparams" -f input.pdf

上面一个是文档级别选项,我在下面链接的 Ghostscript 文档页面上找到了页面级别选项。 https://www.ghostscript.com/doc/9.50/VectorDevices.htm#PS

但我找不到任何 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

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

【问题讨论】:

    标签: pdf printing ghostscript postscript


    【解决方案1】:

    来自 Postscript 语言参考手册第 3 版。在 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”并在开头插入“> setpagedevice”的第 2 页代码。如 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.
    

    编辑:现在我明白了。除了无法使用我的单面打印机检查双面打印外,我能够修改您将字符串插入后记的方法。 Ghostscript 确实按预期将正确的字符串插入到 %%BeginPageSetup 中:

    -c "<</PSPageOptions [ ( (page +1) print) (<</Duplex true>> setpagedevice) ( (page 2+) print) ] /LockDistillerParams true>> setdistillerparams"
    

    第一页和第三页发出页面字符串,我发现 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<<
    

    【讨论】:

    • 有没有办法从外部作为命令传递而不是直接编辑 ps 文件?就像我们对文档级别所做的那样 "gswin64c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=output.ps -c "> setpagedevice)>> setdistillerparams" - f input.pdf"
    • 哇,这很接近。我用更好的信息编辑了上面的答案。
    • 添加了我用于文档中所有 3 页的命令以制作单面和双面。 "gswin32c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=output.ps -c "> setpagedevice) (> setpagedevice) (> setpagedevice) ] /LockDistillerParams true>> setdistillerparams" -f input.pdf"
    • 上述命令仅适用于 Windows 32 位 Ghostscript 而不是 64 位,不知道为什么?同样适用于 Linux 64 位 ghostscript。
    • 请输入您的意见。我已经使用上述解决方案添加了双工参数,并通过打印页面进行验证,无论我按预期放置双工,它都会背靠背打印。现在,我为 2 个 pdf 文件添加了双工参数并转换为 2 个单独的 postscript,问题是,当我将这些 pdf 与 Ghostscript 合并时,它会丢失我们在转换为 ps 时传递的页面级参数。我尝试了以下建议的答案来合并后记。 stackoverflow.com/a/3445325/13696415 为什么在合并时丢失了添加的参数?有什么想法吗?
    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 2014-07-17
    • 2013-12-23
    • 1970-01-01
    相关资源
    最近更新 更多