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...)?
2 Answers
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
\makeatletterand\makeatotherand 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.)
- 14,890
-
Unfortunately
pagesltsseems to be incompatible withchappg, which allows for page numbers being prefixed with a chapter number... See also this question – Tobias Kienzler Dec 02 '15 at 15:45
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).
- 195
The display will be e.g.
– Stephen Feb 28 '12 at 19:267 (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)...