让 LaTeX PDF 显示文档的打印日期,而不是编译日期

让 LaTeX PDF 显示文档的打印日期,而不是编译日期

我已经寻找了很长时间,试图找到一种方法,让 PDF(使用 XeTeX 创建)根据打印日期(而不是编译日期)相应地调整日期。我熟悉\date、、&包等,但这些都不是我想要的。我还在 tex.stackexchange.com 上找到了一个页面,但我大多不理解(\datedatedatenumberdatetime文件创建日期) 这越来越接近我想要的,但并不完全是。哦,顺便说一句,如果它是独立于平台的,那就太好了,因为不是所有的员工都有同一台电脑。

这里的想法是为员工创建时间表,他们可以在工作前打印出来并自动为他们创建日期。这是时间表的粗略(真正)草稿(大多数评论都是我使用涉及pgf/tikz包的一些对我来说很新的技术 - 无关紧要):

非常感谢,希望一切清楚!

\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}

答案1

tdclock包提供了一种将当前日期和时间插入 PDF 文档的简单方法:

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

注意文档开头的,然后\initclock您将能够使用宏显示当前时间和日期\tdclock,,,...(参见\tddate\tdtime文档更多细节)。

答案2

在编译时将编译或其他日期放入文档中很容易。这只是另一个文本。但是,PDF 查看器无法更改此文本以进行打印!所以这两件事完全不同。

我看到的唯一方法是将一些 PDF 表单字段添加到文档中,该字段在打印 PDF 时(即打印之前)使用嵌入的 JavaScript 进行更新。您应该研究这个方向。例如,据我所知,该movie15包将 JavaScript 放入 PDF 中(但这并不是您需要的)。

你可能最终需要自己编写 JavaScript 代码。例如,你可以询问http://stackoverflow.com如何使用 PDF 打印日期更新 PDF 文本字段。

答案3

通过编译为 PostScriptdvips而不是 PDF 可以让您更好地从打印文档时直接获取当前日期 - 请参阅此常见问题解答。与 PDF 文档不同,PostScript 文档实际上是打印机执行的程序,因此每次打印时可能会生成略有不同的页面。

但是,并非所有 PostScript 版本都支持此功能,因此此功能的可用性取决于所使用的打印机。我还对从打印机读取的日期和时间的准确性有些怀疑。总而言之,这似乎不是适合您用例的可行解决方案。

答案4

如果你在 pdf 上有一个使用 JavaScript 计时的时钟,那么每次打印时,纸张上都会打印出时间,对吗?这让我想起了我们在 latex-beamer 上进行的讨论很久以前,人们就讨论过在演示中放置滴答作响的时钟。发布解决方案现在似乎已失效的链接,但有些代码在线程中被交换(来自powerdot包)可能会有所帮助。

相关内容