I would like to use the following code for including PDF documents in my LaTeX document:
\documentclass[12pt,a4paper,fleqn,parskip=half]{scrartcl}
\usepackage{lscape}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[scaled]{helvet}
\usepackage{caption}
\usepackage[breaklinks=true,colorlinks=true,linkcolor=black,citecolor=black,urlcolor=black]{hyperref}
\usepackage{xargs}
%---------------------------------------------------------------------
% % Macro to find the number of pages of included PDF document
%---------------------------------------------------------------------
\makeatletter
\newcounter{imagepage}
\newcommand*{\foreachpage}[2]{
\begingroup
\sbox0{\includegraphics{#1}}
\xdef\foreachpage@num{\the\pdflastximagepages}
\endgroup
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\foreachpage@num\do{
\stepcounter{imagepage}
#2\relax
}
}
\makeatother
%---------------------------------------------------------------------
% % Macro to include PDF document with page numbers in caption and label
%---------------------------------------------------------------------
\makeatletter
\newcommandx{\picTEST}[5][1=0.9, 2=0]
{
\foreachpage{#4}
{
\begin{figure}[h!]
\centering
\makebox[\textwidth]{\includegraphics[width=#1\hsize,page=\value{imagepage},angle=#2]{#4}}
\label{#3\theimagepage}
\caption{#5 - Page \arabic{imagepage} of {\the\pdflastximagepages}}
\end{figure}
\clearpage
}
}
\makeatother
\begin{document}
\section{Some Text}
Here is reference to page \ref{Document1_Label_Page3} of the included PDF document.
\newpage
\section{Some insert of PDF document}
\picTEST{Document1_Label_Page}{Document1.pdf}{Document1}
\end{document}
The problem is that the label in the text does not expand as a number '3', but I get '??' instead. However, when I click on '??' in the text, the cross-referencing to the page number 3 of the included PDF document works well - it jumps to this page (or better say to this figure).
I suppose the problem is in the second macro \picTEST
where I use \label{#3\theimagepage}
and maybe in the text where I am referencing \ref{Document1_Label_Page3}
. I would very kindly ask for support. Please use some example multi page PDF document named Document1.pdf
.
Document1.pdf
etc. at hand.\label
after\caption
and you are referring to page3
(as far as I understand it, but does your document have a page3
at all?)pdfpages
package?pdfpages
does not do the job in my case since, if I am not mistaken, it simply attaches the PDF document without keeping the defined layout (header, footer, etc.) of the main tex document.