6

我正在尝试将多个 pdf 图合并到一个主 pdf 文件中。

例子:

输入:我有三个 pdf 文件:“1.pdf”、“2.pdf”和“3.pdf”

输出:如何将这三个图合并到一个名为“combine.pdf”的文件中

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

4

4 回答 4

8

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

## 获取 plotflow github 包:

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

## 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)

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

于 2013-08-05T23:08:25.107 回答
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}
于 2013-08-05T22:48:50.720 回答
0

将以下代码包含到 PHP 脚本中

shell_exec("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFFitPage -sPAPERSIZE=a4 -dFIXEDMEDIA -sOUTPUTFILE= abc.pdf xyz.pdf"); 
于 2019-09-30T12:25:56.420 回答
0

在 Linux 中使用命令行提示符时,我发现如果您在同一个目录中并且 .pdf 文件按照您希望它们在最终 pdf 文档中的顺序排列,那么这是可行的。

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

于 2019-08-13T18:33:37.340 回答