开发者

Linux piping ( convert -> pdf2ps -> lp)

Ok, so I can print a PDF doing:

pdf2ps file.pdf - | lp -s

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

convert file1.pdf file2.pdf merged.pdf

which merges file1.pdf and file2.pdf into merged.pdf, target can be replaced with '-'.

Question

开发者_C百科

How could I pipe convert into pdf2ps and then into lp though?


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

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


You can use /dev/stdout like a file:

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

I use gs for merging pdfs like:

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


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

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

Note, that older GS releases didn't include the ps2write device (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.

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 -o parameter.

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

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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