19

This question led to a new package:
intopdf

Aim

I want to achieve following:

  1. Embed paper.bib into PDF

  2. paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex

  3. Have paper.bib listed in the attachment section in Acrobat Reader

    attachment view

  4. The attachment section should have a proper description

  5. Have paper.bib listed in the "\EmbedFiles" in PDF (can be checked with Acrobat Pro)

    EmbedFiles

  6. Have paper.bib listed in the bookmarks section

    bookmarks section in SumatraPDF

  7. Have a working link to paper.bib in the PDF

    working link

    single click

  8. Have the link visible also in the printed version

  9. No strange additional icon. Following should not appear:

    strange icon

  10. Link should be marked as link

    marked link

Related questions:

Tried solutions

1. embedfile together with hypgotoe

\documentclass {article}
\usepackage{mwe}
\usepackage{filecontents}
\usepackage{embedfile}
\usepackage{hypgotoe}

\begin{filecontents}{paper.bib}
@article{demo,
  author={Demo Author}
}
\end{filecontents}

\begin{document}

\embedfile[
  desc={BibTeX entry of this paper},
  mimetype=application/x-bibtex
]{paper.bib}

\href{gotoe:embedded=paper.bib}{BibTeX}

\end{document}
  1. YES: Embed paper.bib into PDF
  2. YES: paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  3. YES: Have paper.bib listed in the attachment section in Acrobat Reader
  4. YES: The attachment section should have a proper description
  5. YES: Have paper.bib listed in the "\EmbedFiles" in PDF
  6. Partially: Have paper.bib listed in the bookmarks section (OK: SumatraPDF, NOT OK: Acrobat Pro X)
  7. NO: Have a working link to paper.bib in the PDF. SumatraPDF opens the tex file, Acrobat Reader does nothing
  8. YES: Have the link visible also in the printed version
  9. YES: No strange additional icon
  10. YES: Link should be marked as link

2. navigator

\documentclass {article}
\usepackage{mwe}
\usepackage{filecontents}
\usepackage{navigator}

\begin{filecontents}{paper.bib}
@article{demo,
  author={Demo Author}
}
\end{filecontents}

\begin{document}

\embeddedfile[BibTeX entry of this paper]{paper.bib}{paper.bib}

\openfilelink{paper.bib}{BibTeX}

\end{document}
  1. YES: Embed paper.bib into PDF
  2. YES: paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  3. YES: Have paper.bib listed in the attachment section in Acrobat Reader
  4. YES: The attachment section should have a proper description
  5. YES: Have paper.bib listed in the "\EmbedFiles" in PDF
  6. NO: Have paper.bib listed in the bookmarks section
  7. PARTIALLY: Have a working link to paper.bib in the PDF: Double click opens file in SumatraPDF, not working in Acrobat Reader
  8. YES: Have the link visible also in the printed version
  9. YES: No strange additional icon
  10. NO: Link should be marked as link

3. attachfile

\documentclass {article}
\usepackage{mwe}
\usepackage{filecontents}
\usepackage{attachfile}

\begin{filecontents}{paper.bib}
@article{demo,
  author={Demo Author}
}
\end{filecontents}

\begin{document}

