I am trying to merge multiple pdf plots into one master pdf file.
Example:
Input: I have three pdf files: \"1.pdf\", \"2.pdf\", and \"3.pdf\"
Outpu
Using the command line prompt in Linux, I found this works, if you are in the same directory and the .pdf files are in the order you want them in the final pdf doc.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=Chart_Pak.pdf *.pdf
You can use sweave/knitr
to get more flexibility and merge easily new plots ,old ones and texts:
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
this my plot 1: % write some texts here
\includepdf{1.pdf}
this my plot 2:
\includepdf{2.pdf}
this my plot 3:
\includepdf{3.pdf}
this my plot 4:
\includepdf{4.pdf}
a new plot:
<<echo=FALSE>>= % chunk for new plots
x <- rnorm(100)
hist(x)
@
\end{document}
include below code into PHP script
shell_exec("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFFitPage -sPAPERSIZE=a4 -dFIXEDMEDIA -sOUTPUTFILE= abc.pdf xyz.pdf");
I asked a similar question a while back and Ananda Mahto generously provide time and code to help make a github package that can combine multiple plots of different sizes. I use it in my workflow a bit but have no plans to push it to CRAN but you can download it with the devtools
package. Note that you have to have ghostscript installed and on your path for this to work:
## Getting the plotflow github package:
library(devtools)
install_github("plotflow", "trinker")
library(plotflow)
## 2 Examples using the package to merge multiple pdfs
## Example 1
merge_pdf(3, file = "foo.pdf", widths = c(7, 7, 10), heights = c(6, 10, 7))
plot(1:10)
plot(1:10, pch=19)
plot(1:10, col="red", pch=19)
## Example 2
library(ggplot2)
p <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
merge_pdf(2, file = "bar.pdf", widths = c(7, 10), heights = c(6, 10))
plot(1:10)
print(p)
Note that if you already have the pdfs you may want to look at the plotflow:::mergePDF function.