Linux piping ( convert

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

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


convert file1.pdf file2.pdf - | pdf2ps - - | lp -s 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).

链接地址: http://www.djcxy.com/p/8224.html

上一篇: 如何合并Git中的特定提交

下一篇: Linux管道(转换