# Finding the physical page number of a particular logical page

I need to fetch some part from a pdf file (e.g. with pdftk). The page numbers as given in the table of contents are logical numbers (for example Roman numbers I to XX in the front-matter, main-matter starting with Arabic 1, although being the 21st physical page). Can I get physical numbers of pages for a particular part of a generated document (section, subsection, paragraph...)?

-
It isn't clear what you are asking. Could you expand a little on what you want, and explain what you have tried to do so far? – Seamus Feb 28 '12 at 10:24
I have pdf, which was got from pdflatex and name of toc record, I need know what phisical pages this part (under this record) ocсupy and fetch this pages from pdf programmatically (with pdftk, for example). But there are logical (relative) numders of pages in toc file, while I need absolute in all document. Is there any way to know this? – Andrew Feb 28 '12 at 11:18
You want to fetch the physical page numbers corresponding to specific logical page numbers that appear in the toc? For every page? for particular pages? – Seamus Feb 28 '12 at 11:53
yes, exactly. For particular sections, subsection.. – Andrew Feb 28 '12 at 13:16
"For the logical page numbers display of the pdf file use logical page numbers together with hyperref! - In Adobe Reader X enable: Edit > Preferences (Ctrl+k) > Page Display > Page Content and Information > Use logical page numbers . - Use the hyperref package with option plainpages=false . The display will be e.g. 7 (7 of 9), or, in case of Roman instead of arabic numbers, VII (7 of 9), and when different page numbers are used [...] e.g. arabic after 10 Roman pages: 17 (27 of 30). Please try this with the compiled pageslts-example file!" (to be continued)... – Stephen Feb 28 '12 at 19:26

A) The get the "physical" number of a page of a PDF document, there are different possibilities, for example:

• manual counting (of course; might be cumbersome as well as prone to errors)

• using Adobe Reader to show also the physical page number: "For the logical page numbers display of the pdf file use logical page numbers together with hyperref! - In Adobe Reader X enable: Edit > Preferences (Ctrl+k) > Page Display > Page Content and Information > Use logical page numbers. - Use the hyperref package with option plainpages=false . The display will be e.g. 7 (7 of 9), or, in case of Roman instead of arabic numbers, VII (7 of 9), and when different page numbers are used [...] e.g. arabic after 10 Roman pages: 17 (27 of 30). Please try this with the compiled pageslts-example file!" (page 4 of pageslts manual)

• using the pageslts package to print the physical page number (\theCurrentPage) in the footer:

\documentclass{article}

\usepackage{pageslts}

\makeatletter
\renewcommand{\@evenfoot}{%
\hspace*{\fill}%
Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})%
\hspace*{\fill}%
}
\renewcommand{\@oddfoot}{\@evenfoot}
\makeatother

\begin{document}
\pagenumbering{roman}
Test
\newpage
More test text.
\newpage
\pagenumbering{arabic}
Now look at the first number in the parentheses in the footer!

\end{document}


This will need at least two compiler runs. When you have determined the page numbers you are looking for, you can just remove the code between \makeatletter and \makeatother and recompile.

B) "I need to fetch some part from a pdf file". For this you do not necessarily need to know the physical page numbers. For example you could use the selectp package. For example

\documentclass{article}

\usepackage{selectp}
\outputonly{1,0,1}

\begin{document}
\pagenumbering{roman}
Test
\newpage
More test text.
\newpage
\pagenumbering{arabic}
Still more text.

\end{document}


will allow only pages i (1; 1 of 3) and 1 (3 of 3) to be output. The order is not random but must be the order that the pages are produced; normally this means the numbers must always increase.

With roman numbers: 1-3, 1-3 prints the pages i-iii, 1-3

and 0, 1-3 prints the pages 1-3.

It needs a complete compiled file before use! (And you must translate e.g. i to 1, but that should not be an issue.)

-

Just a few lines to complete Stephen's answer for people using the memoir class:

\documentclass[a4paper,english, final]{memoir}

\usepackage{lipsum}
\usepackage{pageslts}

\makeevenfoot{ruled}{}{}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}
\makeoddfoot{ruled}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}{}{}
\makeevenfoot{plain}{}{}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}
\makeoddfoot{plain}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}{}{}
\makeevenfoot{empty}{}{}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}
\makeoddfoot{empty}{Page \thepage\ (\theCurrentPage\ of \lastpageref{LastPages})}{}{}

\title{This is a test document}
\author{Myself}

%------------------------------------------------------------

\begin{document}

\pagestyle{ruled}

\frontmatter
\maketitle
\tableofcontents

\mainmatter

\chapter{Chapter 1}

\section{First section}
\lipsum
\section{Second section}
\lipsum

\end{document}


Because you reset the foot for all styles, it will be changed on all pages (even for chapter and title pages).

-
Good to know this, thanks for adding it. +1! – Stephen Dec 4 '12 at 19:47