Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Links + Attachfile

2 views
Skip to first unread message

tlhiv

unread,
Dec 26, 2005, 9:40:49 AM12/26/05
to
I'm using the "attachfile" package to attach additional files inside my
PDF. Using the command

\attachfile{file}{text}

allows me to click on the word "text" and it tries to open/save the
file "file". However, I would like to reference this file "file"
several times throughout my document. That is, I'd like to have
several links throughout the document so that when the link is clicked
on, it prompts me to open/save the file each time. I don't want to
have to attach the file each time because I'd have several occurances
of the file. I'd simply like to have one attachment and several links.

Any thoughts on how to accomplish this?

Thanks in advance,

Troy Henderson

tlhiv

unread,
Dec 26, 2005, 10:02:03 AM12/26/05
to

Michael

unread,
Dec 27, 2005, 5:29:44 AM12/27/05
to
I don't know attachfile, but what about

\newcommand\myfile{file}
\attachfile{\myfile}{text}

or

\newcommand\attachmyfile[1]{\attachfile{file}{#1}}
\attachmyfile{text}

or even

\newcommand\attachmyfile{\attachfile{file}{text}}
\attachmyfile

Depending on how much flexibility you want.

Regards

Michael.

"tlhiv" <then...@gmail.com> schreef in bericht
news:1135607696....@f14g2000cwb.googlegroups.com...

Troy Henderson

unread,
Dec 27, 2005, 8:08:27 AM12/27/05
to
Michael,

I'm not quite sure what you're talking about. The "attachfile" package is
a package for embedding external files into the PDF created by pdf(la)tex.

http://www.ctan.org/tex-archive/macros/latex/contrib/attachfile/

It provides a nice way to attach these files (and link to them), but it
doesn't seem trivial to link to the same file several times without
attaching it several times.

Troy

Ulrike Fischer

unread,
Dec 27, 2005, 9:41:11 AM12/27/05
to
Troy Henderson <then...@gmail.com> schrieb:

The following seems to work and to embed a file only once. But I know
up to nothing about pdf annotations, so I really don't know if and
under which conditions this can break ;-)

\documentclass[a4paper]{article}
\usepackage{attachfile}
\makeatletter
\DeclareRobustCommand{\Copyattachfile}[2][]{%
\begingroup
\setkeys{AtFi}{#1}%
%\atfi@embedfile{#2}%
\atfi@set@appearance{\csname atfi@acro\atfi@icon@icon\endcsname}%
\atfi@flags@to@int%
\atfi@insert@file@annot{#2}%
\endgroup
}
\makeatother
\begin{document}

\attachfile{largefile.tex}
\newpage
\Copyattachfile{largefile.tex}
\end{document}

--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.

Troy Henderson

unread,
Dec 27, 2005, 10:07:54 AM12/27/05
to
Ulrike,

Thanks for the reply. This command seems to attach the file again.

Troy

Ulrike Fischer

unread,
Dec 27, 2005, 10:25:35 AM12/27/05
to
Troy Henderson <then...@gmail.com> schrieb:

> Ulrike,
>
> Thanks for the reply. This command seems to attach the file again.

? I'm not quite sure I don't understand what you mean. On my system the
file is attached only once:

with attachfile+ \Copyattachfile
<<largefile.tex>> [1{psfonts.map}] [2]
Output written on test.pdf (2 pages, 43629 bytes)


with two \attachfiles:
<<largefile.tex>> [1{psfonts.map}]<<largefile.tex>> [2]
Output written on test.pdf (2 pages, 81237 bytes).

Troy Henderson

unread,
Dec 27, 2005, 10:42:44 AM12/27/05
to
When I open the file in Adobe Acrobat Reader and go to the file
attachments, it shows the file twice.

Heiko Oberdiek

unread,
Dec 27, 2005, 10:50:41 AM12/27/05
to
Troy Henderson <then...@gmail.com> wrote:

> When I open the file in Adobe Acrobat Reader and go to the file
> attachments, it shows the file twice.

That's life, it shows the file annotations and you have two of them.

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Troy Henderson

unread,
Dec 27, 2005, 10:59:13 AM12/27/05
to
The filesize definitely increases (not just a little either) when using
this command \Copyattachfile The magnitude of the change is similar to
that of the filesize of the file I'm attaching.

Troy

Troy Henderson

unread,
Dec 27, 2005, 11:10:58 AM12/27/05
to
I apologize. I stand corrected. I tried this on a *LARGE* file (a 3 MB
JPEG picture) and used the command 10 times. However, the filesize of the
PDF was just slightly over 3 MB.

Thanks guys. This is good enough.

Troy

Troy Henderson

unread,
Dec 27, 2005, 11:14:50 AM12/27/05
to
Now I just need to get a corresponding \copytextattachfile working.

Troy

Ulrike Fischer

unread,
Dec 27, 2005, 11:32:52 AM12/27/05
to
Troy Henderson <then...@gmail.com> schrieb:

> The filesize definitely increases (not just a little either) when using
> this command \Copyattachfile The magnitude of the change is similar to
> that of the filesize of the file I'm attaching.

I wouldn't be surprized if you had problems to open the attached files,
but I don't think it it is possible that \Copyattachfile embeds a file.
The embedding is done with the command

%\atfi@embedfile{#2}%

And as it isn't there in \Copyattachfile, nothing can be embeded.

What does the log-file tells you at the end?

Btw: I realized that I have use the definition of a quite old
attachfile. With newer one the following should be better:

\makeatletter
\DeclareRobustCommand{\Copyattachfile}[1][]{%
\begingroup
\let\do\@makeother
\dospecials
\catcode`\{=1\relax
\catcode`\}=2\relax
\atfi@copyattachfile{#1}%
}

\def\atfi@copyattachfile#1#2{%


\setkeys{AtFi}{#1}%
%\atfi@embedfile{#2}%
\atfi@set@appearance{\csname atfi@acro\atfi@icon@icon\endcsname}%
\atfi@flags@to@int%
\atfi@insert@file@annot{#2}%
\endgroup
}

\makeatother


Ulrike Fischer

unread,
Dec 27, 2005, 11:53:51 AM12/27/05
to
Troy Henderson <then...@gmail.com> schrieb:

> Now I just need to get a corresponding \copytextattachfile working.

Simply look in attachfile.sty, search the definitions and change them.
The following should word (untested).

Btw: I want to emphasize that I don't understand all this stuff. I only
looked up the commands and tried to disable the embedding. So be
careful and do some tests in different environments.

\makeatletter
\DeclareRobustCommand{\Copytextattachfile}[1][]{% changed
\begingroup


\begingroup
\let\do\@makeother
\dospecials
\catcode`\{=1\relax
\catcode`\}=2\relax

\atfi@Copytextattachfile{#1}% changed
}

\def\atfi@Copytextattachfile#1#2{% changed
\endgroup
\atfi@Copytextattachfile@i{#1}{#2}% changed
}
\def\atfi@Copytextattachfile@i#1#2#3{% changed
\setkeys{AtFi}{#1}%
%\atfi@embedfile{#2}% changed
\def\atfi@textcolor(##1 ##2 ##3)##4{%
\textcolor[rgb]{##1,##2,##3}{##4}}%
\atfi@set@appearance{%
\expandafter\atfi@textcolor\expandafter
(\atfi@color@rgb){#3\strut}}%
\atfi@flags@to@int


\atfi@insert@file@annot{#2}%
\endgroup
}
\makeatother

Troy Henderson

unread,
Dec 27, 2005, 11:56:05 AM12/27/05
to
Thanks. That's exactly what I've done. I've basically copied the code
from 3 different macros, and renamed them to \copytextattachfile.
Everything seems to be working now. Thanks a million.

Troy

Troy Henderson

unread,
Dec 27, 2005, 3:07:10 PM12/27/05
to
It seems that the "non-embedded" version of the attachment gives problems
when trying to save it.

Troy

RS

unread,
Dec 27, 2005, 5:53:15 PM12/27/05
to
On 27.12.2005 21:07, Troy Henderson wrote:
> It seems that the "non-embedded" version of the attachment gives problems
> when trying to save it.

Simply removing \atfi@embedfile will probably put an incorrect reference
into the pdf file. Therefore, one has to keep track of the object number
when embedding it the first time to be able to recall it later.

Here is a minimally corrected version of Ulrike's code:

\DeclareRobustCommand{\atfi@embedfile}[1]{%
\immediate\pdfobj stream attr {
/Type /EmbeddedFile
\atfi@mimetype
} file {#1}%
\setcounter{atfi@embedfileobj}{\pdflastobj}%
% [RS]: save object number
\expandafter\xdef
\csname atfi@embedfileobj@#1\endcsname{\the\pdflastobj}%


}
\DeclareRobustCommand{\Copytextattachfile}[1][]{% changed
\begingroup
\begingroup
\let\do\@makeother
\dospecials
\catcode`\{=1\relax
\catcode`\}=2\relax
\atfi@Copytextattachfile{#1}% changed
}
\def\atfi@Copytextattachfile#1#2{% changed
\endgroup
\atfi@Copytextattachfile@i{#1}{#2}% changed
}
\def\atfi@Copytextattachfile@i#1#2#3{% changed
\setkeys{AtFi}{#1}%
%\atfi@embedfile{#2}% changed
\def\atfi@textcolor(##1 ##2 ##3)##4{%
\textcolor[rgb]{##1,##2,##3}{##4}}%
\atfi@set@appearance{%
\expandafter\atfi@textcolor\expandafter
(\atfi@color@rgb){#3\strut}}%
\atfi@flags@to@int

% [RS]: recall object number
\expandafter\c@atfi@embedfileobj
\csname atfi@embedfileobj@#2\endcsname\relax
\atfi@insert@file@annot{#2}%
\endgroup
}


Regards,
Robert.

Troy Henderson

unread,
Dec 27, 2005, 7:14:19 PM12/27/05
to
Robert,

Thanks for the correction. Unfortunately, it doesn't seem to quite work
here. It complains about


! Missing number, treated as zero.
<to be read again>
\atfi@embedfileobj@tri.mp
l.207 \Copytextattachfile{tri.mp}{some text}


where "tri.mp" is the name of the file I'm re-referencing. Any help on
fixing this would be greatly appreciated.

Troy

RS

unread,
Dec 27, 2005, 7:58:48 PM12/27/05
to
On 28.12.2005 01:14, Troy Henderson wrote:
> ! Missing number, treated as zero.
> <to be read again>
> \atfi@embedfileobj@tri.mp
> l.207 \Copytextattachfile{tri.mp}{some text}

I guess you did not use the normal \textattachfile command for the first
attachment?

With the following, much simpler approach, this is no longer necessary:

\documentclass{article}
\usepackage{attachfile}
\makeatletter
\DeclareRobustCommand{\atfi@embedfile}[1]{%
\@ifundefined{atfi@embedfileobj@#1}{%


\immediate\pdfobj stream attr {
/Type /EmbeddedFile
\atfi@mimetype
} file {#1}%
\setcounter{atfi@embedfileobj}{\pdflastobj}%

\expandafter\xdef
\csname atfi@embedfileobj@#1\endcsname{\the\pdflastobj}%

}{%
\setcounter{atfi@embedfileobj}%
{\csname atfi@embedfileobj@#1\endcsname}%
}%
}
\makeatother
\begin{document}
\attachfile{test1.tex}
\newpage
\textattachfile{test2.tex}{test2}
\newpage
\textattachfile{test1.tex}{test1}
\attachfile{test2.tex}
\end{document}

Regards,
Robert.

Troy Henderson

unread,
Dec 27, 2005, 8:34:37 PM12/27/05
to
Robert,

You're the man. Perhaps you should contact the author to let him know
about this. I think this should be an update to the package.

Thanks a bunch,

Troy

Scott Pakin

unread,
Dec 27, 2005, 9:48:43 PM12/27/05
to
Troy Henderson wrote:
> You're the man. Perhaps you should contact the author to let him know
> about this. I think this should be an update to the package.

It's now on my to-do list.

-- Scott

Troy Henderson

unread,
Dec 28, 2005, 1:41:01 AM12/28/05
to
Scott,

You live. Thanks for the attention. Do you know if it's a
feature/flaw in Acroread/Acrobat that even though the file is embedded
only once, that it shows up several (as many times as it's "referenced")
in the "Attachment List"?

Troy

Scott Pakin

unread,
Dec 28, 2005, 2:38:33 AM12/28/05
to

I don't know but I'd guess it's a flaw. I can't think of why one would
want to see the same attachment listed multiple times.

-- Scott

0 new messages