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.

11
  • @ChristianHupfer So where/how to ask?
    – wondering
    Feb 28, 2015 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, 2015 at 18:49
  • 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, 2015 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. Feb 28, 2015 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, 2015 at 21:49

2 Answers 2

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.

6
  • As I said in the comment, this solution works perfectly well. +1
    – wondering
    Feb 28, 2015 at 20:00
  • HOW? I am struggling with this Aug 23, 2018 at 21:18
  • @ChenStatsYu There's an example given in this StackOverflow answer.
    – Adam Liter
    Aug 24, 2018 at 14:02
  • @AdamLiter sorry I might have misread the question/answer. I have no problem in preserving the link on original pages. I was looking for a way to preserve them on 2-up pages, putting two A4 side by side and preserve the links. Aug 24, 2018 at 15:11
  • @ChenStatsYu Oh, I see. I'm not sure that I know how to do that offhand. But yes, it seems like a separate question—although related—question.
    – Adam Liter
    Aug 25, 2018 at 19:44
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.

5
  • 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 1, 2015 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 1, 2015 at 10:29
  • @wondering You can also put the introductory pages into an included file, e.g. (frontmatter.tex). Mar 1, 2015 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. Mar 1, 2015 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 1, 2015 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .