0

I am trying to create an (encapsulated) Postscript graphic with fonts embedded in the file. For embedding, I use the extrafont package.

While the actual graphic created by the postscript() device is completely fine, embed_fonts() seems to change the paper size to something like A4 or Letter. Why is that? Is there a way to maintain the paper size set by the postscript() device?

Here is a minimal example:

library(extrafont)

postscript( "test.eps", family="Times New Roman", width=4, height=4,
            horizontal = FALSE, onefile=FALSE, paper = "special")

plot(1:10)

dev.off()
embed_fonts("test.eps")

Running this example without the call to embed_fonts() results in a figure with appropriate dimensions (i.e., the desired output). Here is a screenshot from my document viewer:

enter image description here

However, as soon as embed_fonts() is run on this file, the paper size is changed to a fixed paper size:

enter image description here

Is there a way around this? Both embedding the fonts and using .eps is necessary. I suspect it may have to do with the information which is saved in the Postscript file when paper="special" (or the lack thereof). It seems as if embed_fonts() would reset this information on its own.

SimonG
  • 4,701
  • 3
  • 20
  • 31

1 Answers1

0

If you post an eample file, then I can look and tell you what's different, I can't tell you anything about controlling it from R

For EPS (as opposed to PostScript) the program must not request a media size, though it can (in fact must) contain comments which describe the Bounding Box.

So either the file isn't an EPS, or the comments describe it as A4 or 'something'. You haven't explained what it is you are doing with the PostScript program that exhibits a difference between the two sets. By that I mean 'what is your dcument viewer?'

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Whether the file is truly .eps or just .ps, I cannot tell. I essentially followed [these instructions](http://stackoverflow.com/questions/5142842/export-a-graph-to-eps-file-with-r). The `embed_fonts()` function in R is a wrapper for Ghostscript. I managed to produce a properly sized .eps by calling `embed_fonts("test.eps", format="eps2write")`, which I assume calls a different procedure within Ghostscript. Why this is working, I have no idea. My document viewer is Evince, and it shows me a paper size in the file properties that matches the 4x4 inches I specified in R. – SimonG Jun 03 '16 at 16:07
  • Hmm, it may depend on the version of Ghostscript you are using. Older versions may have used the epswrite device, which is deprecated and now no longer shipped. I would very much recommend using the eps2write device anyway, it produces considerably higher quality output. Sounds like you have it working now anyway, so good news :-) FWIW I think Evince uses Ghostscript to display PostScript. – KenS Jun 04 '16 at 07:41