typst icon indicating copy to clipboard operation
typst copied to clipboard

PDF file attachments

Open miliog opened this issue 1 year ago • 4 comments

Description

I'd like to be able to create PDF attachments.

ed08 png img (Screenshot from https://helpx.adobe.com/acrobat/using/links-attachments-pdfs.html#)

Use Case

It's very convenient to add file attachments to the PDF itself. Not only Acrobat Reader, but also many open source readers support it.

miliog avatar Oct 26 '23 15:10 miliog

Here is an example code in LaTeX that shows how to embed the file in the list of embedded files, set the flags and also reuse the embedded binary in a File Attachement Annotation. Maybe it helps the person who wants to implement this.

\pdfcompresslevel=0
\pdfobjcompresslevel=0

\documentclass[a4paper]{article}

\usepackage{embedfile}
\usepackage{attachfile2}
\expandafter\xdef\csname theatfi@flags\endcsname{704}
\newcommand{\clickablefile}[2]{%
\embedfile[ucfilespec={#1}]{#1}%
%\expandafter\xdef\csname atfi@embed@file@#1\endcsname{\the\numexpr\pdflastobj-1}%
\expandafter\xdef\csname atfi@fileobj@#1\endcsname{\the\numexpr\pdflastobj-1}%
\textattachfile[ucfilespec={#1},icon={Paperclip}]{#1}{#2}%
}

\begin{document}

\clickablefile{test.txt}{Double click to export the file}

\end{document}

embed.pdf

ghost avatar Oct 26 '23 18:10 ghost

This seems like a good-contribution, the relevant sections in the PDF 1.7 spec are 12.5.6.15 and 7.11.4, these features would have to be upstreamed into pdf-wirter before typst can support this.

tingerrr avatar Oct 26 '23 19:10 tingerrr

... these features would have to be upstreamed into pdf-wirter before typst can support this.

As far as I can tell, pdf-writer has support for this already: https://github.com/typst/pdf-writer/commit/ba040ace792d57a2e57e4973a38abb1561cdc057

awehrfritz avatar Feb 08 '24 11:02 awehrfritz