Questions tagged [postscript]

PostScript is a Turing-complete page description programming language, designed and developed by Adobe. There are three major releases: PostScript Level 1, released in 1984. PostScript Level 2 (1991) contained several important improvements. PostScript 3 (1997) is the latest version.

PostScript Overview

PostScript is a reverse-polish stack-based, dynamically-typed, dynamic-namespacing, scripting language with built-in primitives for generating rendered images from vector descriptions. PostScript employs the same "Adobe Image Model" as the PDF file format.

PostScript is used as an output format by many programs since it is designed to be easily machine-generated.

Like LISP, PostScript is homoiconic and code and data share the same representation. Procedures can take procedures as data and yield procedures as results, lending itself to techniques from concatenative-programming as well.

General Description of PostScript

PostScript is a Turing-complete general programming language, designed and developed by Adobe Systems. Many of the ideas which blossomed in PostScript had been cultivated in projects for Xerox and Evans & Sutherland.

Its main real-world application historically is as a page description language, or in its single-page EPS form a vector-graphics image-description language. It is dynamically-typed, dynamically-scoped, and stack-based which leads to a mostly Reverse Polish syntax.

There are three major releases of PostScript.

  1. PostScript Level 1 — this was released to the market in 1984 as the resident operating system of the Apple LaserWriter laser printer, inaugurating the Desktop Publishing Era.
  2. PostScript Level 2 — released in 1991, this contained several important improvements to Level 1, including support for image decompression, in-RIP separation, auto-growing dictionaries, garbage collection, Named Resources, binary encodings of the PostScript program stream itself.
  3. PostScript 3 — the latest and perhaps most widely adopted version was released in 1997. It too contains several import improvements over Level 2 such as Smooth Shading. The term “level” has been dropped.

Though PostScript is typically used as a page description language -- and therefore is implemented inside many printers to generate raster images -- it can also be used for other purposes. As a quick reverse-polish calculator with more memorable operator names than dc. As an output format generated by another program (usually in some other language).

Though PostScript files are typically 7-bit-clean ASCII, there exist several kinds of binary encoding described in the level 2 standard. And being programmable, a program may implement its own arbitrarily-complex encoding scheme for itself. There is an International Obfuscated Postscript Competition, somewhat less active than the C one.

Online References

FAQs

Books

  • Postscript Language Reference Manual, 1ed, 1985. Recommended for its small size, and easy operator index from the summary pages (missing from later editions).

  • Real World Postscript. Chapters by various authors on various topics, including excellent coverage of halftoning.

Curriculum

Read the documentation in this order to easily learn postscript:

  1. Paul Bourke's excellent tutorial: http://paulbourke.net/dataformats/postscript/

  2. Blue Book, first half, the original official tutorial:
    http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF

  3. Green Book, how to use postscript effectively:
    http://www-cdf.fnal.gov/offline/PostScript/GREENBK.PDF

  4. Thinking in Postscript, 'nuff said: http://wwwcdf.pd.infn.it/localdoc/tips.pdf

  5. Mathematical Illustrations. Start small, build big. The math behind Bezier Curves. The Hodgman-Sutherland polygon clipping algorithm. Affine transformations and non-linear transformations of the path. 3D drawing and Gouraud shading. From the preface:

Which [of the many tools to help one produce mathematical graphics] to choose apparently involves a trade-off between simplicity and quality, in which most go for what they perceive to be simplicity. The truth is that the trade-off is unnecessary — once one has made a small initial investment of effort, by far the best thing to do in most situations is to write a program in the graphics programming language PostScript. There is practically no limit to the quality of the output of a PostScript program, and as one acquires experience the difficulties of using the language decrease rapidly. The apparent complexity involved in producing simple figures by programming in PostScript, as I hope this book will demonstrate, is largely an illusion. And the amount of work involved in producing more complicated figures will usually be neither more nor less than what is necessary.

Installation and/or Setup

The authentic Adobe PostScript interpreters are available in high-end printers, the Display PostScript (DPS) product, and the Acrobat Distiller product. As authors of the standard, these products are considered "the standard implementation" for the purpose of describing differences among PostScript implementations.

The Standard interface to the interpreter defined in the PLRM is the program-stream which may be either text or binary depending upon the details of the underlying channel or OS/controller. Acrobat Distiller has a GUI front-end to select the input postscript program and render its output as a pdf. Distiller also has some limited support for using the output text stream for reporting errors and other program output. GSView provides a similar GUI front-end for a similar workflow using Ghostscript as the interpreter.

Ghostscript and Xpost both work in a command-line mode. The postscript program file to run can be mentioned on the command-line (gs program.ps or xpost program.ps) which will open a graphics window to display the graphical output. Options may be used to render the graphics somewhere else like a disk file or suppress the graphics entirely and use postscript just as a text scripting language.

The various interpreters each have their own installation and setup instructions and it would be wasteful (and prone to falling out-of-date) to reproduce them here.

Freely-available PostScript interpreters

  • Ghostscript is available for all major platforms and Linux distributions, in source or binary form, under the GNU license or under other license arrangements with the authors, Artifex software. Ghostscript implements the full PostScript 3 standard.

  • Xpost is available in source form for all major platforms, under the BSD-3-clause license. It implements the Level-1 standard with some Level-2 extensions and some DPS extensions.

