Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.