summaryrefslogtreecommitdiff
path: root/texmf-dist/source/latex/qrcstamps/qrcstamps.dtx
blob: fea0309fbab6bc2faaf3ff88c024b6635436e92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
%\iffalse
% makeindex -s gglo.ist -o qrcstamps.gls qrcstamps.glo
% makeindex -s gind.ist -o qrcstamps.ind qrcstamps.idx
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% qrcstamps.sty package,                                %%
%% Copyright (C) 2017                                    %%
%%   dpstory@uakron.edu                                  %%
%%                                                       %%
%% This program can redistributed and/or modified under  %%
%% the terms of the LaTeX Project Public License         %%
%% Distributed from CTAN archives in directory           %%
%% macros/latex/base/lppl.txt; either version 1.2 of the %%
%% License, or (at your option) any later version.       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
%<package>\ProvidesPackage{qrcstamps}
%<package> [2018/06/02 v1.0 qrcstamps: Create QR codes using stamps]
%<*driver>
\documentclass{ltxdoc}
\usepackage{xcolor}
\usepackage[colorlinks,hyperindex=false]{hyperref}
%\usepackage{qrcstamps}
%\pdfstringdefDisableCommands{\let\\\textbackslash}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\gdef\brpr#1{\texttt{\char123\relax#1\char125\relax}}
\let\darg\brpr
\let\env\texttt
\let\opt\texttt
\let\app\textsf
\let\pkg\textsf
\def\visispace{\symbol{32}}
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textsl{\texttt{#1}}}
\def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
%\def\cs#1{\texttt{\bslash#1}}
\DeclareRobustCommand{\tmspace}[3]{%
  \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
\renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
\let\thinspace\,
\renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
\let\negthinspace\!
\renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
\let\medspace\:
\newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
\renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
\let\thickspace\;
\newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
\makeatletter
\renewcommand{\paragraph}
    {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}
    {\normalfont\normalsize\bfseries}}
\renewenvironment{quote}[1][]
   {\def\@rgi{#1}\ifx\@rgi\@empty
    \let\rghtm\@empty\else\def\rghtm{\rightmargin\leftmargin}\fi
    \list{}{\rghtm} %{\rightmargin\leftmargin}%
    \item\relax}
   {\endlist}
\makeatother
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{qrcstamps}{Inputting aebdocfmt.def}}
    {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
     \PackageInfo{qrcstamps}{aebdocfmt.def cannot be found}}
\begin{document}
\def\CMD#1{\textbackslash#1}
  \GetFileInfo{qrcstamps.sty}
  \title{\textsf{qrcstamps}: Create QR codes using stamps}
  \author{D. P. Story\\
    Email: \texttt{dpstory@acrotex.net}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \let\Email\texttt
  \DocInput{qrcstamps.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here.\\Execute
    \texttt{makeindex -s gind.ist -o qrcstamps.ind qrcstamps.idx}\\on the command line and recompile
    \texttt{qrcstamps.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here.\\Execute
    \texttt{makeindex -s gglo.ist -o qrcstamps.gls qrcstamps.glo}\\on the command line and recompile
    \texttt{qrcstamps.dtx}.}
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
%
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
%    {\PackageInfo{web}{cannot find aebdonotindex.def}}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%    \section{Description}
%    This package attempts to create barcodes, at least the ones supported by Acrobat: PDF417,
%    QR Code, Data Matrix. Acrobat has a barcode field that can be created in the standard way using
%    \pkg{eforms}, but it does  not work because the barcode renderer is never called to create the image
%    for the barcode. Bummer.
%
%    The approach we take was suggested to me by Thom Parker, through personal communication, through
%    \href{https://acrobatusers.com/tutorials/print/dynamic_stamp_secrets}{his article} on \href{https://acrobatusers.com/}{AcrobatUser.com}
%    and his book on \href{https://www.pdfscripting.com/public/All-About-PDF-Stamps-in-Acrobat-and-Paperless-Workflows-The-Book.cfm}{PDF Stamps}.
%    The idea is to create \emph{dynamic stamps} whose appearances are barcodes, such as a QR symbol.
%
%    In this version, we concentrate of the QR Code symbology. Whereas PDF417 and Data Matrix symbology may
%    be created in the same way, there seems no need for either of these two. A QR Code symbology can be
%    read by the scanners available on most mobile phones today. In that context, the symbology often contains
%    an URL that can be scanned by a persons mobile, after which time, he (or she) may visit that web site without
%    having to physically type in the URL address.
%    \begin{macrocode}
\RequirePackage{xkeyval}
%    \end{macrocode}
%    \section{Documentation and Code}
%    The \IndexOpt{scandoc}\opt{scandoc} option calls some doc assembly JavaScript to scan the document
%    for barcode stamps, this may not be necessary, depending on the version of Acrobat you have.
%    \begin{macrocode}
\DeclareOptionX{scandoc}{\let\grc@InputScanDoc\qr@scanDoc}
%    \end{macrocode}
%    During document development, you don't what to scan the newly created PDF after you build it to,
%    perhaps, edit the text. In this case, use the \IndexOpt{!scandoc}\opt{!scandoc} option. You want to scan the document when you build the document for the last time
%    before publishing it. Be sure to save the document using the SaveAs menu item. This saves the
%    stamp appearances (symbology in this case) as part of the document.
%    \begin{macrocode}
\DeclareOptionX{!scandoc}{\let\grc@InputScanDoc\relax}
%    \end{macrocode}
%    The default is not to scan the document. Remember, the final document must be scanned; that is,
%    it must be build with the \opt{scandoc} option in effect.
%    \begin{macrocode}
\let\grc@InputScanDoc\relax
\def\qr@scanDoc{\InputIfFileExists{scandoc-grc.def}{\PackageInfo{qrcstamps}
    {Inputting the scandoc-grc.def file}}
    {\PackageWarning{qrcstamps}{Cannot find the file scandoc-grc.def}}}
%    \end{macrocode}
%    \leavevmode\IndexOpt{basename}\hspace{-\marginparsep}\texttt{=\ameta{name}} sets the base name of the barcode annotation.
%    The form of the name is \texttt{\ameta{basename}\_\ameta{size}}. The default value
%    of \opt{basename} is \texttt{basename=AeBQRC}. This option need never be specified unless
%    a package developer creates his own custom barcode fields and stamps. To reference these new
%    stamps, the \texttt{basename} would have to be specified, unique that collection of stamps.
%    \begin{macrocode}
\DeclareOptionX{basename}{\def\QRBase{#1}}
\def\QRBase{AeBQRC}
%    \end{macrocode}
%    \begin{macrocode}
\DeclareOptionX*{\PassOptionsToPackage{\CurrentOption}{insdljs}}
%    \end{macrocode}
%    \begin{macrocode}
\ProcessOptionsX
%    \end{macrocode}
%    The package used here is \pkg{annot\_pro}, version dated 2017/06/06. I made a minor
%    modification of \pkg{annot\_pro} to accommodate \cs{qrcstamps}.
%    \begin{macrocode}
\RequirePackage{annot_pro}[2017/06/06]
\ifx\grc@InputScanDoc\relax\else\let\execjs=y\fi
%    \end{macrocode}
%    \subsection{The \texorpdfstring{\protect\cs{qrCode}}{\textbackslash{qrCode}} command}
%    We develop the stamp annotation for a QR barcode.
%    The command \cs{qrCode}, defined below, uses \cs{annotpro} from \pkg{annot\_pro}, and
%    as such, its optional argument takes the same options as \cs{annotpro}. However,
%    we add two new options, available only within the options list of \cs{qrCode}.
%    modification of \pkg{annot\_pro} to accommodate \cs{qrcstamps}.\medskip
%
%    \noindent The \IndexKey{size}\texttt{size} key takes one of three values
%    \texttt{small}, \texttt{medium}, and \texttt{large}.
%    \begin{itemize}
%       \item \texttt{size=small} produces a stamp that holds at most 75 characters
%       \item \texttt{size=medium} produces a stamp that holds at most 250 characters
%       \item \texttt{size=small} produces a stamp that holds at most 500 characters
%    \end{itemize}
%    The choice of \texttt{size} should be the best fit for the data you provide \cs{qrCode}.
%    \begin{macrocode}
\define@choicekey+{annotprostampQR}{size}[\val\nr]{%
small,medium,large}[small]{\ifcase\nr\relax
    \def\apstamp@@size{Small}\def\qrc@def@W{1in}\or
    \def\apstamp@@size{Med}\def\qrc@def@W{1.5in}\or
    \def\apstamp@@size{Large}\def\qrc@def@W{2in}\else
    \def\apstamp@@size{Small}\def\qrc@def@W{1in}\fi}%
{\PackageWarning{qrcstamps}{Invalid choice of `size=#1'\MessageBreak
    Permissible values are small, medium, large}}
\def\apstamp@@size{Small}
%    \end{macrocode}
%    \leavevmode\IndexKey{allowresize}\hspace{-\marginparsep}\texttt{=\ameta{\upshape{true\string|false}}}
%    The \texttt{allowresize} allows you to resize and move the stamp.
%    By default, the stamp (qr code symbology) cannot be resized or moved.
%    \begin{macrocode}
\define@boolkey{annotprostampQR}{allowresize}[true]{}
%    \end{macrocode}
%    \leavevmode\IndexKey{basename}\hspace{-\marginparsep}\texttt{=\ameta{name}}
%    The \texttt{basename} key allows you to give a \ameta{name} to the stamp you want to use
%    \emph{locally}. It's unlikely you are using more than one barcode stamp collection, so this option
%    is normally not used, but just in case, it is here. Specifying a value for the key \texttt{basename}
%    overrides the choice for the option \texttt{basename}.
%    \begin{macrocode}
\define@key{annotprostampQR}{basename}[\QRBase]{\edef\QRBase{#1}}
%    \end{macrocode}
%    \leavevmode\IndexKey{contents}\hspace{-\marginparsep}\texttt{=\ameta{text}}
%    It's unlikely you'll want to include a text message as part of your stamp, but just in
%    case, we previde the \texttt{contents} key.
%    \begin{macrocode}
\define@key{annotprostampQR}{contents}[]{\long\def\qrc@contents{#1}}
\let\qrc@contents\@empty
%    \end{macrocode}
%    \begin{macro}{\qrCode}\hspace{-\marginparsep}\,\texttt{[\ameta{options}]\darg{\ameta{content}}}
%    The \cs{qrCode} command is the one that produces the QR Code stamp symbol, not as a barcode field,
%    but as an annotation stamp. For printed material, the stamps are flattened and appear as you expect
%    them. The \ameta{options} may be any option for a stamp annotation as produced by \cs{annotpro}
%    plus the options \texttt{size} and \texttt{allowresize}. The required argument \ameta{content}
%    is the text you want the qr barcode symbology to represent. Usually its an URL.
%    \begin{macrocode}
\newcommand\qrCode[2][]{\begingroup\def\n{\string\n}%
    \def\apstamp@@size{Small}\def\qrc@def@W{1in}%
    \setkeys*{annotprostampQR}{#1}%
    \annotpro*[widthTo=\qrc@def@W,#1,type=stamp,
    \ifKV@annotprostampQR@allowresize\else readonly\fi,
    title=QRC,subject={#2},%
    name=\#\QRBase_\apstamp@@size]{\qrc@contents}\endgroup}
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
%</package>
%<*scandoc>
%    \end{macrocode}
%    \subsection{Document assembly}
%    The document assembly code is executed when the \texttt{scandoc} option is used. It is executed
%    then the document is first opened.
%    \begin{macrocode}
\begin{execJS}{scan4qrc}
var aBCStamps=new Array();
if (typeof scancomplete=="undefined") {
    var scancomplete=false,annots,isStamp,isHashtag;
    this.syncAnnotScan();
    for (var p=0; p<this.numPages; p++) {
         annots=this.getAnnots(p);
         if (annots!=null) {
            for (var i=0; i<annots.length; i++) {
%    \end{macrocode}
%    At this time, we search only for annots of type \texttt{"Stamp"} and ones whose \texttt{AP} key
%    has an entry beginning with `\texttt{\#}'. Once found, we push it (the page number)
%    onto the \texttt{aBCStamps} array.
%    \begin{macrocode}
                isStamp=(annots[i].type=="Stamp");
                isHashtag=(annots[i].AP.indexOf("\#")==0);
                if ( isStamp  &&  isHashtag ) {
                    aBCStamps.push(p);
                    break;
                }
            }
        }
    }
}
QRCscrollPage.index=0;
function QRCscrollPage() {
%    \end{macrocode}
%    We go to the page where each stamp of the type we are interested in. Opening the page
%    causes \app{Acrobat} to create an appearance for the stamp.
%    \begin{macrocode}
    if (QRCscrollPage.index<aBCStamps.length) {
         this.pageNum=aBCStamps[QRCscrollPage.index];
         QRCscrollPage.index+=1;
    } else {
        app.clearInterval(qrcTO);
        scancomplete=true;
        this.pageNum=0;
    }
}
if (aBCStamps.length>0)
    var qrcTO=app.setInterval("QRCscrollPage()", 5);
\end{execJS}
%</scandoc>
%<*package>
%    \end{macrocode}
%    Input the \texttt{scandoc-grc.def} code, if the option \texttt{scandoc} is in effect.
%    \begin{macrocode}
\grc@InputScanDoc
%</package>
%    \end{macrocode}
\endinput