% We need "doubleprint", because the text of \textattachfile is not printed when printing a PDF
% We use the idea from https://tex.stackexchange.com/a/19045/9075, accepting that
% the pointers to the files are renderedin semi-bold way
\newlength{\Urlname}
\newcommand{\doubleprint}[1]{\setlength{\Urlname}{\widthof{#1}}\hspace{-\Urlname}#1}

\textattachfile[%
  print=true,%
  color=0 0 0,%
  icon=Paperclip,%
  description={BibTeX entry of this paper},%
  mimetype=application/x-bibtex%
]{paper.bib}{BibTeX}%
\doubleprint{BibTeX}

\end{document}
  1. YES: Embed paper.bib into PDF
  2. YES: paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  3. YES: Have paper.bib listed in the attachment section in Acrobat Reader
  4. YES: The attachment section should have a proper description
  5. NO: Have paper.bib listed in the "\EmbedFiles" in PDF not embedded
  6. NO: Have paper.bib listed in the bookmarks section
  7. Partially: Have a working link to paper.bib in the PDF. Double Click in Acrobat Reader, single click in SumatraPDF
  8. YES: Have the link visible also in the printed version
  9. NO: Strange additional icon Acrobat Reader
  10. NO: Link should be marked as link
Debug Information

The /Type /Embeddedfile entry is appearing next to the embedding text in the PDF, not in the global file catalog:

Embedded File Information

The icon is because of the attachment. In Acrobat Pro, one can drag'n'drop the attachment:

Draggable Attachment

4. embedfile together with stackoverflow tweaks

This solution extends the first solution with

Proposal:

\documentclass {article}
\usepackage{mwe}
\usepackage{filecontents}
\usepackage{embedfile}
\usepackage{hyperref}
\usepackage[atend]{bookmark}

% How do I make an attached non-pdf file display like a link?
% (http://tex.stackexchange.com/q/230581)
\makeatletter
\newcommand*{\embeddedfilelink}[2]{%
  \begingroup
    \leavevmode
    \pdfstartlink
      attr{%
        \Hy@setpdfborder
        \ifx\@pdfhighlight\@empty
        \else
          /H\@pdfhighlight
        \fi
        \ifx\@filebordercolor\relax
        \else
          /C[\@filebordercolor]%
        \fi
      }%
      user{%
       /Subtype/Link%
       /A<<%
         /Type/Action%
         /S/JavaScript%
         /JS(this.exportDataObject({cName: "#1", nLaunch: 2}))%
       >>%
      }%
      \relax
    \Hy@colorlink\@filebordercolor#2%
    \close@pdflink
  \endgroup
}
\makeatother

\begin{filecontents}{paper.bib}
@article{demo,
  author={Demo Author}
}
\end{filecontents}

\begin{document}

\embedfile[
  desc={BibTeX entry of this paper},
  mimetype=application/x-bibtex
]{paper.bib}

\embeddedfilelink{paper.bib}{BibTeX}
%hint from https://tex.stackexchange.com/a/260439/9075
\BookmarkAtEnd{
  \bookmarksetup{startatroot}
  \bookmark[level=0,rawaction={
    /S/JavaScript/JS(%
      this.exportDataObject({cName: "paper.bib", nLaunch: 2})%
    )%
  }]{paper.bib}
}

\end{document}
  1. YES: Embed paper.bib into PDF
  2. YES: paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  3. YES: Have paper.bib listed in the attachment section in Acrobat Reader
  4. YES: The attachment section should have a proper description
  5. YES: Have paper.bib listed in the "\EmbedFiles" in PDF
  6. Partially: Have paper.bib listed in the bookmarks section (Twice in SumatraPDF, OK: Acrobat Pro X)
  7. Partially: Have a working link to paper.bib in the PDF. SumatraPDF opens the tex file, Acrobat Reader opens the correct application
  8. YES: Have the link visible also in the printed version
  9. YES: No strange additional icon
  10. YES: Link should be marked as link

Debugging hints

The tools to list the internal PDF structure are discussed at Best tool for inspecting PDF files?. The screenshots above are made by Acrobat Professional X. iText RUPS seems to be close to Acrobat Professional's capabilities.

Question

How to achieve that eat least following goals are met:

  1. paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  2. Have paper.bib listed in the attachment section in Acrobat Reader
  3. The attachment section should have a proper description
  4. Have paper.bib listed in the bookmarks section
  5. Have a working link to paper.bib in the PDF
  6. Have the link visible also in the printed version

Optionally, following would be good:

  1. No strange additional icon.
  2. Link should be marked as link
6
  • 5
    +1 for the research effort. Links to embedded PDF files are supported by AR at least. If you resort to JavaScript, you will loose most of the PDF viewers. Commented Mar 5, 2018 at 19:55
  • @HeikoOberdiek Doesn't this conflate different things? I thought that bookmarks pointed to things in this file; links pointed to things either in this file or somewhere else; embedded and attached files are distinct kinds of things, neither of which are in this file. So how can it make sense to have an embedded or attached file in the bookmarks? I could understand having a link and, say, including the point at which that link appears in the bookmarks. But the book mark will point to that bit of this document and not the embedded or attached file. Can the desiderata be understood as consistent?
    – cfr
    Commented Mar 6, 2018 at 1:36
  • @cfr A PDF bookmark can have different kind of actions. It is not restricted to links. Commented Mar 6, 2018 at 5:58
  • For me, attachfile looks the most promising. If only SumatraPDF shows the Bookmark and Acrobat Reader in the "Attached Files" tab, it is OK for me. Maybe, there is no solution, because attachfile attaches the file using an annotation (/T:Annot /S:FileAttachment; therefore also the icon) and this annotation enables the viewers to correctly treat the file.
    – koppor
    Commented Mar 6, 2018 at 7:04
  • @HeikoOberdiek I didn't know that. I always thought they were bookmarks, albeit of an electronic variety. I guess I thought you needed other elements for other functions.
    – cfr
    Commented Mar 6, 2018 at 21:50

1 Answer 1

9

This solution does not solve all the problems, but it didn't fit into a comment:

This is similar to attachfile, but without \doubleprint and 9, 10 fixed and making the annotation unmovable:

\documentclass {article}
\usepackage{mwe}
\usepackage{filecontents}
\usepackage{hyperref}

\begin{filecontents}{paper.bib}
@article{demo,
  author={Demo Author}
}
\end{filecontents}

\makeatletter
\newcommand\attachandlink[4]{%
  \leavevmode%
  \immediate\pdfobj stream attr {
    /Subtype /\pdfescapename{#2}
  } file{#1}%
  \immediate\pdfobj{<<
    /Type /Filespec
    /F (\pdfescapestring{#1})
    /EF << /F \the\pdflastobj\space 0 R >>
  >>}%
  \pdfstartlink user {
    /Subtype /FileAttachment
    /FS \the\pdflastobj\space 0 R
    /F 416
    /CA 0
    /Contents (\pdfescapestring{#3 Double click to open.})
  }%
  \pdfstartlink attr{
    \Hy@setpdfborder
    \ifx\@pdfhighlight\@empty%
    \else%
      /H\@pdfhighlight
    \fi%
    \ifx\@urlbordercolor\relax%
    \else%
      /C[\@urlbordercolor]
    \fi%
  } user {
    /Subtype /Link
  }%
  #4%
  \pdfendlink%
  \pdfendlink%
}
\makeatother

\begin{document}

\attachandlink{paper.bib}{application/x-bibtex}{BibTeX entry for this paper}{BibTeX}

\end{document}
  1. YES: Embed paper.bib into PDF
  2. YES: paper.bib should be opened with the OS tool associated with mimetype application/x-bibtex
  3. YES: Have paper.bib listed in the attachment section in Acrobat Reader
  4. YES: The attachment section should have a proper description
  5. NO: Have paper.bib listed in the "/EmbeddedFiles" in PDF 
  6. NO: Have paper.bib listed in the bookmarks section
  7. YES: Have a working link to paper.bib in the PDF, double click is required on Adobe Reader
  8. YES: Have the link visible also in the printed version
  9. YES/NO: Strange additional icon in Adobe Reader only on Mouseover
  10. YES: Link should be marked as link

The Goal 5, listed in /EmbeddedFiles, would be easy to add and probably would add paper.bib to the bookmarks section in SumatraPDF as well (I'm not sure about this one, I couldn't get SumatraPDF to show a bookmarks section for any PDF), but there would be side effects: To open the embedded file without Javascript in Adobe Reader, it has to be added as a File Attachment Annotation at a special location, while files referenced in the /EmbeddedFiles directory are attached to the whole document. One file can be referenced in both ways, but then Acrobat Reader for example will list the file twice.

8
  • Thank you! i) Goal 5: I saw the bookmarks at some of the minimal examples above. Seems, it just crawls the /EmbeddedFiles section. I also encountered the double listing when using \embedfile in addition to textattachfile. So, no boomarks. ii) my Acrobat Reader DC does not show any desription, but his should be fixable easily. iii) SumatraPDF opens the file with a single click. Great. iv) Acrobat Reader does not show the link cursor, but the text cursor. I also need to double click, which is not the common thing for that colored links. Can there be done something about it?
    – koppor
    Commented Mar 7, 2018 at 0:54
  • I fixed ii), but this caused the icon to reappear. Sadly the attached files /Desc is ignored by Adobe Reader for File Annotations and the only alternative is adding Content to the annotation causing the icon. I added some flags to hide the icon except on mouseover or when the annotation is clicked. Commented Mar 7, 2018 at 2:11
  • Thank you four patience. a) I got a description now in Acrobat Reader DC and PDF-XChange Viewer. Very nice. b) With double click, the file is opened. With the fourth solution (emabedfile-tweaked), I I just need a single link in Acrobat Reader. In case this is hard to achieve, maybe the tooltip should be extended with "Double click to open". In SumatraPDF everything works fine. No action in PDF-XChange viewer, but this is OK for me, since I do not use that tool.
    – koppor
    Commented Mar 7, 2018 at 8:19
  • @kopporOpening the file with a single click is only possible with Javascript, which does not work with SumatraPDF. I tried combining this with the navigator approach to add SumatraPDF support, but on my system SumatraPDF could not even open the link in the navigator example. The Tooltip can't controled independent from the file description because Adobe ignores most other fields for file attachments, so we would have to add "Double click to open" to the description. Commented Mar 7, 2018 at 11:04
  • 1
    +1: You have amazing packages on CTAN. Commented Feb 7, 2020 at 6:48

You must log in to answer this question.

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