将多个pdf图组合成一个文件

use*_*932 6 r

我正在尝试将多个pdf图合并为一个主pdf文件.

例:

输入:我有三个pdf文件:"1.pdf","2.pdf"和"3.pdf"

输出:如何将这三个图组合成一个名为"combine.pdf"的文件

我尝试使用pdf()和pdftk(),但还没有成功,可能是我简单地遗漏了一些东西.想要求帮助.非常感谢任何回应.

Tyl*_*ker 8

我回答了一个类似的问题,Ananda Mahto慷慨地提供时间和代码来帮助制作一个可以组合多个不同大小的github包.我在我的工作流程中使用它有点但没有计划将它推送到CRAN但你可以用它下载它devtools.请注意,您必须安装ghostscript并在您的路径上才能使用:

##获取plotflow github包:

library(devtools)
install_github("plotflow", "trinker")
library(plotflow)
Run Code Online (Sandbox Code Playgroud)

## 2使用包合并多个pdf的示例

## 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)
Run Code Online (Sandbox Code Playgroud)

请注意,如果您已经拥有pdfs,则可能需要查看 plotflow ::: mergePDF函数.


ags*_*udy 5

您可以使用sweave/knitr以获得更多灵活性并轻松合并新图,旧图和文本:

\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}
Run Code Online (Sandbox Code Playgroud)