R 4.2.1 OS X Colleagues I have multipage PDF files that were created in R ? the files do NOT have page numbers. I would like to add page numbers after the fact, i.e., read a file into R, add margin text, then output as a PDF. Can this be done in R (base R or a package)? It can be done in Python using reportlab.pdfgen ? however, the file size increases prohibitively. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
Have you done a web search on "R packages to edit pdf files" or similar? I got what looked like relevant hits with it. Bert On Fri, Oct 21, 2022 at 10:49 AM Dennis Fisher <fisher at plessthan.com> wrote:> R 4.2.1 > OS X > > Colleagues > > I have multipage PDF files that were created in R ? the files do NOT have > page numbers. I would like to add page numbers after the fact, i.e., read > a file into R, add margin text, then output as a PDF. > Can this be done in R (base R or a package)? > It can be done in Python using reportlab.pdfgen ? however, the file size > increases prohibitively. > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Create a pdf using latex that has only page numbers and then superimpose that with your pdf using the free utility pdftk. The animation R package has an interface to pdftk. Google to locate pdftk and again to locate instructions. There are also freeware GUI Windows programs that are easy to use. This has nothing to do with R. The one I have used is A-PDF Number. On Fri, Oct 21, 2022 at 1:49 PM Dennis Fisher <fisher at plessthan.com> wrote:> > R 4.2.1 > OS X > > Colleagues > > I have multipage PDF files that were created in R ? the files do NOT have page numbers. I would like to add page numbers after the fact, i.e., read a file into R, add margin text, then output as a PDF. > Can this be done in R (base R or a package)? > It can be done in Python using reportlab.pdfgen ? however, the file size increases prohibitively. > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Hi Below is a script that does the job for a very simple R plot, making use of R and a couple of free software tools (ghostscript and poppler). It may or may not help with your real problem (NOTE the WARNING) ... library(grImport) ## Multipage PDF created by R pdf("plot-in.pdf") plot(1) plot(2) dev.off() ## Separate into individual pages system("pdfseparate plot-in.pdf plot-in-%d.pdf") inFiles <- list.files(pattern="plot-in-[0-9]+.pdf") for (i in seq_along(inFiles)) { ## Convert to PostScript ## (WARNING: may cause [some] rasterization, depending on content ## of plot and on the conversion tool; anything that is ## rasterized will NOT get imported) system(paste0("pdf2ps plot-in-", i, ".pdf plot-in-", i, ".ps")) ## Import to R PostScriptTrace(paste0("plot-in-", i, ".ps"), paste0("plot-in-", i, ".xml")) plot <- readPicture(paste0("plot-in-", i, ".xml")) ## Add page number (in new PDF) pdf(paste0("plot-out-", i, ".pdf")) grid.picture(plot) grid.text(paste0("Page ", i), .5, unit(1, "lines")) dev.off() } outFiles <- list.files(pattern="plot-out-[0-9]+.pdf") ## Recombine into single, multi-page PDF system(paste0("pdfunite ", paste(outFiles, collapse=" "), " plot-out.pdf")) If you do want to use something like this, let me know, because there are some other limitations that you might want to be aware of. Paul On 22/10/2022 6:45 am, Dennis Fisher wrote:> R 4.2.1 > OS X > > Colleagues > > I have multipage PDF files that were created in R ? the files do NOT > have page numbers. I would like to add page numbers after the fact, > i.e., read a file into R, add margin text, then output as a PDF. > Can this be done in R (base R or a package)? > It can be done in Python using reportlab.pdfgen ? however, the file size > increases prohibitively. > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > <http://www.PLessThan.com> > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > <https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code.-- Dr Paul Murrell Te Kura Tatauranga | Department of Statistics Waipapa Taumata Rau | The University of Auckland Private Bag 92019, Auckland, New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz www.stat.auckland.ac.nz/~paul/