pdf device and font family "Arial" / Or: Change font name (not font) in PDF

fonts, pdf, r, typeface

Solution

You need to set a new font family for use with `pdf()`. This requires you to have Adobe Font Metric files (`*.afm` files) for the fonts you wish to use. You can convert the `.tty` files to `.afm` ones or find `.afm` files for Arial on the interweb if you don't already have them.

Arial <- Type1Font(family = "Arial",
                   metrics = c("ArialMT.afm",
                               "arial-BoldMT.afm", 
                               "Arial-ItalicMT.afm",
                               "Arial-BoldItalicMT.afm"))

where the character vector `metrics` contains the paths to the relevant `.afm` files, The files should be specified in this order:

- plain face

- bold face

- italic face

- bold-italic face

The you use the `pdfFonts()` function to add a mapping to these new fonts

pdfFonts(Arial = Arial)

where `Arial` is the object produced by `Type1Font()` earlier.

The final step is to use the `family` argument in `pdf()` which refers to one of the existing families as defined by `pdfFonts()`:

pdf("testArial.pdf", family = "Arial")
plot(1:10, 1:10)
dev.off()

I haven't tried this as I don't have Arial on my system nor too many `.afm` files lying around, but I pieced this together from several sources:

- Paul Murrell and Brian Ripley (2006) Non-standard fonts in PostScript and PDF graphics. R News, 6(2):41-47. PDF

- A posting by David L. Carlson on the R mailing list from earlier this year.

An alternative depending on how your system is set-up is to a Cairo-based PDF device as that will use the functions of your system to identify and load fonts based simply on their name. See `?cairo_pdf` and then the Cairo Fonts section of `?X11` for details.

Problem

I have a problem with typefaces and PDF-Output in R. On this windows machine there is no Helvetica and the Font used by the device seems to be Arial as you can see below. The simple problem is, that Arial is used (as I want it to be) but editing the PDF-File it says Helvetica is used. How can I get R to write the correct Name into the PDF-file. `pdf(...,family="Arial")` won't work, as this family is not known (grDevices version 2.15.1). Or can I substitude this font in the PDF afterwards, creating a file with the font I want? R-PDF-Output Comparision from this Article:Arial vs. Helvetica

Original source

Related problems