我正在尝试将多个pdf图合并为一个主pdf文件。
示例:
输入:我有三个pdf文件:“1.pdf”,“2.pdf”和“3.pdf”
输出:如何将这三个图组合成一个名为“combine.pdf”的文件
我尝试使用pdf()和pdftk(),但还没有成功,可能是我简单地遗漏了一些东西。想要求帮助。非常感谢任何回应。
答案 0 :(得分:8)
前一段时间我问了一个类似的问题,Ananda Mahto慷慨地提供时间和代码来帮助制作一个可以组合多个不同大小的情节的github package。我在我的工作流程中使用它有点但没有计划将其推送到CRAN,但您可以使用devtools
包下载它。请注意,您必须安装ghostscript并在路径上才能实现此目的:
##获取plotflow github包:
library(devtools)
install_github("plotflow", "trinker")
library(plotflow)
## 2使用包合并多个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)
注意 如果您已经拥有pdf,则可能需要查看plotflow:::mergePDF函数。
答案 1 :(得分: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}
答案 2 :(得分:0)
使用Linux中的命令行提示符,如果您位于同一目录中,并且.pdf文件的顺序与最终pdf文档中的顺序相同,我发现它可以正常工作。
gs -dBATCH -dNOPAUSE -q -sDEVICE = pdfwrite -sOutputFile = Chart_Pak.pdf * .pdf
答案 3 :(得分:0)
将以下代码包含到PHP脚本中
shell_exec("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFFitPage -sPAPERSIZE=a4 -dFIXEDMEDIA -sOUTPUTFILE= abc.pdf xyz.pdf");