bash Linux 管道(转换 -> pdf2ps -> lp)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2507596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:51:34  来源:igfitidea点击:

Linux piping ( convert -> pdf2ps -> lp)

linuxbashprinting

提问by alcohol

Ok, so I can print a PDF doing:

好的,所以我可以打印 PDF:

pdf2ps file.pdf - | lp -s

But now I want to use convertto merge several PDF files, I can do this with:

但现在我想用来convert合并多个 PDF 文件,我可以这样做:

convert file1.pdf file2.pdf merged.pdf

which merges file1.pdfand file2.pdfinto merged.pdf, target can be replaced with '-'.

file1.pdffile2.pdf合并到merge.pdf 中,target 可以替换为“-”。

Question

How could I pipe convert into pdf2psand then into lpthough?

我怎么能用管道转换成pdf2ps然后再转换成lp呢?

回答by tonio

convert file1.pdf file2.pdf - | pdf2ps - - | lp -sshould do the job.

convert file1.pdf file2.pdf - | pdf2ps - - | lp -s应该做的工作。

You send the output of the convert command to psf2ps, which in turn feeds its output to lp.

您将 convert 命令的输出发送到 psf2ps,后者又将其输出提供给 lp。

回答by fgb

You can use /dev/stdout like a file:

您可以像使用文件一样使用 /dev/stdout:

convert file1.pdf file2.pdf /dev/stdout | ...

I use gs for merging pdfs like:

我使用 gs 来合并 pdf,例如:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/dev/stdout -f ...

回答by Kurt Pfeifle

Since hidden behind your pdf2pscommand there is a Ghostscript command running (which accomplishes the PDF -> PS conversion), you could also run Ghostscript directly to generate the PostScript:

由于隐藏在你的pdf2ps命令后面有一个 Ghostscript 命令正在运行(它完成 PDF -> PS 转换),你也可以直接运行 Ghostscript 来生成 PostScript:

gs -o output.ps      \
   -sDEVICE=ps2write \
    file1.pdf        \
    file2.pdf        \
    file3.pdf ...

Note, that older GS releases didn't include the ps2writedevice (which generates PostScript Level 2), but only pswrite(which generates the much larger PostScript Level 1). So change the above parameter accordingly if need be.

请注意,较早的 GS 版本不包括ps2write设备(生成 PostScript 级别 2),而仅包括pswrite(生成更大的 PostScript 级别 1)。因此,如果需要,相应地更改上述参数。

Older Ghostscript versions may also need to replace the modern abbreviation of -o -with the more verbose -dNOPAUSE -dBATCH -sOutputFile=/dev/stdout. Only newer GS releases (all after April 2006) know about the -oparameter.

较旧的 Ghostscript 版本可能还需要用-o -更详细的-dNOPAUSE -dBATCH -sOutputFile=/dev/stdout. 只有较新的 GS 版本(均在 2006 年 4 月之后)知道该-o参数。

Now, to directly pipe the PostScript output to the lpcommand, you would have to do this:

现在,要将 PostScript 输出直接通过管道传递给lp命令,您必须执行以下操作:

gs -o -              \
   -sDEVICE=ps2write \
    file1.pdf        \
    file2.pdf        \
    file3.pdf ...    \
| lp -s <other-lp-options>

This may be considerably faster than running pdftkfirst (but this also depends on your input files).

这可能比pdftk首先运行快得多(但这也取决于您的输入文件)。

回答by ghostdog74

convert file1.pdf file2.pdf merged.pdf
pdf2ps merged.pdf - | lp -s