Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have been looking around for quite some time trying to find a way for a PDF (created using XeTeX) to adjust the date accordingly by the date it was printed - not compiled. I am familiar with \date, \datedate, datenumber & datetime packages, etc. but these are not what I want. I also found a page in tex.stackexchange.com, which I mostly do not understand ( Date of file creation ) that was getting closer to what I want but not exactly. Oh, by the way, it would be great if it was platform independent as not all employees have the same computer.

The idea here is to create time-sheets for employees that they can print off before work and have the date automatically created for them. Here is the rough (really) draft of the time sheet (most of the comments are me playing around with some new-to-me techniques involving the pgf/tikz packages - irrelevant):

Thanks very much and hope it is clear!

\documentclass[10pt,onecolumn,usenames,dvipsnames]{amsart}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfkeys}
\usetikzlibrary{
  chains,
  arrows,
  shapes.misc,
  shapes.arrows,
  matrix,
  positioning,
  scopes,
  decorations.pathmorphing,
  shadows%
}
\usetikzlibrary{snakes}
\usepackage[hmargin=1.5cm, vmargin=1.50cm]{geometry}
\geometry{top=0.5cm}
\geometry{left=0.5cm}
\geometry{right=0.5cm}
\usepackage{bbding}
\usepackage{amssymb}
\usepackage{amsmath,fp}
\usepackage{algorithm2e}
\usepackage{eurosym}
\usepackage{color,graphicx}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Hoefler Text}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Gill Sans}
\usepackage{hyperref}
\definecolor{linkcolour}{HTML}{FF0080}
\definecolor{shade}{HTML}{D4D7FE}
\definecolor{text1}{HTML}{2b2b2b}       
\definecolor{headings}{HTML}{701112} 
\hypersetup{    colorlinks,breaklinks,
            urlcolor=linkcolour, 
            linkcolor=linkcolour}
\usepackage{fancyhdr}           
\pagestyle{fancy}
\fancyhf{}
\rfoot{\color{headings} {\sffamily Last update: \today}. Typeset with X\LaTeX}
\renewcommand{\headrulewidth}{0pt}
\usepackage{titlesec}               
\titleformat{\section}
    {\color{headings}
        \scshape \Large\raggedright}{}{0em}{}[\color{blue}\titlerule]
\titlespacing{\section}{0pt}{0pt}{5pt}
\usepackage[yyyymmdd,hhmmss]{datetime}
\usepackage{datenumber}
\usepackage{fancyhdr}
\pagestyle{fancy}
\rfoot{Compiled on \today\ at \currenttime}
\cfoot{}
\lfoot{Page \thepage}
\usepackage{ifthen}
\begin{document}

\color{text1} 

\centering
\par{\centering{
{ \addfontfeature{LetterSpace=20.0}\fontsize{20}{20}\selectfont \scshape {\underline{To Do $\backslash$ Did}} }}
}\\[6mm]    
{\color{white} \hrule} 

\begin{minipage}[t]{0.25\textwidth}
    \section{Timeline}
        \begin{tikzpicture}
            \draw[snake](0,40pt) -- (0,0);
            \draw (0,20pt) node[left=10pt]{\datedate};
            \draw (0,10pt) node[left=10pt]{Worked On:};

            \draw(0 pt, 0 pt) -- (0 pt, -600 pt);


                \foreach \y [count=\yi] in {-30,-54,...,-570}{

                \draw (3 pt, \y pt) -- ( -3pt, \y pt);          
                \draw (0 pt, .1\y pt) -- (-60 pt,  .1\y + 1 pt ) node[midway,above]{[\hspace{1.5cm}]};  
                \draw (0 pt, 0.1\y pt) -- (100 pt, 0.1\y + 20 pt) node[midway,sloped,below]{};
                }

        \end{tikzpicture}

