| 54635 |
ripley |
1 |
% File src/library/tools/man/compactPDF.Rd
|
| 54415 |
ripley |
2 |
% Part of the R package, http://www.R-project.org
|
| 62824 |
ripley |
3 |
% Copyright 2011-3 R Core Team
|
| 54415 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{compactPDF}
|
| 56186 |
murdoch |
7 |
\alias{compactPDF}
|
| 58428 |
ripley |
8 |
\alias{format.compactPDF}
|
| 54415 |
ripley |
9 |
\title{
|
|
|
10 |
Compact PDF Files
|
|
|
11 |
}
|
|
|
12 |
\description{
|
|
|
13 |
Re-save PDF files (especially vignettes) more compactly.
|
|
|
14 |
Support function for \command{R CMD build --compact-vignettes}.
|
|
|
15 |
}
|
|
|
16 |
\usage{
|
| 58428 |
ripley |
17 |
compactPDF(paths,
|
|
|
18 |
qpdf = Sys.which(Sys.getenv("R_QPDF", "qpdf")),
|
| 54434 |
ripley |
19 |
gs_cmd = Sys.getenv("R_GSCMD", ""),
|
| 57933 |
ripley |
20 |
gs_quality = Sys.getenv("GS_QUALITY", "none"),
|
| 54434 |
ripley |
21 |
gs_extras = character())
|
| 58428 |
ripley |
22 |
|
|
|
23 |
\method{format}{compactPDF}(x, ratio = 0.9, diff = 1e4, ...)
|
| 54415 |
ripley |
24 |
}
|
|
|
25 |
\arguments{
|
|
|
26 |
\item{paths}{A character vector of paths to PDF files, or a length-one
|
|
|
27 |
character vector naming a directory, when all \file{.pdf} files in
|
|
|
28 |
that directory will be used.}
|
| 54434 |
ripley |
29 |
\item{qpdf}{Character string giving the path to the \command{qpdf}
|
| 58428 |
ripley |
30 |
command. If empty, \command{qpdf} will not be used.}
|
| 54434 |
ripley |
31 |
\item{gs_cmd}{Character string giving the path to the GhostScript
|
|
|
32 |
executable, if that is to be used. On Windows this is the path to
|
| 62824 |
ripley |
33 |
\file{gswin32c.exe} or \file{gswin64c.exe}. If \code{""} (the
|
|
|
34 |
default), the function will try to find a platform-specific path to
|
|
|
35 |
GhostScript where required.}
|
| 54434 |
ripley |
36 |
\item{gs_quality}{A character string indicating the quality required:
|
| 57933 |
ripley |
37 |
the options are \code{"none"} (so GhostScript is not used),
|
|
|
38 |
\code{"printer"} (300dpi), \code{"ebook"} (150dpi) and
|
|
|
39 |
\code{"screen"} (72dpi).}
|
| 54434 |
ripley |
40 |
\item{gs_extras}{An optional character vector of further options to be
|
|
|
41 |
passed to GhostScript.}
|
| 58428 |
ripley |
42 |
\item{x}{An object of class \code{"compactPDF"}.}
|
|
|
43 |
\item{ratio, diff}{Limits for reporting: files are only reported whose
|
| 58430 |
ripley |
44 |
sizes are reduced both by a factor of \code{ratio} and by
|
| 58428 |
ripley |
45 |
\code{diff} bytes.}
|
|
|
46 |
\item{\dots}{Further arguments to be passed to or from other methods.}
|
| 54415 |
ripley |
47 |
}
|
|
|
48 |
\details{
|
| 54434 |
ripley |
49 |
This by default makes use of \command{qpdf}, available from
|
| 55648 |
ripley |
50 |
\url{http://qpdf.sourceforge.net/} (including as a Windows binary) and
|
|
|
51 |
included with the CRAN Mac OS X distribution of \R. If \code{gs_cmd}
|
| 57933 |
ripley |
52 |
is non-empty and \code{gs_quality != "none"}, GhostScript will used
|
| 58401 |
ripley |
53 |
first, then \command{qpdf} if it is available. If \code{gs_quality !=
|
| 62824 |
ripley |
54 |
"none"} and \code{gs_cmd} is \code{""}, an attempt will be made to find a
|
| 58401 |
ripley |
55 |
GhostScript executable.
|
| 54415 |
ripley |
56 |
|
| 58401 |
ripley |
57 |
\command{qpdf} and/or \command{gs_cmd} are run on all PDF files found,
|
|
|
58 |
and those which are reduced in size by at least 10\% and 10Kb are
|
| 55648 |
ripley |
59 |
replaced.
|
| 61433 |
ripley |
60 |
|
| 55648 |
ripley |
61 |
The strategy of our use of \command{qpdf} is to (losslessly) compress
|
| 62824 |
ripley |
62 |
both PDF streams and objects. GhostScript compresses streams and more
|
| 58108 |
ripley |
63 |
(including downsampling and compressing embedded images) and
|
|
|
64 |
consequently is much slower and may lose quality (but can also produce
|
|
|
65 |
much smaller PDF files). However, quality \code{"ebook"} is perfectly
|
|
|
66 |
adequate for screen viewing and printing on laser printers.
|
| 61433 |
ripley |
67 |
|
| 55648 |
ripley |
68 |
Where PDF files are changed they will become PDF version 1.5 files:
|
| 58401 |
ripley |
69 |
these have been supported by Acrobat Reader since version 6 in 2003,
|
|
|
70 |
so this is very unlikely to cause difficulties.
|
| 58108 |
ripley |
71 |
|
|
|
72 |
Stream compression is what most often has large gains: \R's
|
|
|
73 |
\code{\link{pdf}} device prior to \R 2.14.0 did not use it, and
|
|
|
74 |
older vignette PDFs often benefit from being re-generated. Most PDF
|
|
|
75 |
documents are generated with object compression, but this does not
|
| 58401 |
ripley |
76 |
seem to be the default for MiKTeX's \command{pdflatex}. For some PDF
|
|
|
77 |
files (and especially package vignettes), using GhostScript can
|
|
|
78 |
dramatically reduce the space taken by embedded images (often screenshots).
|
| 61433 |
ripley |
79 |
|
| 62824 |
ripley |
80 |
Where both GhostScript and \command{qpdf} are selected (when
|
| 58428 |
ripley |
81 |
\code{gs_quality != "none"} and both executables are found), they are
|
|
|
82 |
run in that order and the size reductions apply to the total
|
|
|
83 |
compression achieved.
|
| 54415 |
ripley |
84 |
}
|
|
|
85 |
|
| 54454 |
ripley |
86 |
\value{
|
| 58428 |
ripley |
87 |
An object of class \code{c("compactPDF", "data.frame")}.
|
|
|
88 |
This has two columns, the old and new sizes in bytes for the files
|
|
|
89 |
that were changed.
|
|
|
90 |
|
|
|
91 |
There are \code{format} and \code{print} methods: the latter passes
|
|
|
92 |
\code{\dots} to the format method, so will accept \code{ratio} and
|
|
|
93 |
\code{diff} arguments.
|
| 54454 |
ripley |
94 |
}
|
|
|
95 |
|
| 54415 |
ripley |
96 |
\note{
|
|
|
97 |
The external tools used may change in future releases.
|
| 62824 |
ripley |
98 |
|
|
|
99 |
Versions of GhostScript 9.06 and later give several times better
|
|
|
100 |
compression than 9.05 on some vignettes in CRAN packages.
|
| 54415 |
ripley |
101 |
}
|
|
|
102 |
|
|
|
103 |
\seealso{
|
|
|
104 |
\code{\link{resaveRdaFiles}}.
|
|
|
105 |
|
| 54421 |
ripley |
106 |
Many other (and sometimes more effective) tools to compact PDF files
|
| 54434 |
ripley |
107 |
are available, including Adobe Acrobat (not Reader).
|
| 54428 |
ripley |
108 |
See the \sQuote{Writing R Extensions} manual.
|
| 54415 |
ripley |
109 |
}
|
|
|
110 |
|
|
|
111 |
\keyword{ utilities }
|