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.

Pedro
  • 373

1 Answers1

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}
Heiko Oberdiek
  • 271,626
  • 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 08 '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. – Heiko Oberdiek Aug 08 '15 at 21:24
  • What about using javascript? Is it possible to use, for instance, the insDLJS package and hard code it? – Pedro Aug 08 '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 08 '15 at 21:38
  • Hi alfC. Yes, I'm trying to avoid the file being open in internet browser and the solution proposed by Heiko does not solve that. The thing is that the user might be suspicious seeing a file being open through the internet browser. Moreover, if the file is encapsulated in the PDF, then it is better to open it instead of accessing it locally. – Pedro Aug 08 '15 at 22:16
  • @Pedro The wrong OS and the wrong choice for the web browser default are nothing, that can be fixed by a PDF file. – Heiko Oberdiek Aug 09 '15 at 03:00
  • @Pedro I do not see, that JavaScript here helps in saving the embedded file as external file and open that external file. – Heiko Oberdiek Aug 09 '15 at 03:26
  • The embedded file can be exported using the exportDataObject() Acrobat JavaScript method. It will, most likely, be supported only by the Adobe PDF viewers, and no others… This method does have an argument which controls whether the extracted file will be just saved, or also opened in its default application. – Max Wyss Aug 09 '15 at 10:10
  • @MaxWyss Many thanks, I have updated the question with an example, how this can be used. – Heiko Oberdiek Aug 09 '15 at 11:00
  • 1
    Thank you all for your contribution! That completly solve my problem! – Pedro Aug 09 '15 at 12:13