Combine multiple PDF charts into one file

I am trying to combine several PDF plots into one master pdf file.

Example:

Input: I have three pdf files: "1.pdf", "2.pdf" and "3.pdf"

Conclusion: how to combine these three graphs into one file with the name "comb.pdf"

I tried using pdf () and pdftk (), but failed so far, maybe I just missed something. Thought to ask for help. Thanks so much for any answer.

+6
source share
4 answers

You can use sweave/knitr to get more flexibility and easily merge new stories, 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} 
+5
source

I asked a similar question a while ago, and Ananda Mahto generously provided time and code to help make a github package that can combine several graphs of different sizes. I use it a little in my workflow, but I do not plan to translate it into CRAN, but you can download it using the devtools package. Please note that for this you need to install ghostscript in your path too :

## Getting the github overhead stream package:

 library(devtools) install_github("plotflow", "trinker") library(plotflow) 

## 2 Examples of using the package to combine 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 , if you already have PDF files, you can look at the plotflow: mergePDF function .

+8
source

Using the command line prompt on Linux, I found that this works if you are in the same directory and the .pdf files are in the order you want them in the last PDF document.

gs -dBATCH -dNOPAUSE -q -sDEVICE = pdfwrite -sOutputFile = Chart_Pak.pdf * .pdf

0
source

include the below code in a PHP script

 shell_exec("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFFitPage -sPAPERSIZE=a4 -dFIXEDMEDIA -sOUTPUTFILE= abc.pdf xyz.pdf"); 
0
source

Source: https://habr.com/ru/post/951075/


All Articles