6

I would like to send my colleague just part of a document. The document includes hyperlinks from the hyperref package for clickable cross-referencing within my document.

I have tried to create a PDF that is a subset of the pages in the larger PDF file by using the "print to file" feature in evince. It works to create a PDF with just some of the pages, but it does not preserve the hyperlinks from hyperref. How can I create a PDF with just a subset of the pages from the original PDF yet preserve the hyperlinks?

UPDATE: related: Compiling only a page range or page selection.

UPDATE 2: Though Adam Liter's solution works for me, for a (preferable) solution within LaTex see Heiko Oberdiek' answer below.

Adam Liter
  • 12,567
wondering
  • 741
  • @ChristianHupfer So where/how to ask? – wondering Feb 28 '15 at 18:20
  • Not sure if it works, but you might try the command line tool pdftk for splicing up the PDF. It might preserve the hyperlinks. – Adam Liter Feb 28 '15 at 18:49
  • @AdamLiter Although I am used to using pdftk, for some reason I thought the solution would be more difficult. pdftk works, you might want to post it as answer that I would accept? :-) – wondering Feb 28 '15 at 19:29
  • 1
    I'll post it as an answer so it's more obvious to anyone else who sees this question, but I agree that it should probably ultimately be closed since it's not really a (La)TeX question. – Adam Liter Feb 28 '15 at 19:43
  • 2
    The question is, how to generate a part of a LaTeX document while preserving links (of course except links, which point outside the selected part of the document). Thus the question is very on-topic. Even pure LaTeX solutions exist, see the \include feature or package pagesel. Therefore the question should be reopened. – Heiko Oberdiek Feb 28 '15 at 20:18
  • 1
    @HeikoOberdiek That's a good point. Despite what I said before, I'll also vote to reopen the question. But if it is reopened, then I think it should be reworded. Or, minimally, the title should be changed to something like "How to preserve hyperlinks in PDF when creating PDF with a subset of pages in original PDF". Or something like that. The way that the title and the question itself are worded suggest that the problem is with evince, which makes it seem off-topic. – Adam Liter Feb 28 '15 at 21:49
  • @ChristianHupfer The evince stuff is only a failed try to find a solution. The question is clearly not about doing it in evince. And since the base is a LaTeX document and even solutions in LaTeX exist, this is very on-topic. – Heiko Oberdiek Feb 28 '15 at 22:50
  • wondering: I've taken the liberty of editing your question to make it more on topic for the site now that it has been reopened. If you don't like my changes, please feel free to rollback the edit, but I think the community would appreciate it if the question were worded differently from how you originally posted it now that it has been reopened. So if you do rollback the edit, could you please also reword it using your own words? @HeikoOberdiek: you should go ahead and provide an alternative answer now! :) – Adam Liter Feb 28 '15 at 23:37
  • @AdamLiter I am happy with the result, thanks! :-) – wondering Mar 01 '15 at 00:14
  • @AdamLiter Answer is added. – Heiko Oberdiek Mar 01 '15 at 09:20
  • @ChristianHupfer No problem for me, the question is now reopened and the question is even improved. – Heiko Oberdiek Mar 01 '15 at 09:23

2 Answers2

7

For a non-TeX solution: you can use the command line tool pdftk to splice up the original PDF and make a new PDF with just a subset of the pages from the original PDF. This will preserve the hyperlinks from the original PDF.

Adam Liter
  • 12,567
5

Also LaTeX solutions are available.

\include, \includeonly

The document can be divided at page boundaries into single files, e.g. chapters. These are then included via \include. Then \includeonly with the file names, which should be included. Example:

\documentclass{book}
\usepackage{hyperref}

\includeonly{Summary}

\begin{document}
  \include{Introduction}
  \include{Theory}
  \include{Experiments}
  \include{Results}
  \include{Summary}
\end{document}

Package pagesel

Package pagesel can be used, if certain pages should be selected, e.g.:

\documentclass{book}
\usepackage[1,11]{pagesel}
\usepackage{hyperref}
\begin{document}
  \tableofcontents
  \chapter{Introduction}
  \chapter{Theory}
  \chapter{Experiments}
  \chapter{Results}
  \chapter{Summary}
\end{document}

The document is compiled first without package pagesel to get correct/updated auxiliary files. With pagesel, the auxiliary files are not written by default, but used and the selected pages are output.

Links pointing outside the selected range

hyperref does not know, which pages are excluded, when it generates the links. Depending on the driver, these stale links may be replaced by a link to the beginning of the document, if the links are pointing outside the included range of pages.

Heiko Oberdiek
  • 271,626
  • Thank you! Package pagesel works, though I have some problem with page numbering, it is somehow shifted (and it is not a shift due to Roman numeral numbering in the beginning; I think the problem is in the style I am using, the output pdf has Package atbegshi Warning: Ignoring void shipout box on the top of the first page).

    \include, \includeonly do not work for me, because I want to get rid also of the introductory pages like titlepage, table of contents and much other stuff which (I think) cannot be done using \include.

    – wondering Mar 01 '15 at 10:28
  • Btw. Jeff mentioned here that " include doesn't seem to recognize \label's in the included file" whereas \input does". Is that true? Because if not, this Jeff's statement should be changed because it only confuses - for me the \label's seem to work. Also, I linked this related question to my question. – wondering Mar 01 '15 at 10:29
  • @wondering You can also put the introductory pages into an included file, e.g. (frontmatter.tex). – Heiko Oberdiek Mar 01 '15 at 11:04
  • @wondering \label works with \include, the data are written in .aux files, which are also read, if the file is not included. – Heiko Oberdiek Mar 01 '15 at 11:05
  • Well, true with the frontmatter.tex. In any case, I added a link to your answer in my updated question. – wondering Mar 01 '15 at 12:34