\end{minipage}
\hfill
\begin{minipage}[t]{0.25\textwidth}
    \vspace{21mm}
        \foreach \a/\b/\z [count=\ai,count=\bi,count=\zi] in {1,...,23}
            {
            \ifthenelse{\ai<13}
                {
                \ifthenelse{\isodd{\ai}}
                    {                                                               
                    \FPdiv\c{\ai}{2} \FPadd\c{\c}{6} \FPupn\c{\c{} 0 round} $\FPprint\c$: 
                        \ifthenelse{\bi=2}
                            {$30$}
                            {$00$}
                    }
                    {                                                               
                    \FPdiv\c{\ai}{2}    \FPadd\c{\c}{6}    \FPupn\c{\c{} 0 round}    $\FPprint\c$:$30$
                    } to 
                        \ifthenelse{\isodd{\zi}}
                            {
                            \FPdiv\c{\zi}{2}    \FPadd\c{\c}{6}    \FPupn\c{\c{} 0 round}    $\FPprint\c$:$30$
                            }
                            {
                            \FPdiv\c{\zi}{2}    \ifthenelse{\zi<12}{\FPadd\c{\c}{7}}{\FPadd\c{\c}{-5}}    \FPupn\c{\c{} 0 round}    $\FPprint\c$: %interior \ifthenelse takes care of 12:30 - 1:00
                                \ifthenelse{\zi=1}
                                {$30$}
                                {$00$}
                            }
                            \\\\
                }
                {
                \ifthenelse{\isodd{\ai}}
                    {                                                               
                    \FPdiv\c{\ai}{2}    \FPadd\c{\c}{-6}    \FPupn\c{\c{} 0 round}    $\FPprint\c$:$00$
                    }
                    {                                                               
                    \FPdiv\c{\ai}{2}    \FPadd\c{\c}{-6}    \FPupn\c{\c{} 0 round} $\FPprint\c$: 
                        \ifthenelse{\bi=2}
                        {$00$}
                        {$30$}
                    }  --
                        \ifthenelse{\isodd{\zi}}
                            {
                            \FPdiv\c{\zi}{2} \FPadd\c{\c}{-6} \FPupn\c{\c{} 0 round} $\FPprint\c$:$30$
                            }
                            {
                            \FPdiv\c{\zi}{2}    \ifthenelse{\zi<12}{\FPadd\c{\c}{7}}{\FPadd\c{\c}{-5}}    \FPupn\c{\c{} 0 round}    $\FPprint\c$: %interior \ifthenelse takes care of 12:30 - 1:00
                                \ifthenelse{\zi=1}
                                {$30$}
                                {$00$}
                            }
                            \\\\                        
                }
            }   
\end{minipage}
\hfill
\begin{minipage}[t]{0.38\textwidth}
    \section{Description}
        \begin{enumerate}
        \item Move old tires and wheels into grey round bin north of shop.
        \item Move small LP tanks into quonset
        \item Drill and tap threads into quonset door frame
        \item Wire brush wheel and mount two tires for water trailer
        \item Clean up paint gun (air)
        \item Clean up yard of garbage and lumber
        \item Stack wood by container on west side of quonset
        \end{enumerate}


\end{minipage}


\newpage
\begin{minipage}[t]{0.45\textwidth} 

    \section{Timeline}

        \begin{tikzpicture}
            \draw[snake] (0,40pt) -- (0,0);
            \draw (0,20pt) node[left=10pt] {Prior to sale. $\Bigg\{$};

            \draw (0 pt,0 pt) -- (0 pt,-400 pt);
            \foreach \y in {40,0,-40,-80, -120, -160, -200, -240}
            \draw (3pt, \y pt) -- ( -3pt, \y pt);

            \draw (0,0) node[left=10pt] {XX/XX/2011};

            \draw (0 pt,-40 pt) node[left=10pt] {XX/XX/2011};
            \draw (0 pt, -40 pt) -- (40:4) node[midway,sloped,below]{start of .}; 
            \draw (0 pt, -40 pt) node[below=0pt]{\hspace{4cm} Pur};
            \draw (0 pt, -40 pt) node[below=10pt]{\hspace{4cm} arm, };

            \draw (0 pt, -80 pt) node[left=10pt] {XX/XX/2011}; 

            \draw (0 pt, -120 pt) node[left=10pt] {XX/XX/2011};

            \draw (0 pt, -160 pt) node[left=10pt] {XX/XX/2011};

            \draw (0 pt, -200 pt) node[left=10pt] {XX/XX/2011};

        \end{tikzpicture}


\end{minipage} %END of left-hand side minipage
\hfill
\begin{minipage}[t]{0.51\textwidth}
    \section{Timeline Specifics}
        \vspace{60pt}

        \begin{tikzpicture}[every on chain/.style=join,every join/.style=->,node distance=2mm and 1cm]
        { [start chain=trunk]
        \node[on chain]{A};
        \node [on chain] {B};
        { [start branch=numbers going below]
        \node [on chain] {1};
        \node [on chain] {2};
        \node [on chain] {3};
        }
        { [start branch=greek going above]
        \node [on chain] {$\alpha$};
        \node [on chain] {$\beta$};
        \node [on chain] {$\gamma$};
        }
        \node [on chain,join=with trunk/numbers-end,join=with trunk/greek-end] {C};
        { [start branch=symbols going below]
        \node [on chain] {$\star$};
        \node [on chain] {$\circ$};
        \node [on chain] {$\int$};
        }
        }
        \end{tikzpicture}

        \makeatletter
        \tikzset{join/.code=\tikzset{after node path={%
        \ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
        edge[every join]#1(\tikzchaincurrent)\fi}}}
        \makeatother

        \tikzset{>=stealth',every on chain/.append style={join},
                 every join/.style={->}}
        \centering

        \begin{tikzpicture}[start chain] {
            \node[on chain] {$0$};
                \node[on chain] {$A$} ;
                \node[on chain, join={node[above] {$\scriptstyle\varphi$}}] {$B$};
                \node[on chain, join={node[above] {$\scriptstyle\psi$}}] {$C$};
                \node[on chain] {$0$}; }
        \end{tikzpicture}
        \bigskip

        \begin{tikzpicture}
            \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
                { 0 & A  & B  & C  & 0 \\
                0 & A' & B' & C' & 0 \\ };
            { [start chain] \chainin (m-1-1);
                \chainin (m-1-2);
                { [start branch=A] \chainin (m-2-2)
                [join={node[right] {$\scriptstyle\eta_1$}}];}
                \chainin (m-1-3) [join={node[above] {$\scriptstyle\varphi$}}];
                { [start branch=B] \chainin (m-2-3)
                [join={node[right] {$\scriptstyle\eta_2$}}];}
                \chainin (m-1-4) [join={node[above] {$\scriptstyle\psi$}}];
                { [start branch=C] \chainin (m-2-4)
                [join={node[right] {$\scriptstyle\eta_3$}}];}
                \chainin (m-1-5); }
            { [start chain] \chainin (m-2-1);
                \chainin (m-2-2);
                \chainin (m-2-3) [join={node[above] {$\scriptstyle\varphi'$}}];
                \chainin (m-2-4) [join={node[above] {$\scriptstyle\psi'$}}];
                \chainin (m-2-5); }
        \end{tikzpicture}

\end{minipage}
\vspace{10pt}

\end{document}
share|improve this question
1  
Welcome to TeX.SX. I took the liberty to format your post so that it is displayed correctly. Have a look at tex.stackexchange.com/editing-help to learn how it is done. –  Martin Scharrer Mar 22 '11 at 18:11

4 Answers 4

The tdclock package offers an easy way to insert the current date and time into a PDF document:

\documentclass{article}
\usepackage{tdclock}
\begin{document}
\initclock
Date: \tddate
\end{document}

Mind the \initclock at the beginning of the document, then you'll be able to display the current time and date with the macros \tdclock, \tddate, \tdtime, ... (see the documentation for more details).

share|improve this answer
2  
This looks super simple! On Mac OS X 10.6 the Preview app (for viewing PDFs) does not seem to include a JavaScript engine so the date isn't shown when viewing the documentation. –  Christian Lindig Mar 22 '11 at 19:56
4  
@Christian Good point, it should be mentioned that the PDF viewer must support JavaScript so that the date can be displayed (few readers other than Adobe Reader do this...). With no JavaScript support available, however, the question is in my opinion unsolvable, because you can't change the PDF dynamically then to display the current date. –  diabonas Mar 22 '11 at 20:03
3  
Great! It works with Adobe Reader 9 under Linux. A test print into a PS file shows the print date correctly. This should do the what the OP wants. Actually tying it into the print event so that the date is only updated when the PDF is printed would make it more efficient, but not really required. However, I ticking time might be annoying when reading th PDF. –  Martin Scharrer Mar 22 '11 at 20:04

Placing the compile or other date into the document at compile time is easy. It's just another text. However, this text can't be changed by the PDF viewer for the print-out! So these two things are completely different.

The only way I see this done is to add some PDF form field into your document which is updated using embedded JavaScript when (i.e. just before) the PDF is printed. You should look into this direction. For example AFAIK the movie15 package places JavaScript into the PDF (not that it does what you need).

You might end up to need to write the JavaScript code by yourself. You could ask e.g. at http://stackoverflow.com how to update a PDF text field with the date when the PDF is to be printed.

share|improve this answer
    
I still don't think this will work unless the particular pdf viewer used is also a pdf editor. –  Matthew Leingang Mar 22 '11 at 18:57
1  
@Matthew: You can fill out a PDF form in a normal PDF viewer and print it. You only need a PDF editor if you want to save the form data or modify the form itself. The viewer needs to support JavaScript of course. –  Martin Scharrer Mar 22 '11 at 19:00
    
I believe you can use JavaScript to compute a default value (like a date) for a form field in a PDF form. The hyperref package provides support for PDF forms but I haven't used it together with JavaScript. –  Christian Lindig Mar 22 '11 at 19:12
    
I find this idea more and more interesting so I posted a question about JS in PDFs myself: stackoverflow.com/q/5396617/256941 –  Martin Scharrer Mar 22 '11 at 19:20
1  
Hi all! Thanks Martin for reformatting my post. Thanks to all for the help and leads, though well beyond my tex ability ha ha... Actually I started by reading, tug.org/TUGboat/Articles/tb22-3/tb72story.pdf and from there the package insdljs (insert document level javascript). So I hope to come up with something soon. Thanks again! –  Brett Mar 22 '11 at 20:58

Compiling to PostScript via dvips rather than PDF would give you a slightly better chance to obtain the current date directly from within the document while it is being printed -- see this FAQ. A PostScript document, unlike a PDF document, is really a program that is being executed by the printer and hence it could emit slightly different pages every time it is printed.

However, not all PostScript versions support this feature such that it's availability would depend on the printer being used. I would also have some doubts about the accuracy of date and time read from the printer. Taken together, this does not seem to be a viable solution for your use case.

share|improve this answer
2  
Nice post. I assume most people most likely wont use a PS printer directly but use a SW PS interpreter like GhostScript to print it on a "normal" printer. With GhostScript there is a bigger chance to get a correct date and time, I think. –  Martin Scharrer Mar 22 '11 at 18:59

If you had a clock on the pdf that kept time using JavaScript, then any time you printed it the paper would have the time printed, right? It reminds me of a discussion we had on latex-beamer ages ago about putting a ticking clock on a presentation. There was a posted solution with a link that appears dead now, but some code was traded around in the thread (from the powerdot package) which may help.

share|improve this answer
    
Have a look at this question: Is there a way to add a timer to a Beamer presentation? –  Hendrik Vogt Mar 23 '11 at 20:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.