\pdfbookmark 到页码和位置,使用 \includepdf

\pdfbookmark 到页码和位置,使用 \includepdf

我想使用\pdfbookmark类似的命令来引用 PDF 文档中的页面(包含在\includepdf命令中),并进一步将用户带到该页面的特定位置(比如距离顶部 2.34 英寸)。

有没有这样的命令\mypdfbookmark,当你将包含以下行的文档 PDFLaTeX 时

\mypdfbookmark[2]{page 3 location 2.3in}{Test}
\includepdf[pages={-},link,linkname=Test,linkfit=FitH]{Test.pdf}

当您单击 Adode 中的 pdfbookmark 时,它会将您带到第 3 页,位于距文档顶部 2.3 英寸的位置Test

我知道我可以单独导入 PDF 的页面,但这并不能解决显示该页面上特定位置的问题。我希望能够在一个命令中引用页面和位置,但如果有必要,也可以使用单个页面。

答案1

我知道埃格雷格会向我开枪;-)

我玩了一下,您可以使用以下包placebookmarks。该包仅定义一个命令和一些选项。该命令的\mypdfbookmark语法如下:

\mypdfbookmark[<options>]{bookmarkname}

选项包括:

  • level-- 设置级别\pdfbookmark;默认值为 1
  • page-- 设置将获得书签的页面;默认值 = 0
  • x-location-- 设置 x 坐标;默认值 = 0.5\paperwidth
  • y-location-- 设置 x 坐标;默认值 = 0.5\paperheight
  • draw-circle-- 画一个红色实心圆圈来查看当前位置

我使用以下示例来发送包裹短信:

\documentclass{scrreprt}
\usepackage{kantlipsum}
\usepackage{pdfpages}
\usepackage{placebookmarks}
\usepackage{hyperref}

\begin{document}
\kant

\mypdfbookmark[page=2,draw-circle=true]{Test}
\includepdf[frame=true,pages={-}]{Example-file}
\end{document}

这里是包裹:

\RequirePackage{expl3}
\ProvidesExplPackage {placebookmarks} {2012/05/11} {0.1}
  {Placing bookmarks on several pages}



\msg_new:nnnn { placebookmarks } { package-missing }
  { Package~'#1'~is~missing. }
  { The~'#1'~package~is~needed~by~placebookmarks. }
