Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a bash function to convert a text file to PDF using a combination of a2ps and ps2pdf. To convert exc.cpp I have the following command:

a2ps -M a4 -B -1 -o - exc.cpp | ps2pdf  -sPAPERSIZE=a4 -o exc.pdf -

But I get an error indicating undefined filename the following error output:

GPL Ghostscript 9.04 (2011-08-05)
Copyright (C) 2011 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
[exc.cpp (C++): 2 pages on 2 sheets]
[Total: 2 pages on 2 sheets] sent to the standard output
Error: /undefinedfilename in (.setpdfwrite)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1160/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 9.04: Unrecoverable error, exit code 1

Is there some way to specify to ps2pdf a value for the filename to avoid this error? Or is there a simpler way to convert a text file to PDF?

share|improve this question
up vote 2 down vote accepted

a2ps and ps2pdf do not share the same syntax.

According to UNIX man pages : ps2pdf (1), the basic syntax of ps2pdf is

ps2pdf  [options...] {input.[e]ps|-} [output.pdf|-]

This will work:

a2ps -M a4 -B -1 -o - exc.cpp | ps2pdf -sPAPERSIZE=a4 - exc.pdf
share|improve this answer
    
Thanks, that has fixed it nicely. – Bowie Owens Aug 1 '12 at 2:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .