MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: printing from mathematica to non-postscript printer with gs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17478] Re: printing from mathematica to non-postscript printer with gs
  • From: Robb Aley Allan <rallan at helical.com>
  • Date: Mon, 10 May 1999 01:44:22 -0400
  • Organization: Gulfstream Group, Inc.
  • References: <innclip373454B5.14646F98@helical.com> <Pine.LNX.4.10.9905081456490.18492-100000@wabash.wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

The issue is a little more complicated than that. You are partially right that
the problem is eventually isolated to a problem between the structure of the
postscript emitted by mathematica and what ghostscript expects. Consider the
problem as I have narrowed it:

- mathematica file contains pure text: no formulas, graphics, sound, etc.
- one cell of the file contains text with italicized style
- file uses single Times Roman font

- when printed to disk, the front end prepends a set of postscript definitions
such as
	/Times-Roman findfont 10.000000 scalefont
	[1 0 0 -1 0 0 ] makefont setfont
  BEFORE the standard postscript header "%!PS-Adobe-2.0". This of course
confuses ghostscript and the print system.

- however, additional instructions such as "%%IncludeResource: font
Times-Italic-ISO" appear within the cell with the italicized font.

- when printed, the file is recognized by the print magic filter system as TEXT
(never sees the %!PS header) and postscript text is printed.

- when the  "/Times-Roman findfont 10.000000 scalefont" prepended lines are
removed by hand, the file is recognized as postscript, is rendered, and prints
but ONLY the title cell and the cell with the italicized font prints.

- when the cell with the italicized font is REMOVED, everything prints normally.


This suggests that the front-end is emitting non-standard postscript
instructions to ghostscript or is referring to resources that ghostscript does
not recognize. I have a diff file comparing the version of the file with and
without the italicized cell. Would this help in further isolating the problem?





"P.J. Hinton" wrote:
> 
> On 8 May 1999, Robb Aley Allan wrote:
> 
> > Using redhat 5.2 linux, with ghostscript installed, I am having
> > trouble printing from mathematica, since math'a generates postscript
> > directly. What prints is straight postscript text, not the rendered
> > bitmap. Any ideas?
> 
> I doubt that this is a PostScript programming language problem.  It is
> probably a configuration issue or a problem in the front end's PostScript
> generation facility.
> 
> What sort of infrastructure do you have in place for printing Mathematica
> notebooks?  There are two things to keep in mind.
> 
> First, what is the shell command to which the front end pipes PostScript
> output.  You can tell by summoning the front end print dialog with the
> menu command
> 
>                 File -> Print
> 
> and looking at the second field in the Print Destination subsection of the
> dialog box.  Is it the default value of "lpr", or is it something else?
> 
> Second, what is being used to handle the translation of PostScript into
> your printer's native language format?  Having GhostScript installed by
> itself isn't enough.  Usually you have to have some sort of print
> interceptor tool (like Magic Filter) that checks whether the stream is a
> PostScript file.  If you don't have such a tool in place, the PostScript
> will go straight to the printer.  Hence the raw PostScript code.
> 
> There is a problem in the X front end wherein the front end does not emit
> the PostScript in a totally kosher way.  That is, rather than the
> "%!PS-Adobe" line, a bunch of extraneous resource comments are present.
> The "%!" line is what filtering tools look for in deciding whether the
> stream is a PostScript document.  Because it is not present under these
> circumstances, the filter lets the raw text go to the printer rather than
> piping it through Ghostscript.
> 
> A simple workaround is to write a filter program through which the front
> end can pipe the PostScript to strip the extraneous stuff before the "%!".
> Here is one such piece of code written for C.
> 
> [begin C code listing]
> #include <stdio.h>
> #include <string.h>
> 
> #define BUFSIZE         1024
> #define KEEP            1
> #define DISCARD         0
> #define MAGIC           "%!PS-Adobe-2.0"
> 
> int main(){
>         int state;
>         char buf[BUFSIZE];
> 
>         state = DISCARD;
>         while (fgets(buf, BUFSIZE, stdin) != NULL) {
>                 if (state == DISCARD)
>                         if (!strncmp(buf, MAGIC, strlen(MAGIC) - 1))
>                                 state = KEEP;
>                 if (state == KEEP) {
>                         fprintf(stdout, buf);
>                 }
>         }
>         return 0;
> }
> [end C code listing]
> 
> Suppose we save this code to a file named fecleanps.c and compile it with
> the shell command:
> 
>         cc -o fecleanps fecleanps.c
> 
> This creates an executeable named "fecleanps", which can then be moved to
> a directory on your shell's executable search path (PATH).  Then all you
> need to do is to add the following snippet to your .Xdefaults file
> 
>         XMathematica*printCommand: fecleanps | lpr
> 
> It will set your print dialog to display this command by default when you
> print a notebook.
> 
> Where "lpr" replaced with the shell command you normally use for printing.
> 
> You can post questions specific to Mathematica at
> comp.soft-sys.math.mathematica.  The posting guidelines can be found at
> this URL:
> 
>         http://smc.vnet.net/MathGroup.html
> 
> --
> P.J. Hinton
> Mathematica Programming Group           paulh at wolfram.com
> Wolfram Research, Inc.                  http://www.wolfram.com/~paulh/
> Disclaimer: Opinions expressed herein are those of the author alone.

-- 
Robb Aley Allan
Gulfstream Group, Inc. / Myron A. Minskoff, Inc. / Helical Design
rallan at helical.com / rallan at minskoff.com / allanr at acm.org


  • Prev by Date: Re: Why Round[5/2]=2?
  • Next by Date: Re: Hyperlinks from Word97 to Mathematica notebook.
  • Previous by thread: Re: plotting discontinuity
  • Next by thread: Re: exporting graphics as eps