3 %% This is a modified version of `embedfile.sty' generated from a
4 %% modified `embedfile.dtx' incorporating the following pull request:
5 %% https://github.com/ho-tex/oberdiek/pull/72
7 %% This PR adds support for creating PDF/A-compliant attachments. See
8 %% also the following issue:
9 %% https://github.com/ho-tex/oberdiek/issues/37
11 %% !!END OF NOTE NOTE NOTE!!
14 %% This is file `embedfile.sty',
15 %% generated with the docstrip utility.
17 %% The original source files were:
19 %% embedfile.dtx (with options: `package')
21 %% This is a generated file.
24 %% Version: 2018/11/01 v2.8
26 %% Copyright (C) 2006-2011 by
27 %% Heiko Oberdiek <heiko.oberdiek at googlemail.com>
29 %% This work may be distributed and/or modified under the
30 %% conditions of the LaTeX Project Public License, either
31 %% version 1.3c of this license or (at your option) any later
32 %% version. This version of this license is in
33 %% http://www.latex-project.org/lppl/lppl-1-3c.txt
34 %% and the latest version of this license is in
35 %% http://www.latex-project.org/lppl.txt
36 %% and version 1.3 or later is part of all distributions of
37 %% LaTeX version 2005/12/01 or later.
39 %% This work has the LPPL maintenance status "maintained".
41 %% This Current Maintainer of this work is Heiko Oberdiek.
43 %% The Base Interpreter refers to any `TeX-Format',
44 %% because some files are installed in TDS:tex/generic//.
46 %% This work consists of the main source file embedfile.dtx
47 %% and the derived files
48 %% embedfile.sty, embedfile.pdf, embedfile.ins, embedfile.drv,
49 %% dtx-attach.sty, embedfile-example-plain.tex,
50 %% embedfile-example-collection.tex, embedfile-test1.tex,
51 %% embedfile-test2.tex, embedfile-test3.tex,
52 %% embedfile-test4.tex.
54 \begingroup\catcode61\catcode48\catcode32=10\relax%
66 \expandafter\let\expandafter\x\csname ver@embedfile.sty\endcsname
67 \ifx\x\relax % plain-TeX, first loading
70 \ifx\x\empty % LaTeX, first loading,
71 % variable is initialized, but \ProvidesPackage not yet seen
73 \expandafter\ifx\csname PackageInfo\endcsname\relax
75 \immediate\write-1{Package #1 Info: #2.}%
78 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
80 \x{embedfile}{The package is already loaded}%
85 \begingroup\catcode61\catcode48\catcode32=10\relax%
102 \expandafter\ifx\csname ProvidesPackage\endcsname\relax
103 \def\x#1#2#3[#4]{\endgroup
104 \immediate\write-1{Package: #3 #4}%
108 \def\x#1#2[#3]{\endgroup
118 \expandafter\x\csname ver@embedfile.sty\endcsname
119 \ProvidesPackage{embedfile}%
120 [2018/11/01 v2.8 Embed files into PDF (HO)]%
121 \begingroup\catcode61\catcode48\catcode32=10\relax%
128 \expandafter\edef\csname EmFi@AtEnd\endcsname{%
129 \endlinechar=\the\endlinechar\relax
130 \catcode13=\the\catcode13\relax
131 \catcode32=\the\catcode32\relax
132 \catcode35=\the\catcode35\relax
133 \catcode61=\the\catcode61\relax
134 \catcode64=\the\catcode64\relax
135 \catcode123=\the\catcode123\relax
136 \catcode125=\the\catcode125\relax
139 \x\catcode61\catcode48\catcode32=10\relax%
146 \def\TMP@EnsureCode#1#2{%
149 \catcode#1=\the\catcode#1\relax
153 \TMP@EnsureCode{39}{12}% '
154 \TMP@EnsureCode{40}{12}% (
155 \TMP@EnsureCode{41}{12}% )
156 \TMP@EnsureCode{44}{12}% ,
157 \TMP@EnsureCode{46}{12}% .
158 \TMP@EnsureCode{47}{12}% /
159 \TMP@EnsureCode{58}{12}% :
160 \TMP@EnsureCode{60}{12}% <
161 \TMP@EnsureCode{62}{12}% >
162 \TMP@EnsureCode{91}{12}% [
163 \TMP@EnsureCode{93}{12}% ]
164 \TMP@EnsureCode{96}{12}% `
165 \edef\EmFi@AtEnd{\EmFi@AtEnd\noexpand\endinput}
166 \begingroup\expandafter\expandafter\expandafter\endgroup
167 \expandafter\ifx\csname RequirePackage\endcsname\relax
168 \def\EmFi@RequirePackage#1[#2]{%
172 \let\EmFi@RequirePackage\RequirePackage
174 \EmFi@RequirePackage{infwarerr}[2007/09/09]%
176 \@PackageError{embedfile}%
178 \ifx\pdfextension\@undefined\else
179 \protected\def\pdflastobj {\numexpr\pdffeedback lastobj\relax}
180 \protected\def\pdfnames {\pdfextension names }
181 \protected\def\pdfobj {\pdfextension obj }
182 \let\pdfoutput \outputmode
184 \EmFi@RequirePackage{ifpdf}[2007/09/09]
188 Missing pdfTeX in PDF mode%
190 Currently other drivers are not supported. %
191 Package loading is aborted.%
193 \expandafter\EmFi@AtEnd
195 \EmFi@RequirePackage{pdftexcmds}[2007/11/11]
196 \EmFi@RequirePackage{ltxcmds}[2010/03/01]
197 \EmFi@RequirePackage{kvsetkeys}[2010/03/01]
198 \EmFi@RequirePackage{kvdefinekeys}[2010/03/01]
199 \begingroup\expandafter\expandafter\expandafter\endgroup
200 \expandafter\ifx\csname pdf@filesize\endcsname\relax
202 Unsupported pdfTeX version%
204 At least version 1.30 is necessary. Package loading is aborted.%
206 \expandafter\EmFi@AtEnd
208 \EmFi@RequirePackage{pdfescape}[2007/11/11]
210 \expandafter\EdefSanitize\csname EmFi@S@#1\endcsname{#1}%
220 \EmFi@temp{afrelationship}
222 \EmFi@temp{creationdate}
224 \EmFi@temp{ascending}
225 \EmFi@temp{descending}
228 \ltx@newif\ifEmFi@collection
229 \ltx@newif\ifEmFi@sort
230 \ltx@newif\ifEmFi@visible
231 \ltx@newif\ifEmFi@edit
232 \ltx@newif\ifEmFi@item
233 \ltx@newif\ifEmFi@finished
235 \def\EmFi@GlobalKey#1#2{%
236 \global\expandafter\let\csname KV@#1@#2\expandafter\endcsname
237 \csname KV@#1@#2\endcsname
239 \def\EmFi@GlobalDefaultKey#1#2{%
240 \EmFi@GlobalKey{#1}{#2}%
241 \global\expandafter\let
242 \csname KV@#1@#2@default\expandafter\endcsname
243 \csname KV@#1@#2@default\endcsname
245 \def\EmFi@DefineKey#1#2{%
246 \kv@define@key{EmFi}{#1}{%
247 \expandafter\def\csname EmFi@#1\endcsname{##1}%
249 \expandafter\def\csname EmFi@#1\endcsname{#2}%
251 \EmFi@DefineKey{mimetype}{}
252 \EmFi@DefineKey{filespec}{\EmFi@file}
253 \EmFi@DefineKey{ucfilespec}{}
254 \EmFi@DefineKey{filesystem}{}
255 \EmFi@DefineKey{desc}{}
256 \EmFi@DefineKey{afrelationship}{}
257 \EmFi@DefineKey{stringmethod}{%
258 \ifx\pdfstringdef\@undefined
261 \ifx\pdfstringdef\relax
268 \kv@define@key{EmFi}{id}{%
274 \expandafter\xdef\csname EmFi@#1@\EmFi@id\endcsname{%
275 \the\pdflastobj\ltx@space 0 R%
279 \def\embedfileifobjectexists#1#2{%
280 \expandafter\ifx\csname EmFi@#2@#1\endcsname\relax
281 \expandafter\ltx@secondoftwo
283 \expandafter\ltx@firstoftwo
286 \def\embedfilegetobject#1#2{%
287 \embedfileifobjectexists{#1}{#2}{%
288 \csname EmFi@#2@#1\endcsname
293 \kv@define@key{EmFi}{view}[]{%
294 \EdefSanitize\EmFi@temp{#1}%
296 \global\EmFi@collectiontrue
298 \ifx\EmFi@temp\ltx@empty
299 \let\EmFi@view\EmFi@S@details
300 \else\ifx\EmFi@temp\EmFi@S@details
301 \let\EmFi@view\EmFi@S@details
302 \else\ifx\EmFi@temp\EmFi@S@tile
303 \let\EmFi@view\EmFi@S@tile
304 \else\ifx\EmFi@temp\EmFi@S@hidden
305 \let\EmFi@view\EmFi@S@hidden
309 Unknown value `\EmFi@temp' for key `view'.\MessageBreak
310 Supported values: `details', `tile', `hidden'.%
315 \EmFi@DefineKey{initialfile}{}
316 \def\embedfilesetup{%
320 \string\embedfilefield\ltx@space after \string\embedfilefinish
322 The list of embedded files is already written.%
333 \let\EmFi@@order\relax
334 \def\EmFi@fieldlist{}
335 \def\EmFi@sortcase{0}%
336 \def\embedfilefield#1#2{%
339 \string\embedfilefield\ltx@space after \string\embedfilefinish
341 The list of embedded files is already written.%
344 \global\EmFi@collectiontrue
345 \EdefSanitize\EmFi@key{#1}%
346 \expandafter\ifx\csname KV@EmFi@\EmFi@key.prefix\endcsname\relax
350 \xdef\EmFi@order{\the\count@}%
351 \let\EmFi@title\EmFi@key
352 \let\EmFi@type\EmFi@S@text
355 \kvsetkeys{EmFiFi}{#2}%
356 \EmFi@convert\EmFi@title\EmFi@title
359 /\pdf@escapename{\EmFi@key}<<%
361 \ifx\EmFi@type\EmFi@S@date D%
362 \else\ifx\EmFi@type\EmFi@S@number N%
363 \else\ifx\EmFi@type\EmFi@S@file F%
364 \else\ifx\EmFi@type\EmFi@S@desc Desc%
365 \else\ifx\EmFi@type\EmFi@S@afrelationship AFRelationship%
366 \else\ifx\EmFi@type\EmFi@S@moddate ModDate%
367 \else\ifx\EmFi@type\EmFi@S@creationdate CreationDate%
368 \else\ifx\EmFi@type\EmFi@S@size Size%
370 \fi\fi\fi\fi\fi\fi\fi
372 \EmFi@@order{\EmFi@order}%
383 \xdef\EmFi@fieldlist{%
387 \ifx\EmFi@type\EmFi@S@text
388 \kv@define@key{EmFi}{\EmFi@key.value}{%
391 \EmFi@convert\EmFi@temp\EmFi@temp
392 \expandafter\def\csname EmFi@V@#1%
393 \expandafter\endcsname\expandafter{%
394 \expandafter(\EmFi@temp)%
397 \EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
398 \else\ifx\EmFi@type\EmFi@S@date
399 \kv@define@key{EmFi}{\EmFi@key.value}{%
402 \EmFi@convert\EmFi@temp\EmFi@temp
403 \expandafter\def\csname EmFi@V@#1%
404 \expandafter\endcsname\expandafter{%
405 \expandafter(\EmFi@temp)%
408 \EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
409 \else\ifx\EmFi@type\EmFi@S@number
410 \kv@define@key{EmFi}{\EmFi@key.value}{%
412 \expandafter\EdefSanitize\csname EmFi@V@#1\endcsname{ ##1}%
414 \EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
416 \kv@define@key{EmFi}{\EmFi@key.prefix}{%
418 \expandafter\def\csname EmFi@P@#1\endcsname{##1}%
420 \EmFi@GlobalKey{EmFi}{\EmFi@key.prefix}%
421 \kv@define@key{EmFiSo}{\EmFi@key}[ascending]{%
422 \EdefSanitize\EmFi@temp{##1}%
423 \ifx\EmFi@temp\EmFi@S@ascending
424 \def\EmFi@temp{true}%
425 \else\ifx\EmFi@temp\EmFi@S@descending
426 \def\EmFi@temp{false}%
430 Unknown sort order `\EmFi@temp'.\MessageBreak
431 Supported values: `\EmFi@S@ascending', %
435 \ifx\EmFi@temp\ltx@empty
437 \xdef\EmFi@sortkeys{%
439 /\pdf@escapename{#1}%
441 \ifx\EmFi@sortorders\ltx@empty
442 \global\let\EmFi@sortorders\EmFi@temp
443 \gdef\EmFi@sortcase{1}%
445 \xdef\EmFi@sortorders{%
450 \xdef\EmFi@sortcase{2}%
454 \EmFi@GlobalDefaultKey{EmFiSo}\EmFi@key
458 Field `\EmFi@key' is already defined%
463 \kv@define@key{EmFiFi}{type}{%
464 \EdefSanitize\EmFi@temp{#1}%
465 \ifx\EmFi@temp\EmFi@S@text
466 \let\EmFi@type\EmFi@temp
467 \else\ifx\EmFi@temp\EmFi@S@date
468 \let\EmFi@type\EmFi@temp
469 \else\ifx\EmFi@temp\EmFi@S@number
470 \let\EmFi@type\EmFi@temp
471 \else\ifx\EmFi@temp\EmFi@S@file
472 \let\EmFi@type\EmFi@temp
473 \else\ifx\EmFi@temp\EmFi@S@desc
474 \let\EmFi@type\EmFi@temp
475 \else\ifx\EmFi@temp\EmFi@S@afrelationship
476 \let\EmFi@type\EmFi@temp
477 \else\ifx\EmFi@temp\EmFi@S@moddate
478 \let\EmFi@type\EmFi@temp
479 \else\ifx\EmFi@temp\EmFi@S@creationdate
480 \let\EmFi@type\EmFi@temp
481 \else\ifx\EmFi@temp\EmFi@S@size
482 \let\EmFi@type\EmFi@temp
485 Unknown type `\EmFi@temp'.\MessageBreak
486 Supported types: `text', `date', `number', `file',\MessageBreak
487 `desc', `afrelationship', `moddate', `creationdate', `size'%
489 \fi\fi\fi\fi\fi\fi\fi\fi\fi
491 \kv@define@key{EmFiFi}{title}{%
494 \def\EmFi@setboolean#1#2{%
495 \EdefSanitize\EmFi@temp{#2}%
496 \ifx\EmFi@temp\EmFi@S@true
497 \csname EmFi@#1true\endcsname
499 \ifx\EmFi@temp\EmFi@S@false
500 \csname EmFi@#1false\endcsname
503 Unknown value `\EmFi@temp' for key `#1'.\MessageBreak
504 Supported values: `true', `false'%
509 \kv@define@key{EmFiFi}{visible}[true]{%
510 \EmFi@setboolean{visible}{#1}%
512 \kv@define@key{EmFiFi}{edit}[true]{%
513 \EmFi@setboolean{edit}{#1}%
516 \def\EmFi@sortorders{}
521 \ltx@ifnextchar[\EmFi@embedfile{\EmFi@embedfile[]}%
523 \def\EmFi@embedfile[#1]#2{%
526 \string\embedfile\ltx@space after \string\embedfilefinish
528 The list of embedded files is already written.%
533 \kvsetkeys{EmFi}{#1}%
534 \expandafter\expandafter\expandafter
535 \ifx\expandafter\expandafter\expandafter
536 \\\pdf@filesize{\EmFi@file}\\%
538 File `\EmFi@file' not found%
540 The unknown file is not embedded.%
543 \edef\EmFi@@filespec{%
544 \pdf@escapestring{\EmFi@filespec}%
546 \ifx\EmFi@ucfilespec\ltx@empty
547 \let\EmFi@@ucfilespec\ltx@empty
549 \EmFi@convert\EmFi@ucfilespec\EmFi@@ucfilespec
551 \ifx\EmFi@desc\ltx@empty
552 \let\EmFi@@desc\ltx@empty
554 \EmFi@convert\EmFi@desc\EmFi@@desc
556 \ifx\EmFi@afrelationship\ltx@empty
557 \let\EmFi@@afrelationship\ltx@empty
559 \EmFi@convert\EmFi@afrelationship\EmFi@@afrelationship
568 \edef\EmFi@ci{\the\pdflastobj}%
570 \immediate\pdfobj stream attr{%
572 \ifx\EmFi@mimetype\ltx@empty
574 /Subtype/\pdf@escapename{\EmFi@mimetype}%
577 /ModDate(\pdf@filemoddate{\EmFi@file})%
578 /Size \pdf@filesize{\EmFi@file}%
579 /CheckSum<\pdf@filemdfivesum{\EmFi@file}>%
581 }file{\EmFi@file}\relax
582 \EmFi@defobj{EmbeddedFile}%
586 \ifx\EmFi@filesystem\ltx@empty
588 /FS/\pdf@escapename{\EmFi@filesystem}%
591 \ifx\EmFi@@ucfilespec\ltx@empty
593 /UF(\EmFi@@ucfilespec)%
595 \ifx\EmFi@@desc\ltx@empty
599 \ifx\EmFi@@afrelationship\ltx@empty
601 /AFRelationship\EmFi@@afrelationship%
604 /F \the\pdflastobj\ltx@space 0 R%
607 /CI \EmFi@ci\ltx@space 0 R%
611 \EmFi@defobj{Filespec}%
614 }{\the\pdflastobj\ltx@space 0 R}%
620 \expandafter\ifx\csname EmFi@P@#1\endcsname\relax
621 \expandafter\ifx\csname EmFi@V@#1\endcsname\relax
623 /\pdf@escapename{#1}\csname EmFi@V@#1\endcsname
626 /\pdf@escapename{#1}<<%
627 \expandafter\ifx\csname EmFi@V@#1\endcsname\relax
629 /D\csname EmFi@V@#1\endcsname
631 /P(\csname EmFi@P@#1\endcsname)%
635 \def\EmFi@convert#1#2{%
636 \ifnum\pdf@strcmp{\EmFi@stringmethod}{psd}=0 %
637 \pdfstringdef\EmFi@temp{#1}%
640 \edef#2{\pdf@escapestring{#1}}%
643 \global\let\EmFi@list\ltx@empty
646 \ifx\EmFi@list\ltx@empty
647 \xdef\EmFi@list{\noexpand\do{#1}{#2}}%
650 \ifnum\pdf@strcmp{##1}{#1}>0 %
654 \noexpand\do{#1}{#2}%
655 \noexpand\do{##1}{##2}%
660 \toks@\expandafter{\the\toks@\do{####1}{####2}}%
663 \xdef\EmFi@list{\the\toks@}%
666 \toks@\expandafter{\the\toks@\do{##1}{##2}}%
670 \xdef\EmFi@list{\the\toks@\noexpand\do{#1}{#2}}%
677 \def\embedfilefinish{%
680 Too many invocations of \string\embedfilefinish
682 The list of embedded files is already written.%
685 \ifx\EmFi@list\ltx@empty
687 \global\EmFi@finishedtrue
698 /EmbeddedFiles \the\pdflastobj\ltx@space 0 R%
709 /AF \the\pdflastobj\ltx@space 0 R%
712 \ifx\EmFi@initialfile\ltx@empty
717 \ifx\EmFi@initialfile\ltx@empty
718 \let\EmFi@@initialfile\ltx@empty
720 \edef\EmFi@@initialfile{%
721 \pdf@escapestring{\EmFi@initialfile}%
728 \ifx\x\EmFi@@initialfile
730 \let\do\ltx@gobbletwo
734 \expandafter\endgroup
737 \@PackageWarningNoLine{embedfile}{%
738 Missing initial file `\EmFi@initialfile'\MessageBreak
739 among the embedded files%
741 \let\EmFi@initialfile\ltx@empty
742 \let\EmFi@@initialfile\ltx@empty
744 \ifcase\EmFi@sortcase
754 /A[\EmFi@sortorders]%
757 \def\EmFi@@order##1{%
758 \ifnum\EmFi@order>1 %
764 \ifx\EmFi@schema\ltx@empty
766 /Schema<<\EmFi@schema>>%
768 \ifx\EmFi@@initialfile\ltx@empty
770 /D(\EmFi@@initialfile)%
772 \ifx\EmFi@view\EmFi@S@tile
774 \else\ifx\EmFi@view\EmFi@S@hidden
777 \ifx\EmFi@temp\ltx@empty
785 /Collection \the\pdflastobj\ltx@space0 R%
791 \begingroup\expandafter\expandafter\expandafter\endgroup
792 \expandafter\ifx\csname AtEndDocument\endcsname\relax
794 \AtEndDocument{\embedfilefinish}%
799 %% End of file `embedfile.sty'.