在LaTeX中插入PDF文件

695

我正在尝试将一个PDF或doc文件作为附录插入到我的LaTeX文件中。你知道我该如何做吗?


14
你是只想将PDF文件追加到文档末尾,还是想像插入图片一样嵌入其中? - zdav
17
请注意,如果有人想建议将此内容迁移到text.stackexchange,我们无法这样做。这篇文章的发布时间是2010年,太过久远无法迁移。 - ChrisF
1
参见:在LaTeX文档中插入PDF文件 - Martin Thoma
参见:https://tex.stackexchange.com/questions/8662/merge-two-pdf-files-output-by-latex - 0 _
6个回答

1018

使用pdfpages包。

\usepackage{pdfpages}

为了包含PDF文件中的所有页面:

\includepdf[pages=-]{myfile.pdf}
要仅包含PDF的第一页,请使用以下方法:
\includepdf[pages={1}]{myfile.pdf}

在命令行中运行texdoc pdfpages,以查看 pdfpages 的完整手册。


191
需要明确指定想要包含的页面,例如\includepdf[pages={1,3,5}]{myfile.pdf}会包含文件中的第1、3、5页。若要包含整个文件,则需指定pages={-},其中{-}是一个范围,未指定端点将默认分别为第一页和最后一页。 - rcollyer
58
我需要进行的前两件事是缩放和重新启用我的外部页面设计(以便再次显示页码),这两个操作都可以使用配置设置,例如:\includepdf[pages=-,scale=.8,pagecommand={}]{file} - LeoR
6
似乎它不能与LaTeX Beamer一起使用;这是如何在Beamer中实现的:http://tex.stackexchange.com/questions/57441/how-to-include-existing-pdf-slides-into-my-beamer - thias
4
偏移选项在\includepdf[page={-},offset=<x偏移量>毫米 <y偏移量>毫米]{myfile.pdf}中很有用。 - Katu
2
从(docs)[http://mirrors.sorengard.com/ctan/macros/latex/contrib/pdfpages/pdfpages.pdf]中可以看到,你可以指定范围。例如,如果你想从总共100页中删除第49页,你可以使用`pages={1-48,50-100}`。虽然不像`pages={!49}`这样简单,但也不是很麻烦。 - rcollyer
显示剩余9条评论

104

如果您想将整个PDF文件而不仅仅是一页放入您的文件中,请使用:

\usepackage{pdfpages}

\includepdf[pages=-]{myfile.pdf}

5
你可以直接使用 \includepdf{myfile.pdf}。 - user1529540
2
@CroCo 是的,由于某些原因有时它可以工作,有时它不行,对于误导你我感到抱歉 :( - user1529540

57
\includegraphics{myfig.pdf}

5
我知道如何插入一个figure.pdf文件,但是我需要插入的文件有多页。 - Guido
29
嗨dagray,你的回答可能是Guido在寻找的,但即使如此,仅仅写一小段代码而没有任何进一步的解释是没有帮助的。 - LeoR
7
@LeoR 我不同意。问题本质上是:“如何在LaTeX中插入pdf?”答案就是dagray写的那样。问题并不是“你如何将pdf插入LaTeX并能否解释它的工作原理”。这个答案中已经有足够的信息可以让你自己找到其余部分的答案。 - Automatico
3
然而,问题明确声明这是一个附录的DOC/PDF文件,因此它可能不止一页。 - igorsantos07
7
请注意,需要使用命令前先添加\usepackage{graphicx}包。 - anroesti

33

\includegraphics 函数有一个 page 选项,可以将 PDF 文件的特定页面作为图形插入。默认设置为 1,但您可以更改它。

\includegraphics[scale=0.75,page=2]{multipage.pdf}

更多信息可以在这里找到。


22

我不认为有一种自动的方法。您可能还需要正确添加附录的页码。假设您已经有了一个多页的PDF文档,您需要首先使用Adobe Acrobat Professional提取每一页并将它们保存为单独的PDF文件。然后,您需要在每一页上将每个PDF文档作为图像包含(每页1个),并在每页之间使用newpage,例如:

\appendix
\section{Quiz 1}\label{sec:Quiz}
\begin{figure}[htp] \centering{
\includegraphics[scale=0.82]{quizz.pdf}}
\caption{Experiment 1}
\end{figure}  

\newpage
\section{Sample paper}\label{sec:Sample}
\begin{figure}[htp] \centering{
\includegraphics[scale=0.75]{sampaper.pdf}}
\caption{Experiment 2}
\end{figure}

现在每个页面都会显示一个pdf图像,并且您将在底部看到正确的页码。如我的示例所示,您需要针对每个图像调整一下比例因子,以获得合适的尺寸,以适合单个页面。希望这有所帮助...


2
问题是关于插入整个页面,而不是关于如何在由latex格式化和生成的现有页面中包含pdf文件的内容。 - Mayer Goldberg

11

有一种选项可以在 pdflatex 下工作,无需任何额外的软件包。

请修改此代码。

\begin{figure}[h]
    \centering
    \includegraphics[width=\ScaleIfNeeded]{figuras/diagrama-spearman.pdf}
    \caption{Schematical view of Spearman's theory.}
\end{figure}
"

"diagrama-spearman.pdf"是使用TikZ生成的图形,这是代码(它是一个与我要插入pdf的.tex文件不同的.tex文件)

"
\documentclass[border=3mm]{standalone}
\usepackage[applemac]{inputenc}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage[bb=lucida,bbscaled=1,cal=boondoxo]{mathalfa}
\usepackage[stdmathitalics=true,math-style=iso,lucidasmallscale=true,romanfamily=bright]{lucimatx}
\usepackage{tikz}
\usetikzlibrary{intersections}
\newcommand{\at}{\makeatletter @\makeatother}

\begin{document}

\begin{tikzpicture}
\tikzset{venn circle/.style={draw,circle,minimum width=5cm,fill=#1,opacity=1}}
\node [venn circle = none, name path=A] (A) at (45:2cm) { };
\node [venn circle = none, name path=B] (B) at (135:2cm) { };
\node [venn circle = none, name path=C] (C) at (225:2cm) { };
\node [venn circle = none, name path=D] (D) at (315:2cm) { };
\node[above right] at (barycentric cs:A=1) {logical}; 
\node[above left] at (barycentric cs:B=1) {mechanical}; 
\node[below left] at (barycentric cs:C=1) {spatial}; 
\node[below right] at (barycentric cs:D=1) {arithmetical}; 
\node at (0,0) {G};    
\end{tikzpicture}

\end{document} 

这是我包含的图表

enter image description here


4
值得一提的是,页码参数也可以用于使用graphicsx的参数\includegraphics[page=2,width=0.5\textwidth,height = 0.3\textheight]{file.pdf} - user2589273
3
我认为这个问题是在询问如何包含多个页面。 - Charles Stewart

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接