4

I tried to use tdclock package to embed a stopwatch in a beamer PDF file.

However, Adobe Reader is the only PDF viewer that can properly display the stopwatch/clock without those empty red boxes. Nevertheless, Adobe Reader is sluggish and crashes frequently when opening my presentation file.

In addition to embedding a stopwatch/clock, my presentation file has a movie (embedded by media9 package) which can be properly loaded/played in Adobe Reader and Foxit Reader. Unfortunately, Foxit Reader can't load tdclock stopwatch/clock and replaces it with empty red boxes despite enabling javascript and marking the file as safe.

My questions are:

  1. are there any alternatives to tdclock package?
  2. is it possible to fix the empty red boxes issue in Foxit Reader?
  3. what is the PDF viewer that can properly load tdclock clock/stopwatch and play embedded movies flawlessly?
5

Not a stopwatch, but another digital clock implementation showing the wall-time, working out of the box in AR and Foxit.

No empty red boxes in non-conforming PDF viewers, no save-the-changes dialog upon closing the document in AR and Foxit:

\documentclass{beamer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Digital Clock
%
% Usage:
%
%   % set-up (defaults)
%   \def\clockfont{Helvetica} % or Times
%   \def\clockfontscale{0.93}
%   \def\clockformat{yyyy/mm/dd HH:MM:ss}
%   \def\clockrefresh{1000} % milli-seconds
%
%   % insert clock
%   \digiclock
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pdfbase,xcolor}
\ExplSyntaxOn
\let\clockPdfAnnot\pbs_pdfannot:nnnn\let\clockPdfLastAnn\pbs_pdflastann:
\let\clockAppendToFields\pbs_appendtofields:n
\ExplSyntaxOff

\makeatletter
\def\clock@start#1#2#3{%
  function showtime#3(){%
    this.getField("digiclock.#3").value=util.printd("#1",new Date());%
    this.dirty=false;%
  }%
  try{showtime#3();}catch(e){}%
  try{app.clearInterval(digiclock#3);}catch(e){}%
  try{var digiclock#3=app.setInterval("showtime#3()",#2);}catch(e){}%
}%
\def\clock@stop#1{try{app.clearInterval(digiclock#1);}catch(e){}}%
\newcounter{clock@num}%
\newlength\ex@height%
\newlength\clock@width%
\newlength\clock@height%
\def\digiclock{%
  \settowidth\clock@width{\clockformat}%
  \settoheight\clock@height{\clockformat}%
  \settoheight\ex@height{X}%
  \extractcolorspec{.}\clock@tempb% current color (\setcolor{...})
  \expandafter\convertcolorspec\clock@tempb{rgb}\clock@tempb%
  \edef\clock@tempa{\expandafter\clock@rgbcomp\clock@tempb\@nil}%
  \raisebox{\depth}{%
    \makebox[\clockfontscale\clock@width][l]{%
      \clockPdfAnnot{\clockfontscale\clock@width}%
                    {\clockfontscale\clock@height}{\clockfontscale\clock@height}{%
        /Subtype/Widget/FT/Tx/T (digiclock.\theclock@num) /Ff 1
        /DA (/\clockfont\space 0 Tf \clock@tempa\space rg)
        /MK<</BC []/BG []>>
        /Q 2
        /BS <</W 1/S/S>>
      }%
      \clockAppendToFields{\clockPdfLastAnn}%
      %this is for Foxit compatibility: Widget annots don't seem to acknowledge /P* events;
      %therefore, we move /AA into a separate Screen annot
      \clockPdfAnnot{1ex}{0.5ex}{0.5ex}{%
        /Subtype/Screen/F 2%
        /AA <<%
          /PO <</S/JavaScript/JS(\clock@start{\clockformat}{\clockrefresh}{\theclock@num})>>%
          /PC <</S/JavaScript/JS(\clock@stop{\theclock@num})>>%
        >>%
      }%
    }%
    \vrule width 0pt height 0.5\ex@height depth 0.5\ex@height%
  }%
  \stepcounter{clock@num}%
}
\def\clock@rgbcomp#1,#2,#3\@nil{#1 #2 #3}
\makeatother
%default settings
\def\clockfont{Helvetica}
\def\clockfontscale{0.93}
\def\clockformat{yyyy/mm/dd HH:MM:ss}
\def\clockrefresh{1000}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\usetheme{Madrid}

%page foot
\date[\def\clockfontscale{1.1}\def\clockformat{HH:MM:ss}\digiclock]{\today}

\begin{document}

\begin{frame}
  \Large Current date \& time: \digiclock
\end{frame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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