ARCHIVED: In Unix, how do I convert a PostScript file to text?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

A PostScript file is a text file that describes how to place text and graphics on paper. While there are many programs available for generating PostScript files from text, converting a PostScript file back to normal text is more difficult. Extracting the raw text and graphics that originally composed the document from the special instructions in the PostScript file is not a straightforward task.

Ideally, you should try to obtain a copy of the original text from the creator of the PostScript file. If you're unable to do so, you can try using the script below, which invokes Ghostscript, the PostScript and PDF interpreter and previewer:

  1. Copy the following text and save it to a file; make sure long lines are saved as single lines:
     #!/bin/sh if ( test $# -eq 0 ) then gs -q -dNODISPLAY -dNOBIND -dWRITESYSTEMDICT -dSIMPLE ps2ascii.ps - -c quit elif ( test $# -eq 1 ) then gs -q -dNODISPLAY -dNOBIND -dWRITESYSTEMDICT -dSIMPLE ps2ascii.ps $1 -c quit else gs -q -dNODISPLAY -dNOBIND -dWRITESYSTEMDICT -dSIMPLE ps2ascii.ps $1 -c quit >$2 fi
  2. Add execute permission to the file. For example, if you saved the script as ps2ascii, at the command prompt, enter:
     chmod u+x ps2ascii
  3. Run the script on your PostScript file. For example, if the PostScript file is named myfile.ps, and you want the output saved to myfile.txt, at the command prompt, enter:
     ./ps2ascii myfile.ps > myfile.txt

Note: The results will likely not be perfect, because of the difficulty involved in extracting the text, so some editing of the output file may be necessary to make it presentable.

At Indiana University, Ghostscript is installed on Big Red II, Karst, and Mason. To invoke it from the command line, use the gs command. For more about Ghostscript, see the gs manual page.

Research computing support at IU is provided by the Research Technologies division of UITS. To ask a question or get help regarding Research Technologies services, including IU's research supercomputers and research storage systems, and the scientific, statistical, and mathematical applications available on those systems, contact UITS Research Technologies. For service-specific support contact information, see Research computing support at IU.

This is document abcd in the Knowledge Base.
Last modified on 2018-01-18 08:55:57.