There is more introductory material that was formerly part of the SO Documentation project.

1059 questions
13
votes
3 answers

Viewing the stack, dictionaries, etc. on PostScript for debugging purposes

How can I do debugging in PostScript? I can use GhostView/GhostScript on Linux, but I can't view the stack, dictionaries, etc.
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
12
votes
2 answers

How can I remove all images from a PDF?

I want to remove all images from a PDF file. The page layouts should not change. All images should be replaced by empty space. How can this be achieved with the help of Ghostscript and the appropriate PostScript code?
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
12
votes
5 answers

How do I send data to a modern printer? PDF, PostScript, HPGL, etc

I am trying to understand my options for communicating programmatically with a printer to get something printed from application software. In other words, what happens when the user tells my application they want to print something. I understand the…
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
12
votes
1 answer

embedFonts complains about “Unknown device: pswrite”

Running embedFonts on some EPS file I created, I get an error message: > embedFonts("foo.ps") Unknown device: pswrite Unrecoverable error: undefined in .uninstallpagedevice Operand stack: defaultdevice Error in embedFonts("foo.ps") : status 1…
MvG
  • 57,380
  • 22
  • 148
  • 276
11
votes
3 answers

How can you get the height metric of a string in PostScript?

You can obtain the width of a string in the current font with stringwidth and although this actually pushes offset coordinates on the stack, the y-value always seems to be useless. Is there a way to determine the exact height of a string, that may…
dreamlax
  • 93,976
  • 29
  • 161
  • 209
11
votes
2 answers

unicode in postscript

Is there anyway to use unicode strings (most probably in UTF-8, but could be any encoding) in PostScript? So far, i've been using this function to transforms fonts to Latin1 encoding: /latinize { findfont dup length dict begin { 1 index /FID…
Javier
  • 60,510
  • 8
  • 78
  • 126
10
votes
4 answers

Java printing directly to a Postscript network printer

I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd like to send directly to a networked PS printer. Is there an easy way (i.e. just popping open a port and sending the text) to print this, bypassing all of the…
David Jaquay
  • 1,032
  • 1
  • 8
  • 11
10
votes
1 answer

Modify existing PDF to add "Page N of NNN" footer

How can I use pdftk either from the command line (or preferably from Ruby) to add page numbers to the bottom of a pre-existing PDF? I'm looking for this format: Page 1 of 2 Page 2 of 2
jrhicks
  • 14,759
  • 9
  • 42
  • 57
10
votes
1 answer

How to tell if a .woff font has hinting?

I have a .woff font that is rendering very poorly on Windows platforms. I suspect this may be due to a lack of hinting information but I need to make sure. Can you recommend a tool that can inspect the font file and tell me if hinting metrics exist…
Zaqx
  • 1,401
  • 8
  • 17
10
votes
1 answer

How to get Ghostscript to use embedded fonts in PDF

gs -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH \ -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf I'm using (trying anyway) to use Ghostscript to reduce my PDF file size. The command above looks like it works, it reduces…
Sheldon Ross
  • 5,364
  • 7
  • 31
  • 37
10
votes
1 answer

Why are postscript files being created in Python directory?

I have a python script which imports some Python modules, such as bs4, json, os, requests, signal, sys, and time. Sometimes I notice in my PWD the following files: $ ls -la -rw-rw-r-- 1 dotancohen dotancohen 12429677 Jun 26 11:37 bs4 -rw-rw-r-- 1…
dotancohen
  • 30,064
  • 36
  • 138
  • 197
10
votes
4 answers

Is it possible in Ghostscript to add watermark to every page in PDF

I convert PDF -> many JPEG and many JPEG -> many PDF using ghostscript. I need to add watermark text on every converted JPEG (PDF) page. Is it possible using only Ghostscript and PostScript? The only way I found: gswin32c -q -sDEVICE=pdfwrite…
radistao
  • 14,889
  • 11
  • 66
  • 92
9
votes
3 answers

Tracking Code Into a PDF or PostScript File

Is there a way to track when a PDF is opened? Perhaps by embedding some script into the pdf itself? I saw the question below, and I suppose the answer is "no" for javascript, but I am wondering if this is possible at all. Google analytics tracking…
speedplane
  • 15,673
  • 16
  • 86
  • 138
9
votes
4 answers

How to use non-ASCII characters in Matlab figures (for use in LaTeX doc)?

I am using including Matlab-drawn figures into LaTeX. My usual workflow is as following: Script in matlab creates figure(s), I tweak what I find needs to be tweaked in visual figure editor, Figure is saved as .fig (for future modification) and .eps…
triazotan
  • 2,192
  • 1
  • 22
  • 32
9
votes
8 answers

Can't add new Redirected Port in Windows 7 after installing RedMon

My operating system is Windows 7 32bit. I installed RedMon1.7, Ghostscript 8.71 and GSview 4.9; installations were successful. I went to Add New Local Printer in Windows Devices and Printers, clicked on Create A New Port, and selected Redirected…
Zerone
  • 566
  • 4
  • 10
  • 24
1
2
3
70 71