Post by Ulrich D i e zPost by Holger SchieferdeckerI include single page PDF documents with \includepdf. They have the same
size and aspect ratio as the output document (A4). With the option
"addtotoc" I can add an entry to the tableofcontents and the bookmarks.
But clicking on that doesn't jump to the top of the included page.
It seems like the link target set by \includepdf is set with respect of
the page margins of the output document. I didn't find any hints in the
manual of pdfpages, besides that "addtotoc" is experimental. Is there a
way of positioning the link target at the top of the included pdf page?
I think there is no official interface but you can hook into
\includegraphics.
In the meantime I wrote to the author of pdfpages and asked if your
workaround could be used to create a solution internally in the package.
Unfortunately he found out that your macro has a problem. For the
landscape version a negative y coordinate is created. Some PDF viewers
like Evince and Atril he used for his test jump to the end of the page.
I used SumatraPDF and Adobe Reader which jump to the beginning of the
page like it is desired.
He also mentioned that some people use the geometry package and
temporarily change the type area. His suggestion was to use something like
\newgeometry{top=0pt, headheight=0pt, headsep=0pt, vscale=1}
\includepdf{file.pdf}
In my tests I tried with \newgeometry{margin=0pt}.
In the example below there are 4 documents embedded. Example A shows the
problem with the negative y coordinate for some viewers. Example C1 and
C2 are created with the help of geometry. This works for the landscape
document on a landscape page (C1), but not for the landscape document on
a portrait page (C2). Of course this is obvious as the page has no
margins and the link then is at the very top.
Anyway, I can solve my limited use case. There are just landscape
documents on a landscape page.
Holger
%%%%%%%%%%%%%%
\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage{hyperref}
%% Get links to top of images included with \includepdf
%From: Ulrich D i e z <***@web.de>
%Newsgroups: comp.text.tex
%Subject: Re: pgfplots: link to top of embedded page
%Date: Sat, 28 Sep 2024 02:35:29 +0200
%Message-ID: <vd7j0j$voaf$***@solani.org>
\makeatletter
\newif\iffirstpicture
\newcommand\HookIntoIncludegraphics[4]{%
\let\includegraphicscopy=\includegraphics
\def\includegraphics##1##{\MyIncludegraphicsB{##1}}%
\firstpicturetrue
\def\MyIncludegraphicsB##1##2{%
\ifnum
\iffirstpicture\csname ***@includegraphics@status\endcsname
\else 0\fi
=1 %
\global\firstpicturefalse
\vbox{%
\***@landscape\else
\hbox{%
\kern-\baselineskip
\refstepcounter{#2}%
\addcontentsline{#1}{#2}{%
\protect\numberline{\@currentlabel}#3%
}%
}%
\hrule height 0pt
\fi
\hbox{\includegraphicscopy##1{##2}}%
\***@landscape
\hrule height 0pt
\hbox{%
\def\HyperRaiseLinkDefault{-\baselineskip}%
\kern-\baselineskip
\refstepcounter{#2}%
\addcontentsline{#1}{#2}{%
\protect\numberline{\@currentlabel}#3%
}%
\kern\baselineskip
}%
\fi
\***@gettitle{#3}%
\label{#4}%
}%
\else
\includegraphicscopy##1{##2}%
\fi
}%
}%
\makeatother
\begin{document}
\tableofcontents
\begingroup
\HookIntoIncludegraphics{toc}{section}{Example A}{sp:ex-a}%
\includepdf[landscape, scale=0.97]{example-image-a}
\endgroup
\begingroup
\HookIntoIncludegraphics{toc}{section}{Example B}{sp:ex-b}%
\includepdf[scale=0.97]{example-image-b}
\endgroup
\begingroup
\newgeometry{margin=0pt}
\includepdf[landscape, scale=0.97,
addtotoc={1, section, 1, Example C1, sp:ex-c1}]{example-image-c}
\includepdf[scale=0.97,
addtotoc={1, section, 1, Example C2, sp:ex-c2}]{example-image-c}
\endgroup
\clearpage
Nothing here.
\end{document}
%%%%%%%%%%%%%%%