Rev 52782 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/grDevices/man/pdf.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2009 R Core Development Team% Distributed under GPL 2 or later\name{pdf}\alias{pdf}\encoding{UTF-8}\title{PDF Graphics Device}%% The definitive doc is the source :-)%% ../../../main/devices.c & ../../../main/devPS.c\description{\code{pdf} starts the graphics device driver for producing PDFgraphics.}\usage{pdf(file = ifelse(onefile, "Rplots.pdf", "Rplot\%03d.pdf"),width, height, onefile, family, title, fonts, version,paper, encoding, bg, fg, pointsize, pagecentre, colormodel,useDingbats, useKerning, fillOddEven, maxRasters)}\arguments{\item{file}{a character string giving the name of the file.For use with \code{onefile=FALSE} give a C integer format suchas \code{"Rplot\%03d.pdf"} (the default in that case).(See \code{\link{postscript}} for further details.)}\item{width, height}{the width and height of the graphics region ininches. The default values are \code{7}.}\item{onefile}{logical: if true (the default) allow multiple figuresin one file. If false, generate a file with name containing the pagenumber for each page. Defaults to \code{TRUE}.}\item{family}{the font family to be used, see\code{\link{postscript}}. Defaults to \code{"Helvetica"}.}\item{title}{title string to embed as the \samp{/Title} field in thefile. Defaults to \code{"R Graphics Output"}.}\item{fonts}{a character vector specifying \R graphics font familynames for fonts which will be included in the PDF file. Defaults to\code{NULL}.}\item{version}{a string describing the PDF version that will berequired to view the output. This is a minimum, and will beincreased (with a warning) if necessary. Defaults to \code{"1.4"},but see \sQuote{Details}.}\item{paper}{the target paper size. The choices are\code{"a4"}, \code{"letter"}, \code{"legal"} (or \code{"us"}) and\code{"executive"} (and these can be capitalized), or \code{"a4r"}and \code{"USr"} for rotated (\sQuote{landscape}).The default is \code{"special"}, which means that the \code{width}and \code{height} specify the paper size. A further choice is\code{"default"}; if this is selected, thepapersize is taken from the option \code{"papersize"}if that is set and as \code{"a4"} if it is unset or empty.Defaults \code{"special"}.}\item{encoding}{the name of an encoding file. See\code{\link{postscript}} for details. Defaults to \code{"default"}.}\item{bg}{the initial background color to be used. Defaults to\code{"transparent"}.}\item{fg}{the initial foreground color to be used. Defaults to\code{"black"}.}\item{pointsize}{the default point size to be used. Strictlyspeaking, in bp, that is 1/72 of an inch, but approximately inpoints. Defaults to \code{12}.}\item{pagecentre}{logical: should the device region be centred on thepage? -- is only relevant for \code{paper != "special"}. Defaultsto true.}\item{colormodel}{a character string describing the color model:currently allowed values are \code{"rgb"}, \code{"gray"} and\code{"cmyk"}. Defaults to \code{"rgb"}.}\item{useDingbats}{logical. Should small circles be rendered\emph{via} the Dingbats font? Defaults to \code{TRUE}, which producessmaller and better output. Setting this to \code{FALSE} can workaround font display problems in broken PDF viewers.#ifdef unixSee the \sQuote{Note} for a possible fix for such viewers.#endif}\item{useKerning}{logical. Should kerning corrections be included insetting text and calculating string widths? Defaults to \code{TRUE}.}\item{fillOddEven}{logical controlling the polygon fill mode: see\code{\link{polygon}} for details. Default \code{FALSE}.}\item{maxRasters}{integer. The maximum number of raster images thatcan be stored in this PDF document. }}\details{All arguments except \code{file} default to values given by\code{\link{pdf.options}()}. The ultimate defaults are quoted in thearguments section.\code{pdf()} opens the file \code{file} and the PDF commands needed toplot any graphics requested are sent to that file.The \code{file} argument is interpreted as a C integer format as usedby \code{\link{sprintf}}, with integer argument the page number.The default gives files \file{Rplot001.pdf}, \dots, \file{Rplot999.pdf},\file{Rplot1000.pdf}, \dots.The \code{family} argument can be used to specify a PDF-specificfont family as the initial/default font for the device.If a device-independent \R graphics font family is specified (e.g., via\code{par(family=)} in the graphics package), the PDF device makes useof the PostScript font mappings to convert the \R graphics font familyto a PDF-specific font family description. (See thedocumentation for \code{\link{pdfFonts}}.)\R does \emph{not} embed fonts in the PDF file, so it is onlystraightforward to use mappings to the font families that can beassumed to be available in any PDF viewer: \code{"Times"}(equivalently \code{"serif"}), \code{"Helvetica"} (equivalently\code{"sans"}) and \code{"Courier"} (equivalently \code{"mono"}).Other families may be specified, but it is the user's responsibilityto ensure that these fonts are available on the system and third-partysoftware, e.g., Ghostscript, may be required to embed the fonts sothat the PDF can be included in other documents (e.g., LaTeX): see\code{\link{embedFonts}}. The URW-based families described for\code{\link{postscript}} can be used with viewers#ifdef unixset up to use URW fonts, which is usual with those based on\code{xpdf} or Ghostscript.#endif#ifdef windowssuch as GSView which utilise URW fonts.#endifSince \code{\link{embedFonts}} makes use of Ghostscript, it should beable to embed the URW-based families for use with other viewers.See \code{\link{postscript}} for details of encodings, as the internalcode is shared between the drivers. The native PDF encoding is givenin file \file{PDFDoc.enc}.\code{pdf} writes uncompressed PDF. It is primarily intended forproducing PDF graphics for inclusion in other documents, andPDF-includers such as \code{pdftex} are usually able to handlecompression: there are a large number of PDF compression utilitiessuch as \samp{pdftk}.The PDF produced is fairly simple, with each page being representedas a single stream. The \R graphics model does not distinguishgraphics objects at the level of the driver interface.The \code{version} argument declares the version of PDF that getsproduced. The version must be at least 1.4 for semi-transparentoutput to be understood, and at least 1.3 if CID fonts are to be used:if these features are used the version number will be increased (witha warning). Specifying a low version number is useful if you want toproduce PDF output that can be viewed on older or non-Adobe PDFviewers. (PDF 1.4 requires Acrobat 5 or later.)Line widths as controlled by \code{par(lwd=)} are in multiples of1/96 inch. Multiples less than 1 are allowed. \code{pch="."} with\code{cex = 1} corresponds to a square of side 1/72 inch, which isalso the \sQuote{pixel} size assumed for graphics parameters such as\code{"cra"}.The \code{paper} argument sets the \samp{/MediaBox} entry in the file,which defaults to \code{width} by \code{height}. If it is set tosomething other than \code{"special"}, a device region of thespecified size is (by default) centred on the rectangle given by thepaper size: if either \code{width} or \code{height} is lessthan \code{0.1} or too large to give a total margin of 0.5 inch, it isreset to the corresponding paper dimension minus 0.5. Thus if youwant the default behaviour of \code{\link{postscript}} use\code{pdf(paper="a4r", width=0, height=0)} to centre the device regionon a landscape A4 page with 0.25 inch margins.When the background colour is fully transparent (as is the initialdefault value), the PDF produced does not paint the background.Almost all PDF viewers will use a white canvas so the visual effect isif the background were white. This will not be the case when printingonto coloured paper, though.If you are planning to use a large number of raster images in youroutput, you may need to specify a larger value for \code{maxRasters}.}\section{Color models}{The default color model is RGB, and model \code{"gray"} maps RGBcolors to greyscale using perceived luminosity (biased towards green).\code{"cmyk"} outputs in CMYK colorspace. Nothing in \R specifies theinterpretation of the RGB or CMYK color spaces, and the simplestpossible conversion to CMYK is used(\url{http://en.wikipedia.org/wiki/CMYK_color_model#Mapping_RGB_to_CMYK}).}\section{Conventions}{This section describes the implementation of the conventions forgraphics devices set out in the \dQuote{R Internals Manual}.\itemize{\item The default device size is 7 inches square.\item Font sizes are in big points.\item The default font family is Helvetica.\item Line widths are as a multiple of 1/96 inch, with no minimum.\item Circles of any radius are allowed. Unless \code{useDingbats =FALSE}, opaque circles of less than 10 bigpoints radius are rendered using char 108 in the Dingbats font:all semi-transparent and larger circles using a \enc{Bézier}{Bezier}curve for each quadrant.\item Colours are interpreted by the viewing/printing application.}}\note{If you see problems with PDF output, do remember that theproblem is much more likely to be in your viewer than in \R. Tryanother viewer if possible. Symptoms for which the viewer has been atfault are apparent grids on image plots (turn off graphicsanti-aliasing in your viewer if you) and missing or incorrect glyphsin text (viewers silently doing font substitution).Unfortunately the default viewers on most Linux and Mac OS X systemshave these problems, and no obvious way to turn off graphics anti-aliasing.Acrobat Reader does not use the fonts specified but rather emulatesthem from multiple-master fonts. This can be seen in imprecisecentering of characters, for example the multiply and divide signs inHelvetica. This can be circumvented by embedding fonts wherepossible. Most other viewers substitute fonts, e.g. URW fonts for thestandard Helvetica and Times fonts, and these too often have differentfont metrics from the true fonts.Acrobat Reader 5.x and later can be extended by support for Asian and(so-called) Central European fonts, and these will be needed for thefull use of encodings other than Latin-1. See\url{http://www.adobe.com/products/acrobat/acrrasianfontpack.html} forReader 6.x to 8.x, and \url{http://www.adobe.com/downloads/updates}for 9.x.#ifdef unixOn some systems the default plotting character \code{pch = 1} isdisplayed in some PDF viewers incorrectly as a \code{"q"}character. (These seem to be viewers based on the \samp{poppler} PDFrendering library). This may be due to incorrect or incomplete mappingof font names to those used by the system. Adding the following linesto \file{~/.fonts.conf} or \file{/etc/fonts/local.conf} may circumventthis problem.\preformatted{<fontconfig><alias binding="same"><family>ZapfDingbats</family><accept><family>Dingbats</family></accept></alias></fontconfig>}#endif}\seealso{\code{\link{pdfFonts}}, \code{\link{pdf.options}},\code{\link{embedFonts}},\code{\link{Devices}},\code{\link{postscript}}.#ifdef unix\code{\link{cairo_pdf}} and (on Mac OS X only) \code{\link{quartz}}for other devices that can produce PDF.#endifMore details of font families and encodings and especially handlingtext in a non-Latin-1 encoding and embedding fonts can be found inPaul Murrell and Brian Ripley (2006) Non-standard fonts in PostScriptand PDF graphics. \emph{R News}, 6(2):41--47.\url{http://cran.r-project.org/doc/Rnews/Rnews_2006-2.pdf}.}\examples{\dontrun{## Test function for encodingsTestChars <- function(encoding="ISOLatin1", ...){pdf(encoding=encoding, ...)par(pty="s")plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",xaxs="i", yaxs="i")title(paste("Centred chars in encoding", encoding))grid(17, 17, lty=1)for(i in c(32:255)) {x <- i \%\% 16y <- i \%/\% 16points(x, y, pch=i)}dev.off()}## there will be many warnings.TestChars("ISOLatin2")## this does not view properly in older viewers.TestChars("ISOLatin2", family="URWHelvetica")## works well for viewing in gs-based viewers, and often in xpdf.}}\keyword{device}