\cs_new_protected:Npn \placebookmarks_load_check:n #1 {
  \group_begin:
    \@ifpackageloaded {#1}
      { }
      { 
       \msg_error:nnx { placebookmarks } { package-missing } {#1} 
       \tex_endinput:D
      }
  \group_end:
}
\AtBeginDocument {
  \clist_map_function:nN { hyperref , pdfpages  }
    \placebookmarks_load_check:n
}

\RequirePackage{l3keys2e , xparse , picture }
%Define options
\keys_define:nn { placebookmarks } {
   level       .int_set:N   = \l_placebookmarks_store_level_int,
   page        .int_set:N   = \l_placebookmarks_store_page_int,
   x-location  .dim_set:N   = \l_placebookmarks_xlocation_dim,
   y-location  .dim_set:N   = \l_placebookmarks_ylocation_dim,
   draw-circle .bool_set:N  = \l_placebookmarks_drawcircle_bool,
}
\keys_set:nn { placebookmarks } { level = 1 ,page = 0 ,  draw-circle = true ,
                                  x-location= .5\paperwidth , y-location= 0.5\paperheight }




\tl_new:N \l_placebookmarks_store_bookmarktitle_tl

\cs_new_protected:Npn \placebookmarks_position_aux_i: { }


\NewDocumentCommand \mypdfbookmark {  O{} m }
{
 \keys_set:nn { placebookmarks } { #1 }
 \tl_set:Nn \l_placebookmarks_store_bookmarktitle_tl { #2 }
 \cs_set_protected:Npn \placebookmarks_position_aux_i:
  {
   \int_compare:nNnT { \AM@page } = { \l_placebookmarks_store_page_int }
   { 
    \bool_if:NT \l_placebookmarks_drawcircle_bool
        {
         \put ( \l_placebookmarks_xlocation_dim ,
                \l_placebookmarks_ylocation_dim ) 
              {\color{red}\circle*{10}}
        }
    \put ( \l_placebookmarks_xlocation_dim ,
           \l_placebookmarks_ylocation_dim )
         {
          \pdfbookmark[\int_use:N \l_placebookmarks_store_level_int]
                      {\tl_use:N \l_placebookmarks_store_bookmarktitle_tl}
                      {placebookmarks-\thepage}
         }
    \cs_gset_eq:NN \placebookmarks_position_aux_i: \tex_relax:D
   }
  }
}


\newcommand{\placebookmarks@output}[1]{%
  \c@totalnumber=0
  \if@twocolumn\let\AM@twocolumn\relax \onecolumn \fi
  \AM@disable@includegraphics
  \@ifundefined{AM@xnup}
    {\def\AM@xnup{\@ne}\def\AM@ynup{\@ne}%
     \def\AM@xnupminusi{\z@}\def\AM@ynupminusi{\z@}}{}%
  \@ifundefined{AM@deltax}
    {\def\AM@deltax{-\fboxrule}\def\AM@deltay{-\fboxrule}}{}%
  \@ifundefined{AM@xoffset}
    {\def\AM@xoffset{\z@}\def\AM@yoffset{\z@}}{}%
  \def\AM@xpos{\z@}\def\AM@ypos{\z@}%
  \ifAM@pkg@draft \setkeys{Gin}{draft=true}%
  \else \setkeys{Gin}{draft=false}%
  \fi
  \ifthenelse{\boolean{AM@landscape}}
    {\def\AM@lscape@rot{90}%
     \@ifundefined{AM@shortnupsyntax}{}
       {\let\AM@temp\AM@xnup
        \let\AM@xnup\AM@ynup
        \let\AM@ynup\AM@temp}%
    }{}%
  \AM@setphantom
  \ifthenelse{\boolean{AM@openright}}
         {\AM@openright}{}%
  \ifx\AM@signature\@empty\AM@filluppagelist
  \else\AM@prepare@signature\AM@signaturetrue\AM@turnfalse\fi
  \@tempcnta=\AM@xnup\relax \advance\@tempcnta\m@ne
  \edef\AM@xnupminusi{\the\@tempcnta}%
  \@tempcnta=\AM@ynup\relax \advance\@tempcnta\m@ne
  \edef\AM@ynupminusi{\the\@tempcnta}%
  \ifthenelse{\boolean{AM@column}%
              \and\not\boolean{AM@columnstrict}}
         {\AM@getlastn{\AM@doclist}{\AM@nup}%
          \edef\AM@lastndocs{\AM@lastnitems}%
          \AM@getlastn{\AM@pagelist}{\AM@nup}%
          \edef\AM@lastnpages{\AM@lastnitems}%
          \AM@resort
          \AM@count{\AM@pagelist}%
          \expandafter\ifx\expandafter\\\AM@pagelist\\%
            \edef\AM@pagelist{\AM@resortedpagelist}%
            \edef\AM@doclist{\AM@resorteddoclist}%
          \else
            \edef\AM@pagelist{\AM@pagelist,\AM@resortedpagelist}%
            \edef\AM@doclist{\AM@doclist,\AM@resorteddoclist}%
          \fi}{}%
  \ifthenelse{\boolean{AM@frame}}
         {\global\let\AM@fbox\fbox}
         {\global\let\AM@fbox\relax
          \setlength{\fboxrule}{\z@}}%
  \ifthenelse{\boolean{AM@reflect}}
         {\global\let\AM@reflectbox\reflectbox}
         {\global\let\AM@reflectbox\relax}%
  \setbox\AM@pagebox\null
  \ifthenelse{\boolean{AM@column}}
         {\def\AM@xnupi{\@ne}%
          \def\AM@ynupi{\z@}}
         {\def\AM@xnupi{\z@}%
          \def\AM@ynupi{\@ne}}%
  \AM@firstpagetrue
  \setlength{\fboxsep}{\z@}%
  \@ifundefined{AM@pagetemplate}
      {\AM@readfirst{\AM@pagelist}%
       \edef\AM@page{\the\toks@}}
      {\edef\AM@page{\AM@pagetemplate}}%
  \AM@readfirst{\AM@doclist}%
  \edef\AM@docname{\the\toks@}%
  \newpage
  \AM@isphantom
  \ifAM@noautoscale
    \def\AM@globalscale{1}%
  \else
    \AM@split@options{Gin@noscale}{#1}%
    \let\AM@filelist@save\@filelist
    \ifAM@DVIoutput
      \setbox\@tempboxa=\hbox{\rule{597pt}{845pt}}%
    \else
      \ifAM@templatesize
        \setbox\@tempboxa=\hbox{%
          \rotatebox{\AM@lscape@rot}{\copy\AM@templatesizebox}}%
      \else
        \setbox\@tempboxa=\hbox{%
          \expandafter\includegraphics\expandafter[\the\@temptokena,
            page=\AM@page, angle=\AM@lscape@rot]{\AM@docname}}%
      \fi
    \fi
    \ifthenelse{\boolean{AM@fitpaper}}
      {\setlength{\AM@pagewidth}{\wd\@tempboxa}%
       \setlength{\AM@pageheight}{\ht\@tempboxa + \dp\@tempboxa}%
       \setlength{\paperwidth}{\wd\@tempboxa}%
       \setlength{\paperheight}{\ht\@tempboxa + \dp\@tempboxa}%
       \AM@fitpaper@special
       \AM@setpagedimen
       \@ifundefined{stockwidth}{}{%
         \setlength{\stockwidth}{\AM@pagewidth}%
         \setlength{\stockheight}{\AM@pageheight}%
         \setlength{\trimtop}{0pt}%
         \setlength{\trimedge}{0pt}}%
      }{}%
    \ifdim\AM@pagewidth=\z@
      \AM@pagewidth=210mm
      \PackageWarningNoLine{pdfpages}{%
        Erroneous page width of 0.0pt is corrected}%
    \fi
    \ifdim\AM@pageheight=\z@
      \AM@pageheight=297mm
      \PackageWarningNoLine{pdfpages}{%
        Erroneous page height of 0.0pt is corrected}%
    \fi
    \ifdim\paperwidth=\z@
      \let\paperwidth\AM@pagewidth
    \fi
    \ifdim\paperheight=\z@
      \let\paperheight\AM@pageheight
    \fi
    \def\AM@xscale{%
      (\paperwidth - \tw@\fboxrule*\AM@xnup
       - \AM@deltax * \AM@xnupminusi) /
      (\AM@xnup * \real{\strip@pt\wd\@tempboxa})
    }%
    \setlength{\@tempdima}{\AM@xscale}%
    \edef\AM@xscale{\strip@pt\@tempdima}%
    \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
    \def\AM@yscale{
      (\paperheight - \tw@\fboxrule*\AM@ynup
       - \AM@deltay *\AM@ynupminusi) /
      (\AM@ynup * \real{\strip@pt\@tempdimb})
    }%
    \setlength{\@tempdima}{\AM@yscale}%
    \edef\AM@yscale{\strip@pt\@tempdima}%
    \@tempdima=\AM@xscale\p@
    \@tempdimb=\AM@yscale\p@
    \ifdim\@tempdima<\@tempdimb
      \let\AM@globalscale\AM@xscale
    \else
      \let\AM@globalscale\AM@yscale
    \fi
  \fi
  \let\AM@filelist@save\@filelist
  \AM@split@options{Gin}{#1}%
  \ifAM@templatesize
    \setbox\@tempboxa=\hbox{%
      \scalebox{\AM@scale@factor}{\copy\AM@templatesizebox}}%
    \setbox\@tempboxa=\hbox{%
      \scalebox{\AM@globalscale}{\copy\@tempboxa}}%
    \setbox\@tempboxa=\hbox{%
      \rotatebox{\AM@lscape@rot}{\copy\@tempboxa}}%
  \else
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\AM@docname}}%
  \fi
  \let\@filelist\AM@filelist@save
  \edef\AM@templatewidth{\the\wd\@tempboxa}%
  \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
  \edef\AM@templateheight{\the\@tempdima}%
  \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
  \def\AM@xmargin{%
    (\paperwidth - (\wd\@tempboxa+\tw@\fboxrule)*\AM@xnup
     - \AM@deltax * \AM@xnupminusi) * \real{.5}%
  }%
  \def\AM@ymargin{%
    (\paperheight - (\@tempdimb+\tw@\fboxrule)*\AM@ynup
     - \AM@deltay * \AM@ynupminusi) * \real{.5}%
  }%
  \setlength{\@tempdima}{\AM@xmargin}%
  \edef\AM@xmargin{\the\@tempdima}%
  \setlength{\@tempdima}{\AM@ymargin}%
  \edef\AM@ymargin{\the\@tempdima}%
  \ifthenelse{\boolean{AM@landscape}}
       {\edef\AM@temp{\AM@xnup}%
        \edef\AM@xnup{\AM@ynup}%
        \edef\AM@ynup{\AM@temp}}
       {}%
  \ifAM@signature
    \ifAM@landscape\AM@sigrotatefalse\else\AM@sigrotatetrue\fi
  \fi
  \setboolean{AM@endoflist}{false}%
  \whiledo{\not\boolean{AM@endoflist}}{%
    \AM@getfirst{\AM@pagelist}%
      \edef\AM@page{\the\toks@}%
      \AM@isphantom
      \@tempcnta=\AM@page\relax
      \edef\AM@linktodoc@page{\the\@tempcnta}%
      \advance\@tempcnta\m@ne
      \edef\AM@linktodoc@page@m@ne{\the\@tempcnta}%
    \AM@getfirst{\AM@doclist}%
      \edef\AM@docname{\the\toks@}%
      \ifAM@linkfilename
      \else
        \let\AM@linkfilename\AM@docname
      \fi
      \ifx\@empty\AM@linkname@option \edef\AM@linkname{\the\toks@}%
      \else \edef\AM@linkname{\AM@linkname@option} \fi
    \ifthenelse{\boolean{AM@column}}
      {\@tempcnta=\AM@ynupi\relax
       \@tempcntb=\AM@ynup\relax
       \advance\@tempcnta\@ne
       \ifnum\@tempcnta>\@tempcntb
         \@tempcnta=\@ne
         \@tempcntb=\AM@xnupi\relax
         \advance\@tempcntb\@ne
         \edef\AM@xnupi{\the\@tempcntb}%
       \fi
       \edef\AM@ynupi{\the\@tempcnta}%
       \@tempcnta=\AM@xnupi\relax
       \@tempcntb=\AM@xnup\relax
       \ifnum\@tempcnta>\@tempcntb
         \def\AM@xnupi{\@ne}%
       \fi
      }
      {\@tempcnta=\AM@xnupi\relax
       \@tempcntb=\AM@xnup\relax
       \advance\@tempcnta\@ne
       \ifnum\@tempcnta>\@tempcntb
         \@tempcnta=\@ne
         \@tempcntb=\AM@ynupi\relax
         \advance\@tempcntb\@ne
         \edef\AM@ynupi{\the\@tempcntb}%
       \fi
       \edef\AM@xnupi{\the\@tempcnta}%
       \@tempcnta=\AM@ynupi\relax
       \@tempcntb=\AM@ynup\relax
       \ifnum\@tempcnta>\@tempcntb
         \def\AM@ynupi{\@ne}%
       \fi
      }%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\AM@docname}}%
    \edef\AM@localwd{\the\wd\@tempboxa}%
    \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
    \edef\AM@localht{\the\@tempdima}%
    \AM@rescalefalse
    \ifdim\AM@localwd=\AM@templatewidth \else \AM@rescaletrue \fi
    \ifdim\AM@localht=\AM@templateheight \else \AM@rescaletrue \fi
    \def\AM@localxoff{\z@}%
    \def\AM@localyoff{\z@}%
    \def\AM@rotateoversize{0}%
    \def\AM@localscale{\p@}%
    \ifAM@rescale
      \ifthenelse{\lengthtest{\AM@localwd<\AM@templatewidth} \and
                  \lengthtest{\AM@localht<\AM@templateheight}}{%
        \setlength{\@tempdima}{(\AM@templatewidth - \AM@localwd)
             * \real{.5}}%
        \edef\AM@localxoff{\the\@tempdima}%
        \setlength{\@tempdima}{(\AM@templateheight - \AM@localht)
             * \real{.5}}%
        \edef\AM@localyoff{\the\@tempdima}%
      }{%
        \ifAM@rotateoversize
          \def\AM@rotateoversize{90}%
          \let\AM@filelist@save\@filelist
          \setbox\@tempboxa=\hbox{%
            \expandafter\includegraphics\expandafter
                [\the\@temptokena, page=\AM@page,
                 scale=\AM@globalscale,
                 angle=\AM@lscape@rot, angle=90]{\AM@docname}}%
          \let\@filelist\AM@filelist@save
          \edef\AM@localwd{\the\wd\@tempboxa}%
          \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
          \edef\AM@localht{\the\@tempdima}%
        \fi
        \setlength{\@tempdima}
                  {\p@ * \ratio{\AM@templatewidth}{\AM@localwd}}%
        \edef\AM@localxscale{\the\@tempdima}%
        \setlength{\@tempdima}
                  {\p@ * \ratio{\AM@templateheight}{\AM@localht}}%
        \edef\AM@localyscale{\the\@tempdima}%
        \ifdim\AM@localxscale<\AM@localyscale
          \let\AM@localscale\AM@localxscale
          \setlength{\@tempdima}{\AM@localxscale}%
          \setlength{\@tempdima}{(\AM@templateheight -
            \AM@localht * \real{\strip@pt\@tempdima}) * \real{.5}}%
          \edef\AM@localyoff{\the\@tempdima}%
        \else
          \let\AM@localscale\AM@localyscale
          \setlength{\@tempdima}{\AM@localyscale}%
          \setlength{\@tempdima}{(\AM@templatewidth -
             \AM@localwd * \real{\strip@pt\@tempdima}) * \real{.5}}%
          \edef\AM@localxoff{\the\@tempdima}%
        \fi
      }%
    \fi
    \setlength{\@tempdima}{\AM@localscale}%
    \edef\AM@localscale{\strip@pt\@tempdima}%
    \ifAM@noautoscale
      \def\AM@localxoff{\z@}%
      \def\AM@localyoff{\z@}%
      \def\AM@localscale{1}%
    \fi
    \let\AM@filelist@save\@filelist
    \AM@split@options{Gin}{#1}%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\AM@docname}}%
    \let\@filelist\AM@filelist@save
    \setlength{\@tempdimc}{\ht\@tempboxa + \dp\@tempboxa}%
    \def\AM@add{+}%
    \if@twoside\ifodd\c@page\else\def\AM@add{-}\fi\fi
    \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
    \ifthenelse{\boolean{AM@landscape}}
      {\def\AM@xpos{%
         \AM@xmargin \AM@add\AM@xoffset + \AM@localxoff +
         (\AM@templatewidth + \AM@deltax + \tw@\fboxrule) *
         (\AM@ynupi - 1)
       }%
       \def\AM@ypos{%
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\fboxrule) *
         (\AM@xnupi - 1)
       }%
      }
      {\def\AM@xpos{%
         \AM@xmargin \AM@add\AM@xoffset + \AM@localxoff +
         (\AM@templatewidth + \AM@deltax + \tw@\fboxrule) *
         (\AM@xnupi - 1)
       }%
       \def\AM@ypos{%
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\fboxrule) *
         (\AM@ynup-\AM@ynupi)
       }%
      }%
    \setlength{\@tempdima}{\AM@xpos}%
    \edef\AM@xpos{\strip@pt\@tempdima}%
    \setlength{\@tempdima}{\AM@ypos}%
    \edef\AM@ypos{\strip@pt\@tempdima}%
    \setlength{\fboxsep}{\z@}%
     \AM@region@calc
    \ifAM@phantompage
      \def\AM@shippage{}%
    \else
      \AM@split@options{Gin}{#1}%
      \edef\AM@shippage{%
        \noexpand\put(\AM@xpos,\AM@ypos){%
        \noexpand\raisebox{\dp\@tempboxa}{%
        \noexpand\raise \ht\@tempboxa \hbox{\AM@hyper@begin@i}%
        \AM@hyper@begin@ii\noexpand\AM@fbox{%
          \noexpand\AM@ARBug@hook
          \noexpand\AM@reflectbox{%
          \noexpand\includegraphics[\the\@temptokena,
                    page=\AM@page, scale=\AM@globalscale,
                    scale=\AM@localscale,
                    \ifAM@sigrotate angle=180,\fi
                    \ifAM@doublepagestwist\ifAM@doublepagestmp
                      angle=180,\fi\fi
                    angle=\AM@rotateoversize,
                    angle=\AM@lscape@rot]{\AM@docname}}}%
        \AM@hyper@end}}%
      }%
    \fi
    \ifAM@doublepagestwist
      \ifAM@doublepagestmpi
        \ifAM@doublepagestwistx\AM@doublepagestmpifalse\fi
        \ifAM@doublepagestmp\AM@doublepagestmpfalse
        \else\AM@doublepagestmptrue\fi
      \else\AM@doublepagestmpitrue\fi
    \fi
    \AM@AddToShipoutPicture{\setlength{\unitlength}{\p@}%
      \global\let\AM@filelist@save\@filelist}%
    \ifAM@reflectall
      \begin{lrbox}{\AM@pagebox}
        \global\let\AM@filelist@save\@filelist
        \usebox{\AM@pagebox}\AM@shippage
        \global\let\@filelist\AM@filelist@save
      \end{lrbox}
    \else
      \expandafter\AM@AddToShipoutPicture\expandafter{%
        \AM@shippage
        \placebookmarks_position_aux_i: %%%%ADDED
        \global\let\@filelist\AM@filelist@save
      }%
    \fi
    \AM@toclof{\AM@page}%
    \ifnum\AM@xnupi=\AM@xnup\relax
      \ifnum\AM@ynupi=\AM@ynup\relax
        \begingroup\AM@pagecommand\endgroup
        \hskip\z@
        \ifthenelse{\boolean{AM@turn}}
          {\ifthenelse{\boolean{AM@landscape}}
             {\AM@setlscape}{}}
          {}%
        \AM@AddToShipoutPicture{%
          \begingroup\AM@picturecommand\endgroup}%
        \ifAM@firstpage
          \AM@AddToShipoutPicture{%
            \begingroup\AM@picturecommandstar\endgroup}%
          \AM@firstpagefalse
        \fi
        \ifAM@reflectall
          \AM@AddToShipoutPicture{%
            \hskip\AM@pagewidth
            \reflectbox{\usebox\AM@pagebox}%
            \global\let\@filelist\AM@filelist@save
          }%
          \AM@ClearShipoutPicture
        \fi
        \newpage
        \ifAM@reflectall \setbox\AM@pagebox\null \fi
        \ifAM@pdflscape\PLS@Rotate{0}\fi
        \AM@ClearShipoutPicture
        \ifAM@signature
          \ifAM@sigrotate\AM@sigrotatefalse\else\AM@sigrotatetrue\fi
          \@tempdima=\AM@xoffset\relax
          \multiply\@tempdima\m@ne
          \edef\AM@xoffset{\the\@tempdima}
        \fi
      \fi
    \fi
  }% whiledo
  \ifx\AM@twocolumn\relax\twocolumn\fi
}% AM@output


\AtBeginDocument{
 \let\AM@output\placebookmarks@output
}
\tex_endinput:D

答案2

更轻量,但可能不如伟大的解决方案强大马可已给予

它使用bookmark包,它已经提供了一种使用参数设置书签打开位置的方法view。因此,剩下的唯一问题是获取所包含页面的正确页码。这可以通过在开头放置一个标签来完成\includepdf,这样就可以计算绝对页码和所包含 PDF 的页码之间的偏移量:

\usepackage{pdfpages}
\usepackage{refcount}
\usepackage{bookmark}
\makeatletter
\define@key{pdfpages}{linkname}{\def\AM@linkname@option{#1}\label{pdfpages@#1@begin}}
\newcommand*{\mypdfbookmark}[4]{\bookmark[page=\numexpr\getpagerefnumber{pdfpages@#1@begin}+#2\relax,view={#3}]{#4}}
\makeatother

将此代码添加到文档的前言部分,即\documentclass和之间\begin{document}。它定义了一个用户级宏\mypdfbookmark,需要四个参数:

\mypdfbookmark{<linkname>}{<page number>}{<view specification>}{<bookmark text>}

这里<linkname>对应于您在 中设置的参数\includepdf[link,linkname=Test]{Test.pdf},即Test在本例中。<page number>是您要打开的页码, 是将作为参数的<view specification>内容(请参阅\bookmarkviewbookmark手动的(了解更多信息),最后<bookmark text>是书签的名称。

一个小例子

此代码创建一个名为“示例书签”的书签,它将在页面顶部下方 2.34 英寸处打开所含 PDF 的第二页。

\documentclass{article}

\usepackage{pdfpages}
\usepackage{refcount}
\usepackage{bookmark}
\makeatletter
\define@key{pdfpages}{linkname}{\def\AM@linkname@option{#1}\label{pdfpages@#1@begin}}
\newcommand*{\mypdfbookmark}[4]{\bookmark[page=\numexpr\getpagerefnumber{pdfpages@#1@begin}+#2\relax,view={#3}]{#4}}
\makeatother

\begin{document}
\mypdfbookmark{Test}{2}{FitH \calc{\paperheight-2.34in}}{Sample bookmark}
\dots
\includepdf[pages={-},link,linkname=Test]{Test.pdf}
\end{document}

相关内容