Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a basic PostScript script by hand

I wanted to try and manually code a PostScript file. Why? Why not. From Wikipedia, I copied and pasted their basic Hello World program for PostScript which is:

%!PS
/Courier             % name the desired font
20 selectfont        % choose the size in points and establish 
                     % the font as the current one
72 500 moveto        % position the current point at 
                     % coordinates 72, 500 (the origin is at the 
                     % lower-left corner of the page)
(Hello world!) show  % stroke the text in parentheses
showpage             % print all on the page

When I try to open it in GIMP, I get

Opening 'Hello World.ps' failed. Could not interpret file 'Hello World.ps'

I can use ImageMagick to convert the file

convert "Hello World.ps" "Hello World.pdf"
convert "Hello World.ps" "Hello World.eps"

The PDF opens successfully and displays 'Hello World' in Courier. The EPS yields the same error as the PS.

  • Is there something wrong with the syntax of the PS file?

  • Are PS files just not meant to be viewed directly, and should instead be viewed in a containing format like PDF?

  • Is GIMP just not able to handle this particular format of PS file?

like image 735
chiliNUT Avatar asked Feb 06 '15 21:02

chiliNUT


People also ask

What does PostScript code look like?

The character "%" is used to introduce comments in PostScript programs. As a general convention, every PostScript program should start with the characters "%!

How do I start a PostScript file?

Here's a tip: People wonder—does the PS come before or after the signature? Since a postscript is an addition that comes after a letter is completed, it should always follow the signature. Including a PS has long been a direct mail marketing strategy.

How do you draw a line in PostScript?

The "stroke" command at the end is what tells PostScript to actually draw the line; without this command PostScript will not print anything. (This is useful later if you want to make a shape and fill it, but not draw the outline.)


1 Answers

To answer your questions, one by one:

  1. You PostScript file is completely OK.

  2. PostScript files can be viewed directly if you use a PostScript-capable viewer. (BTW: PDF may be regarded as a 'container format' -- but it never embeds a PostScript file for 'viewing'...)

  3. For Gimp to be able and handle PS/EPS files, you need a working Ghostscript (installation link) on your system.

The same as point '3.' is true for your convert command: ImageMagick cannot handle PS/EPS or PDF input files unless there is a functional Ghostscript installation available on the local system. This would work as a so-called 'delegate', employed by ImageMagick to handle file formats which it cannot handle itself. A delegate converts such a format into a raster file, which ImageMagick in turn can then take over for further processing.

To check for available ImageMagick delegates, run these commands:

convert -list delegate

convert -list delegate | grep -Ei --color '(eps|ps|pdf)' 
like image 138
Kurt Pfeifle Avatar answered Sep 22 '22 21:09

Kurt Pfeifle