combine multiple pdf plots into one file

前端 未结 4 1782

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

相关标签:
4条回答
  • 2020-12-06 13:42

    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

    0 讨论(0)
  • 2020-12-06 13:48

    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}
    
    0 讨论(0)
  • 2020-12-06 13:49

    include below code into PHP script

    shell_exec("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFFitPage -sPAPERSIZE=a4 -dFIXEDMEDIA -sOUTPUTFILE= abc.pdf xyz.pdf"); 
    
    0 讨论(0)
  • 2020-12-06 13:59

    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.

    0 讨论(0)
提交回复
热议问题