5

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?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
alcohol
  • 22,596
  • 4
  • 23
  • 21

4 Answers4

7

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.

tonio
  • 10,355
  • 2
  • 46
  • 60
  • This works indeed. However, I just found out convert doesn't properly merge my pdf files. Argh. The content is empty. So, onto posting my next question I guess : > – alcohol Mar 24 '10 at 12:49
  • 1
    Final solution: `pdftk file1.pdf file2.pdf cat output - | pdf2ps - - | lp -s` (after installing pdftk) – alcohol Mar 24 '10 at 13:10
  • @tonio: You do not seem to be aware that both, `convert` as well as `pdf2ps` employ Ghostscript in the background. So instead of running two different wrappers around the same Ghostscript in a pipeline which would make the input data have to go through Ghostscript two times (if it works ***AT ALL***), you would be better off to run a single Ghostscript command to convert multiple PDF files into one PostScript file or data stream.... – Kurt Pfeifle Mar 30 '16 at 13:38
0

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 ...
fgb
  • 18,439
  • 2
  • 38
  • 52
0

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).

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
-1
convert file1.pdf file2.pdf merged.pdf
pdf2ps merged.pdf - | lp -s
ghostdog74
  • 327,991
  • 56
  • 259
  • 343