Search code examples
postscript

PostScript: not able to execute a macro containing "run" command


Trying make some PostScript functions which I can use later, I need to store those functions (processes in PostScript lingo) in separate files. There is a run command

(foo.bar) run

you can use to do so. but I can't get it to work. this is a sample of a function (itopc.ps):

% this function converts inches to points
/itopc {72 mul} def

and this is a sample of a main script (from here):

%!
(itopc.ps) run

newpath
1 itopc 2 itopc moveto
200 250 lineto
100 300 lineto
2 setlinewidth
stroke
showpage

and this is the error I get using gsview on windows 10:

Error: /invalidfileaccess in --run--
Operand stack:
   (itopc.ps)   (r)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   false   1   %stopped_push   1983   1   3   %oparray_pop   1982   1   3   %oparray_pop   1966   1   3   %oparray_pop   1852   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   1983   1   3   %oparray_pop   --nostringval--
Dictionary stack:
   --dict:1212/1684(ro)(G)--   --dict:0/20(G)--   --dict:82/200(L)--
Current allocation mode is local
Last OS error: No such file or directory

--- Begin offending input ---

the main code and then

--- End offending input ---
file offset = 0
gsapi_run_string_continue returns -101

P.S. It seams like Ghostscript is able to run this script/macro, perfectly fine. but GSview and mac OS X automatic Preview ps to pdf converter are not able to do so! enter image description here


Solution

  • I think I have figure the issue out. As this page has explained, many official PostScript interpreters do not support "run" command for security reasons. At least Apple Preview and Adobe products do not. But GhosScript can. you may just open the file using command:

    gs foo.ps

    on unix like machines and on a Windows machine you may use the PS_View app installed with Ghostscript or Samutrapdf

    with ps2pdf as this post explains you may use the command below to compile the PDF:

    ps2pdf -dNOSAFER foo.ps

    For GSView, on Windows you can go to Options>Advance Configure... and add

    -dNOSAFE

    to GhostScript Options.