This question led to a new package:
intopdf
Aim
I want to achieve following:
Embed
paper.bibinto PDFpaper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtexHave
paper.biblisted in the attachment section in Acrobat ReaderThe attachment section should have a proper description
Have
paper.biblisted in the "\EmbedFiles" in PDF (can be checked with Acrobat Pro)Have
paper.biblisted in the bookmarks sectionHave a working link to
paper.bibin the PDFHave the link visible also in the printed version
No strange additional icon. Following should not appear:
Link should be marked as link
Related questions:
- How do I make an attached file display like a link?
- How do I make an attached non-pdf file display like a link?
- Opening a non-PDF file clicking on a bookmark
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}
- YES: Embed
paper.bibinto PDF - YES:
paper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtex - YES: Have
paper.biblisted in the attachment section in Acrobat Reader - YES: The attachment section should have a proper description
- YES: Have
paper.biblisted in the "\EmbedFiles" in PDF - Partially: Have
paper.biblisted in the bookmarks section (OK: SumatraPDF, NOT OK: Acrobat Pro X) - NO: Have a working link to
paper.bibin the PDF. SumatraPDF opens thetexfile, Acrobat Reader does nothing - YES: Have the link visible also in the printed version
- YES: No strange additional icon
- 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}
- YES: Embed
paper.bibinto PDF - YES:
paper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtex - YES: Have
paper.biblisted in the attachment section in Acrobat Reader - YES: The attachment section should have a proper description
- YES: Have
paper.biblisted in the "\EmbedFiles" in PDF - NO: Have
paper.biblisted in the bookmarks section - PARTIALLY: Have a working link to
paper.bibin the PDF: Double click opens file in SumatraPDF, not working in Acrobat Reader - YES: Have the link visible also in the printed version
- YES: No strange additional icon
- 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}
- YES: Embed
paper.bibinto PDF - YES:
paper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtex - YES: Have
paper.biblisted in the attachment section in Acrobat Reader - YES: The attachment section should have a proper description
- NO: Have
paper.biblisted in the "\EmbedFiles" in PDF
- NO: Have
paper.biblisted in the bookmarks section - Partially: Have a working link to
paper.bibin the PDF. Double Click in Acrobat Reader, single click in SumatraPDF - YES: Have the link visible also in the printed version
- NO: Strange additional icon Acrobat Reader
- 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:
The icon is because of the attachment. In Acrobat Pro, one can drag'n'drop the 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}
- YES: Embed
paper.bibinto PDF - YES:
paper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtex - YES: Have
paper.biblisted in the attachment section in Acrobat Reader - YES: The attachment section should have a proper description
- YES: Have
paper.biblisted in the "\EmbedFiles" in PDF - Partially: Have
paper.biblisted in the bookmarks section (Twice in SumatraPDF, OK: Acrobat Pro X) - Partially: Have a working link to
paper.bibin the PDF. SumatraPDF opens thetexfile, Acrobat Reader opens the correct application - YES: Have the link visible also in the printed version
- YES: No strange additional icon
- 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:
paper.bibshould be opened with the OS tool associated with mimetypeapplication/x-bibtex- Have
paper.biblisted in the attachment section in Acrobat Reader - The attachment section should have a proper description
- Have
paper.biblisted in the bookmarks section - Have a working link to
paper.bibin the PDF - Have the link visible also in the printed version
Optionally, following would be good:
- No strange additional icon.
- Link should be marked as link









attachfilelooks 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, becauseattachfileattaches 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 Mar 06 '18 at 07:04