\AtEndDocument{<stuff>}
is a shorthand equivalent to
<stuff>
\end{document}
Why? Look at the definition of \enddocument (from latex.ltx):
\def\enddocument{%
\let\AtEndDocument\@firstofone
\@enddocumenthook
\@checkend{document}%
\clearpage
\begingroup
\if@filesw
\immediate\closeout\@mainaux
\let\@setckpt\@gobbletwo
\let\@newl@bel\@testdef
\@tempswafalse
\makeatletter \@@input\jobname.aux
\fi
\@dofilelist
\ifdim \font@submax >\fontsubfuzz\relax
\@font@warning{Size substitutions with differences\MessageBreak
up to \font@submax\space have occurred.\@gobbletwo}%
\fi
\@defaultsubs
\@refundefined
\if@filesw
\ifx \@multiplelabels \relax
\if@tempswa
\@latex@warning@no@line{Label(s) may have changed.
Rerun to get cross-references right}%
\fi
\else
\@multiplelabels
\fi
\fi
\endgroup
\deadcycles\z@\@@end}
\@enddocumenthook is the hook that is updated by \AtEndDocument:
\def\AtEndDocument{\g@addto@macro\@enddocumenthook}
You may consider alternative end-of-document hooks by looking into the atveryend package. It provides the following hooks, all of which are executed after the \AtEndDocument hook, except the first:
BeforeClearDocument{<code>}
The code is called before the final \clearpage in \enddocument. However it is
unknown, whether the last page is already shipped out or if this will be triggered
by the final \clearpage.
\AfterLastShipout{<code>}
The code is called after the final \clearpage of \enddocument before the main
.aux file is closed. This is the right place to remember the last page in the .aux
file, for instance.
\AtVeryEndDocument{<code>}
The code is called after the .aux file is closed and read in again. It is the place
for final checks, rerun hints, final messages.
\AtEndAfterFileList{<code>}
After the .aux file closing and reading LaTeX prints the file list if requested by
\listfiles. Then this hook is executed.
\AtVeryVeryEnd{<code>}
This code is called right before the final \@@end.
Refer to the definition of \enddocument in order to see an approximate location where the above hooks are placed.
\AtEndDocument{}on preamble not on the body. – Sigur Jan 25 '15 at 22:17:)– Svend Tveskæg Jan 25 '15 at 22:17\AtEndDocument{}on the preamble. I prepare the minimal example. – fauve Jan 25 '15 at 22:19\usepackage{etoolbox}and then\preto\enddocument{\nameofcompany\par}? – jon Jan 25 '15 at 22:32