使用 pdfpages 和 hyperref 时如何链接到同级 PDF

使用 pdfpages 和 hyperref 时如何链接到同级 PDF

我用pdfpages它来将多个 PDF 文档(是的,它们必须是单独的文档)绑定到一个文件包中。我的问题是,我需要在一个子文档中放置许多链接,这些链接链接到其他子文档的第一页(这些子文档在外部文档中被加了书签)。这是一个 MWE:

******ChildOne.tex:******

\documentclass{article}

\usepackage[bookmarksopenlevel=1,%
     pdfpagemode=UseOutlines]{hyperref}
\hypersetup{
    pdfinfo={
        Title={Child One},
        Author={Me}
    }
}

\author{Me}
\title{Child One}

\begin{document}
\maketitle
Here is where I want to refer to Child Two.

I can do it by \href[page=3]{OuterDoc.pdf}{absolute page reference},
but the zoom level changes, and I don't always know the absolute
page number ahead of time (because there are so many child documents
of varying lengths).

My preference would be to refer to Child Two automatically, and
\href{OuterDoc.pdf#nameddest=ChildTwo}{a named destination} doesn't
seem to work.

\end{document}

******ChildTwo.tex:******

\documentclass{article}

\usepackage{lipsum}

\usepackage[bookmarksopenlevel=1,%
     pdfpagemode=UseOutlines]{hyperref}
\hypersetup{
    pdfinfo={
        Title={Child Two},
        Author={Me}
    }
}

\author{Me}
\title{Child Two}

\begin{document}
\maketitle
\lipsum[1-5]
\end{document}

编译ChildOne.tex和之后ChildTwo.tex,我运行paxChildOne.pdf使用这个问题),然后编译OuterDoc.tex

******OuterDoc.tex:******

\documentclass{article}

\author{Me}
\title{Big Title}

\usepackage{pdfpages}

\newcommand{\singlepageinpdf}{1}
\newcommand{\pagesinpdf}{1}

\newcounter{includepdfpage}
\newcounter{currentpagecounter}
\newcommand{\addlabelstoallincludedpages}[1]{%
   \refstepcounter{includepdfpage}%
   \stepcounter{currentpagecounter}%
   \label{#1.\thecurrentpagecounter}}
\newcommand{\modifiedincludepdf}[4]{%
    \setcounter{currentpagecounter}{0}%
    \includepdf[pages=1,pagecommand={\pdfbookmark[#1]{#2}{#3}\addlabelstoallincludedpages{#3}}]{#4}%
    \pdfximage{#4}%
    \renewcommand{\pagesinpdf}{\the\pdflastximagepages}%
    \if\pagesinpdf\singlepageinpdf%
      \relax%
    \else%
        \includepdf[pages=2-,pagecommand=\addlabelstoallincludedpages{#3}]{#4}%
    \fi%
}

\usepackage{pax}

\usepackage[bookmarksopenlevel=1,%
     pdfpagemode=UseOutlines,%
     pdfpagelayout=OneColumn,%
     pdfnewwindow=false,%
     pdfstartview=FitH]{hyperref}
\hypersetup{
    pdfinfo={%
        Title={Outer Doc},%
        Author={Me}%
    }%
}

\usepackage{bookmark}

\begin{document}
\bookmark[page=1, level=0]{Title Page}
{\begin{center}
\Huge \textbf{My Big Document}
\end{center}
}

\modifiedincludepdf{0}{First Child}{ChildOne}{ChildOne.pdf}
\modifiedincludepdf{0}{Second Child}{ChildTwo}{ChildTwo.pdf}

\end{document}

因为我的\href[page=3]{OuterDoc.pdf}{absolute page reference}链接工作正常,所以在我看来,包括在内的链接系统pax工作正常。然而,\href{OuterDoc.pdf#nameddest=ChildTwo}{a named destination}并没有给我带来任何快乐。

我是不是可能运气不好,因为书签不是有效的目标?(如果是这样,哪位聪明人能想到解决办法?)

另外一个(但很小)的问题是, (2012/11/06 v6.83m)pdfstartview=FitH选项hyperref不会以适合的宽度(对于链接)加载页面[page=3]——它会放大到整个页面视图。

答案1

  • 在 中,通过添加到 中的键来OuterDoc.tex创建命名目的地。(我没有费心粘贴整个文件,只进行这一更改。)\hypertarget{#3}{}pagecommand\modifiedincludepdf

  • 链接到命名的目的地\hyperref{OuterDoc.pdf}{}{ChildTwo}{a named destination}似乎有效。

  • 对于您提到的最后一个小问题,将pdfremotestartview=FitH \hypercalcbp{\paperheight-\topmargin-1in -\headheight-\headsep}键添加到。 (如果 中的所有页面都具有与包含链接的页面相同的纸张尺寸和边距,则\href获取正确的位置,即。)ChildTwoChildOne

儿童一号.tex

\documentclass{article}

\usepackage[bookmarksopenlevel=1,%
     pdfpagemode=UseOutlines]{hyperref}
\hypersetup{
    pdfinfo={
        Title={Child One},
        Author={Me}
    }
}

\author{Me}
\title{Child One}

\begin{document}
\maketitle
Here is where I want to refer to Child Two.

I can do it by \href[page=3,pdfremotestartview=FitH \hypercalcbp{\paperheight-\topmargin-1in
-\headheight-\headsep}]{OuterDoc.pdf}{absolute page reference},
but the zoom level changes, and I don't always know the absolute
page number ahead of test (because there are so many child documents
of varying lengths).

My preference would be to refer to Child Two automatically, and
\hyperref{OuterDoc.pdf}{}{ChildTwo}{a named destination} doesn't
seem to work.


\end{document}

相关内容