6

I know it is possible to open a PDF file using bookmarks. But is it possible to open a non-PDF file by clicking on a bookmark?

I've read all documentation from hyperref and bookmark packages but couldn't find any info or example.

I'm guessing it is possible because acrobat lets you do it... I just don't know how to do it using Latex.

EDIT: The non-PDF file was embeded using \embeddedfile and can be found in the PDF attachments.

1
5

Package bookmark also supports URI actions in bookmarks, which can be used to link to other files or URLs.

\documentclass{article}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{open,numbered}
\begin{document}
\section{Hello World}
\bookmark[
  level=subsection,
  uri={https://tex.stackexchange.com/},
]{URI: TeX.SX}
\end{document}

However, it depends on the PDF viewer, to what extend this is supported.

Open embedded files

Thanks to Max Wyss' comment, the example can be extended. A file example-image.png from package mwe is embedded and a bookmark is created, which saves the file to a temporary location and opens the file according to the PDF viewer and OS configuration. A security warning might be raised, before opening the file. The temporary file is deleted at AR's shutdown.

If parameter nLaunch is set to 0, then the file is saved only. If the value is 1, then the file is saved and launched.

When the file is saved permanently, the user is asked for a location unless parameter cDIPath is set for a device-independent path absolute or relative to the current document.

See "JavaScript for Acrobat API Reference" for more details.

\documentclass{article}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{open,numbered}
\usepackage{embedfile}
\begin{document}
\section{Embedded example image}
\embedfile[
  id={example-image},
  desc={example image from package mwe},
]{example-image.png}
\bookmark[
  level=subsection,
  rawaction={%
    /S/JavaScript/JS(%
      this.exportDataObject({cName: "example-image.png", nLaunch: 2})%
    )%
  },
]{Embedded: example-image.png}
\bookmark[
  level=subsection,
  uri={https://tex.stackexchange.com/},
]{URI: TeX.SX}
\end{document}
10
  • The question was edited to mention that the non-PDF file can be found in the attachments. It was embeded using \embeddedfile. In that case how to do it?
    – Pedro
    Aug 8 '15 at 21:19
  • An embedded PDF file could be opened by AR, there is an action for going to embedded PDF files. But this does not work for non-PDF files. Embedded files can be managed by the embedded pane. Aug 8 '15 at 21:24
  • What about using javascript? Is it possible to use, for instance, the insDLJS package and hard code it?
    – Pedro
    Aug 8 '15 at 21:34
  • This method also works with files (specified in relative paths), pdf or otherwise. It works in Evince and Acrobat (Linux). Although in Acrobat files tend to be opened by the internet browser.
    – alfC
    Aug 8 '15 at 21:38
  • 1
    Thank you all for your contribution! That completly solve my problem!
    – Pedro
    Aug 9 '15 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.