| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3pdffield-action.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2021-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "LaTeX PDF management bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/pdfresources |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\DocumentMetadata{tagging=on} %no ua-2 currently, as labels/contents for widgets are missing |
| 27 |
\documentclass[full]{l3doc} |
| 28 |
\usepackage{latex-lab-testphase-l3doc} |
| 29 |
|
| 30 |
\usepackage{array,booktabs,siunitx} |
| 31 |
\usepackage{l3pdffield,bearwear} |
| 32 |
\hypersetup{pdfauthor=The LaTeX Project, |
| 33 |
pdftitle=l3pdffield (LaTeX PDF management bundle)} |
| 34 |
\begin{document} |
| 35 |
\DocInput{\jobname.dtx} |
| 36 |
\end{document} |
| 37 |
%</driver> |
| 38 |
% \fi |
| 39 |
% \providecommand\hook[1]{\texttt{#1}} |
| 40 |
% \title{^^A |
| 41 |
% The \pkg{l3pdffield-action} module\\ Commands to handle actions of form fields ^^A |
| 42 |
% \\ \LaTeX{} PDF management bundle |
| 43 |
% } |
| 44 |
% |
| 45 |
% \author{^^A |
| 46 |
% The \LaTeX{} Project\thanks |
| 47 |
% {^^A |
| 48 |
% E-mail: |
| 49 |
% \href{mailto:[email protected]} |
| 50 |
% {[email protected]}^^A |
| 51 |
% }^^A |
| 52 |
% } |
| 53 |
% |
| 54 |
% \date{Version 0.97c, released 2026-05-26} |
| 55 |
% |
| 56 |
% \maketitle |
| 57 |
% \begin{documentation} |
| 58 |
% \section{\pkg{l3pdffield-action} Introduction} |
| 59 |
% This is the documentation for actions for formular fields, for general information about form fields |
| 60 |
% check the documentation l3pdffield. |
| 61 |
% |
| 62 |
% \begin{center} |
| 63 |
% \ExplSyntaxOn |
| 64 |
% A:~ \pdffield_checkbox:n {name=A}\quad B:~\pdffield_checkbox:n {name=B}\par\bigskip |
| 65 |
% \pdffield_pushbutton:n{name=all,caption=Reset~All,reset}\quad |
| 66 |
% \pdffield_reset_new:nn{B}{fields=B} |
| 67 |
% \pdffield_pushbutton:n{name=all,caption=Reset~B,reset=B}\quad |
| 68 |
% \ExplSyntaxOff |
| 69 |
% \end{center} |
| 70 |
% |
| 71 |
% Please keep in mind |
| 72 |
% \begin{itemize} |
| 73 |
% \item Not every PDF viewer supports form fields. |
| 74 |
% \item Even if they support it, that doesn't mean that |
| 75 |
% they support actions like Submit. |
| 76 |
% \item The handling can depend on settings in the PDF viewer. |
| 77 |
% \item Standards like pdf/A disable features of form fields too |
| 78 |
% (as you typically can't change the PDF). |
| 79 |
% \end{itemize} |
| 80 |
% |
| 81 |
% \section{Actions} |
| 82 |
% |
| 83 |
% Actions must be handled in three places: In the action dictionary (|/A|) |
| 84 |
% of the annotation(s), in the additional action dictionary of the field (|/AA|), |
| 85 |
% and in the additional action dictionary (|/AA|) of the annotation(s). The distinction |
| 86 |
% between the two |/AA| dictionaries is relevant as field actions can only be |
| 87 |
% added when the field is initialized, so typically with the first field command |
| 88 |
% for a specific name, while annotation actions can be added for example only to |
| 89 |
% one specific instance of a checkbox or to pushbuttons belonging to the same field. |
| 90 |
% |
| 91 |
% \subsection{The additional action dictionaries (AA)} |
| 92 |
% The actions in the |/AA| dictionaries are JavaScript (ECMAScript) actions. |
| 93 |
% An example is the |calculate|/|AA/C| action, which is added with the |/C| key: |
| 94 |
% |
| 95 |
% \begin{verbatim} |
| 96 |
% Netto~\pdffield_textfield:n{name=netto}~ |
| 97 |
% \pdf_object_unnamed_write:ne{stream} |
| 98 |
% { |
| 99 |
% {} |
| 100 |
% { |
| 101 |
% var~f_netto = this.getField("netto"); |
| 102 |
% event.value = 1.19*f_netto.value; |
| 103 |
% } |
| 104 |
% } |
| 105 |
% \tl_set:Ne\l_tmpa_tl{\pdf_object_ref_last:} |
| 106 |
% Brutto~\pdffield_textfield:n{name=brutto,AA/C={\l_tmpa_tl}} |
| 107 |
% \end{verbatim} |
| 108 |
% |
| 109 |
% The main problem with scripts is to get the escaping right. While it is possible |
| 110 |
% to pass the script as string, it is less error prone to include it as (file) stream |
| 111 |
% and to reference the object number as done in the example. |
| 112 |
% |
| 113 |
% \subsection{The action dictionary (A)} |
| 114 |
% |
| 115 |
% The action dictionary can contain much more action types. The PDF reference lists 20 |
| 116 |
% different types\footnote{Sound and Movie are deprecated in PDF~2.0}: |
| 117 |
% GoTo, GoToR, GoToE, GoToDp, Launch, Thread, URI, Sound, Movie, |
| 118 |
% Hide, Named, SubmitForm, ResetForm, ImportData, SetOCGState, Rendition, |
| 119 |
% Trans, GoTo3DView, JavaScript, RichMediaExecute. |
| 120 |
% |
| 121 |
% And action dictionary typically looks like this: |
| 122 |
% \begin{verbatim} |
| 123 |
% /A << /Type /Action |
| 124 |
% /S ... % type name, e.g. /URI |
| 125 |
% /Next ... % optional, next action |
| 126 |
% ... ... % more keys |
| 127 |
% >> |
| 128 |
% \end{verbatim} |
| 129 |
% |
| 130 |
% The |/Next| key allows to chain actions. The value can be a reference to a |
| 131 |
% single action, or an array of actions. |
| 132 |
% |
| 133 |
% It depends on the action type which other keys should be used. |
| 134 |
% |
| 135 |
% While almost all actions are usable in the annotations of a field, the three |
| 136 |
% actions |SubmitForm|, |ResetForm| and |ImportData| are specific to fields and need |
| 137 |
% explicit support. This support is the main task of this module. |
| 138 |
% |
| 139 |
% \subsubsection{ResetForm} |
| 140 |
% The |ResetForm| action resets the fields of a form. The action is typically |
| 141 |
% attached to a pushbutton. |
| 142 |
% |
| 143 |
% In simple cases the action only need to contain the subtype entry and then resets |
| 144 |
% everything (sadly with some side-effect on the appearance of the pushbutton, sigh). |
| 145 |
% |
| 146 |
% \begin{verbatim} |
| 147 |
% \group_begin: |
| 148 |
% \pdfannot_dict_put:nnn{widget}{A}{<</Type/Action/S/ResetForm>>} |
| 149 |
% \pdffield_pushbutton:n{name=R,caption=Reset} |
| 150 |
% \group_end: |
| 151 |
% \end{verbatim} |
| 152 |
% |
| 153 |
% A |ResetForm| action knows two optional keys: |/Fields| allows to describe or restrict |
| 154 |
% the fields which should be reset. Depending on the setting of the |/Flags| key |
| 155 |
% the value of |/Fields| describes the fields to reset or the fields to leave unchanged. |
| 156 |
% |
| 157 |
% The commands of this module allow to store actions under a name which can then be |
| 158 |
% used in the key-val list of a field annotation. |
| 159 |
% |
| 160 |
% A reset action can be defined and used like this |
| 161 |
% \begin{verbatim} |
| 162 |
% \pdffield_reset_new:nn |
| 163 |
% {myreset} |
| 164 |
% { |
| 165 |
% fields= {A,B,C}, |
| 166 |
% exclude % or include |
| 167 |
% } |
| 168 |
% \pdffield_pushbutton:n{name=r,caption=Reset,reset=myreset} |
| 169 |
% \end{verbatim} |
| 170 |
% |
| 171 |
% |myreset| is the name the action can be referred to with the |reset| key. |
| 172 |
% |
| 173 |
% It is possible to define and use a reset action before all fields it |
| 174 |
% refers too have been created. |
| 175 |
% The list of names can contain names that are actually not used by the form. |
| 176 |
% |
| 177 |
% The reset action |all| is predefined. |
| 178 |
% |
| 179 |
% \subsubsection{ImportData} |
| 180 |
% The |ImportData| action allows to import field data from an external file, for example |
| 181 |
% a |.fdf| created with the submit action. |
| 182 |
% The action is typically attached to a pushbutton, its only value is a file name. |
| 183 |
% |
| 184 |
% \subsubsection{SubmitForm} |
| 185 |
% |
| 186 |
% |SubmitForm| is the most challenging action. There are more keys in the dictionary, |
| 187 |
% 13 flags, and there are four export options, which require each some flag settings. |
| 188 |
% And the main argument is an url, which can contain special chars like \# or \% and |
| 189 |
% so need special handling. |
| 190 |
% |
| 191 |
% A submit action can be defined like this |
| 192 |
% \begin{verbatim} |
| 193 |
% \pdffield_submit_new:nnn |
| 194 |
% {mysubmit} |
| 195 |
% { |
| 196 |
% export = fdf, |
| 197 |
% fields= {A,B,C}, |
| 198 |
% exclude, % or include |
| 199 |
% setsubmitflags={...} |
| 200 |
% ... |
| 201 |
% } |
| 202 |
% {URL} |
| 203 |
% \pdffield_pushbutton:n{name=s,caption={Submit~A,B,C},submit=mysubmit} |
| 204 |
% \end{verbatim} |
| 205 |
% |
| 206 |
% The export options are |html|, |pdf|, |fdf| and |xfdf|. The |html| export uses |
| 207 |
% my default the |POST| method, the |GET| method can be forced by setting the |
| 208 |
% |GetMethod| flag---at least according to the reference, I wasn't able yet to test it. |
| 209 |
% |
| 210 |
% |
| 211 |
% The following tabular describes the relation between these export options and the |
| 212 |
% flags. |0| and |1| in the tabular means that the value is set by the code. |*| |
| 213 |
% can be set by the user with the |setFlags| or |setsubmitflags| key. |
| 214 |
% |
| 215 |
% \begin{center} |
| 216 |
% \begin{tabular}{lcccc} |
| 217 |
% Flag & html & pdf & fdf & xfdf \\\hline |
| 218 |
% Include/Exclude & * & 0 & * & * \\ |
| 219 |
% IncludeNoValueFields & * & 0 & * & * \\ |
| 220 |
% ExportFormat & 1 & 0 & 0 & 0 \\ |
| 221 |
% GetMethod & * & 0 & 0 & 0 \\ |
| 222 |
% SubmitCoordinates & * & 0 & 0 & 0 \\ |
| 223 |
% XFDF & 0 & 0 & 0 & 1 \\ |
| 224 |
% IncludeAppendSaves & 0 & 0 & * & 0 \\ |
| 225 |
% IncludeAnnotations & 0 & 0 & * & 0 \\ |
| 226 |
% SubmitPDF & 0 & 1 & 0 & 0 \\ |
| 227 |
% CanonicalFormat & * & 0 & * & * \\ |
| 228 |
% ExclNonUserAnnots & 0 & 0 & * & 0 \\ |
| 229 |
% ExclFKey & 0 & 0 & * & 0 \\ |
| 230 |
% EmbedForm & 0 & 0 & * & 0 \\% |
| 231 |
% \end{tabular} |
| 232 |
% \end{center} |
| 233 |
% |
| 234 |
% \bigskip |
| 235 |
% \subsection{Commands} |
| 236 |
% \begin{function}{\pdffield_reset_new:nn} |
| 237 |
% \begin{syntax} |
| 238 |
% \cs{pdffield_reset_new:nn} \Arg{name} \Arg{key val list} |
| 239 |
% \end{syntax} |
| 240 |
% This defines an new reset action with the name \meta{name}. |
| 241 |
% The keys are described below. |
| 242 |
% \end{function} |
| 243 |
% |
| 244 |
% \begin{function}{\pdffield_submit_new:nnn} |
| 245 |
% \begin{syntax} |
| 246 |
% \cs{pdffield_submit_new:nn} \Arg{name} \Arg{key val list} \Arg{URL} |
| 247 |
% \end{syntax} |
| 248 |
% This defines an submit action with the name \meta{name}. |
| 249 |
% The keys are described below. \meta{URL} should be given verbatim. |
| 250 |
% That means \# and \% should not be escaped. The URL should be |
| 251 |
% correctly percent encoded, or the |urlencode| key should |
| 252 |
% be used then the code will create the percent encoding. |
| 253 |
% |
| 254 |
% \meta{URL} can be a mail address and should then start with |mailto:|. |
| 255 |
% A subject can be attached with |?subject=...|. |
| 256 |
% This normally works quite fine as it only needs a correctly working mail program. |
| 257 |
% (But for some unknown reason my mail program don't like mail addresses with hyphens in them). |
| 258 |
% |
| 259 |
% Alternatively it should be an URL of a script, which should return the correct |
| 260 |
% answer (which one this is, is rather unclear). |
| 261 |
% |
| 262 |
% \end{function} |
| 263 |
% |
| 264 |
% \subsection{Keys for the commands to create actions} |
| 265 |
% \begin{function}{fields} |
| 266 |
% \begin{syntax} |
| 267 |
% |fields| = \Arg{comma list of fully qualified field names} |
| 268 |
% \end{syntax} |
| 269 |
% |fields| is a comma list of \emph{fully qualified} field names, typically this can |
| 270 |
% be the short name set with |name| in a field declaration, but in complex fieldsets |
| 271 |
% it is needed to include the parents in the name too, separated by periods. |
| 272 |
% If |exclude| is set, this list describes the fields that should |
| 273 |
% be excluded from the reset or the submission. |
| 274 |
% The default is |include|: the list describes the fields |
| 275 |
% to reset or submit. Descendant of fields are reset or submitted too! |
| 276 |
% |
| 277 |
% The key is relevant for reset and submit actions. |
| 278 |
% \end{function} |
| 279 |
% |
| 280 |
% \begin{function}{include, exclude} |
| 281 |
% \begin{syntax} |
| 282 |
% |include| \\ |
| 283 |
% |exclude| |
| 284 |
% \end{syntax} |
| 285 |
% These keys are shorthands to unset/set the |Include/Exclude| flag and decide |
| 286 |
% if the list of fields in the |fields| key are included or |
| 287 |
% excluded. The default is |include|: the list describes the fields |
| 288 |
% to reset or submit. |
| 289 |
% |
| 290 |
% The keys are relevant for reset and submit actions. |
| 291 |
% \end{function} |
| 292 |
|
| 293 |
% \begin{function}{urlencode} |
| 294 |
% \begin{syntax} |
| 295 |
% |urlencode| = |true|\verb+|+|false| |
| 296 |
% \end{syntax} |
| 297 |
% When this is true the code will percent encode the submission URL. |
| 298 |
% This is needed if the URL contains for example non-ascii chars or spaces. |
| 299 |
% \end{function} |
| 300 |
% |
| 301 |
% \begin{function}{setsubmitflags,setFlags,unsetsubmitflags,unsetFlags} |
| 302 |
% \begin{syntax} |
| 303 |
% |setsubmitflags| = \Arg{comma list of flags}\\ |
| 304 |
% |setFlags| = \Arg{comma list of flags}\\ |
| 305 |
% |unsetsubmitflags| = |all| \verb"|" \Arg{comma list of flags}\\ |
| 306 |
% |unsetFlags| = |all| \verb"|" \Arg{comma list of flags} |
| 307 |
% \end{syntax} |
| 308 |
% These keys accept a list of flag names and then sets or unsets them, the resulting value |
| 309 |
% is then used with the \texttt{/Flags} key of a submit action. |Include/Exclude| |
| 310 |
% is also used by a reset action andcan also be set with the |exclude| and |include| |
| 311 |
% keys. Depending on the export type of the submit action some flags are set by the code. |
| 312 |
% See the tabular above for details. |
| 313 |
% The flag name can be given in PDF spelling (\texttt{IncludeNoValueFields}), |
| 314 |
% in lowercase (\texttt{includenovaluefields}), and as number. |unsetFlags| and its |
| 315 |
% alias |unsetsubmitflags| know the special value |all| which clears all the fields. |
| 316 |
% |
| 317 |
% The list of flags are: |
| 318 |
% |Include/Exclude|, |IncludeNoValueFields|, |ExportFormat|, |GetMethod|, |
| 319 |
% |SubmitCoordinates|, |XFDF|, |IncludeAppendSaves|, |IncludeAnnotations|, |
| 320 |
% |SubmitPDF|, |CanonicalFormat|, |ExclNonUserAnnots|, |ExclFKey|, |EmbedForm| |
| 321 |
% \end{function} |
| 322 |
% |
| 323 |
% \begin{function}{next} |
| 324 |
% \begin{syntax} |
| 325 |
% |next| = \meta{object reference} |
| 326 |
% \end{syntax} |
| 327 |
% This allows to add a follow up action to the |/Next| key. The value is expanded, so can |
| 328 |
% be given as |\pdf_object_ref:n{name}| and point to a suitable object. |
| 329 |
% \end{function} |
| 330 |
% |
| 331 |
% \subsection{Keys for fields} |
| 332 |
% With the following keys actions can be attached to the annotation of a form field, |
| 333 |
% for example a pushbutton. |
| 334 |
% |
| 335 |
% \begin{function}{reset,submit} |
| 336 |
% \begin{syntax} |
| 337 |
% |reset| = \meta{name}\\ |
| 338 |
% |submit| = \meta{name} |
| 339 |
% \end{syntax} |
| 340 |
% This adds the reset or submit action \meta{name} as action to the annotation. |
| 341 |
% The action should be |
| 342 |
% been defined first. The actions are mutually exclusive, only one action can |
| 343 |
% be added. If more actions are needed use the |next| key. |
| 344 |
% For reset the default value |all| exists and it is used if the key is used |
| 345 |
% without value. |
| 346 |
% \end{function} |
| 347 |
% |
| 348 |
% \begin{function}{import} |
| 349 |
% \begin{syntax} |
| 350 |
% |import| = \meta{file name} |
| 351 |
% \end{syntax} |
| 352 |
% This adds an import action to the annotation. \meta{file name} should |
| 353 |
% be for example the name of a |.fdf| file. If the name contains a path use a |
| 354 |
% slash as separator. non-ascii chars should work, but ascii is safer. |
| 355 |
% The action is mutually exclusive to submit and reset. |
| 356 |
% \end{function} |
| 357 |
% \end{documentation} |
| 358 |
% |
| 359 |
% \begin{implementation} |
| 360 |
% \DoNotIndex |
| 361 |
% {\\ |
| 362 |
% ,\%,\# |
| 363 |
% ,\bitset_clear:N |
| 364 |
% ,\bitset_new:Nn |
| 365 |
% ,\bitset_set_false:Nn |
| 366 |
% ,\bitset_set_true:Nn |
| 367 |
% ,\bitset_to_arabic:N |
| 368 |
% ,\bitset_item:Nn |
| 369 |
% ,\bool_new:N |
| 370 |
% ,\bool_if:NTF |
| 371 |
% ,\box_dp:N |
| 372 |
% ,\box_ht:N |
| 373 |
% ,\l_tmpa_box |
| 374 |
% ,\char_set_catcode_other:N |
| 375 |
% ,\clist_map_inline:nn |
| 376 |
% ,\color_export:nnN |
| 377 |
% ,\color_set:nn |
| 378 |
% ,\color_set:nnn |
| 379 |
% ,\cs_new_protected:Npn |
| 380 |
% ,\cs_new_protected:cpn |
| 381 |
% ,\cs_set_eq:NN |
| 382 |
% ,\cs_gset_eq:cN |
| 383 |
% ,\cs_if_exist:cTF |
| 384 |
% ,\cs_set_protected:Npn |
| 385 |
% ,\cs_generate_variant:Nn |
| 386 |
% ,\cs_gset_eq:NN |
| 387 |
% ,\csname |
| 388 |
% ,\dim_eval:n |
| 389 |
% ,\dim_new:N |
| 390 |
% ,\dim_set:N |
| 391 |
% ,\endcsname |
| 392 |
% ,\exp_args:Ne |
| 393 |
% ,\exp_args:Nne |
| 394 |
% ,\exp_args:Ne |
| 395 |
% ,\fboxsep |
| 396 |
% ,\group_begin: |
| 397 |
% ,\group_end: |
| 398 |
% ,\hbox_to_wd:nn |
| 399 |
% ,\hbox_set:Nn |
| 400 |
% ,\hfill |
| 401 |
% ,\hook_gput_code:nnn |
| 402 |
% ,\int_eval:n |
| 403 |
% ,\int_gincr:N |
| 404 |
% ,\int_new:N |
| 405 |
% ,\int_use:N |
| 406 |
% ,\l_keys_choice_int |
| 407 |
% ,\keys_define:nn |
| 408 |
% ,\keys_set:nn |
| 409 |
% ,\mode_leave_vertical: |
| 410 |
% ,\makebox |
| 411 |
% ,\msg_error:nnn |
| 412 |
% ,\msg_error:nnnn |
| 413 |
% ,\msg_new:nnn |
| 414 |
% ,\msg_warning:nn |
| 415 |
% ,\msg_warning:nnn |
| 416 |
% ,\msg_warning:nnnnn |
| 417 |
% ,\msg_warning:nnnn |
| 418 |
% ,\NeedsTeXFormat |
| 419 |
% ,\normalsize |
| 420 |
% ,\pdf_name_from_unicode_e:n |
| 421 |
% ,\pdf_object_if_exist:nTF |
| 422 |
% ,\pdf_object_if_exist:nF |
| 423 |
% ,\pdf_object_new:n |
| 424 |
% ,\pdf_object_ref:n |
| 425 |
% ,\pdf_object_ref_last: |
| 426 |
% ,\pdf_object_unnamed_write:nn |
| 427 |
% ,\pdf_object_unnamed_write:ne |
| 428 |
% ,\pdf_object_write:nnn |
| 429 |
% ,\pdf_string_from_unicode:nnN |
| 430 |
% ,\pdfannot_box_ref_last: |
| 431 |
% ,\pdfannot_dict_put:nnn |
| 432 |
% ,\pdfannot_dict_put:nne |
| 433 |
% ,\pdfannot_dict_remove:nn |
| 434 |
% ,\pdfannot_widget_box:nnn |
| 435 |
% ,\pdfdict_if_empty:nTF |
| 436 |
% ,\pdfdict_get:nnN |
| 437 |
% ,\pdfdict_new:n |
| 438 |
% ,\pdfdict_put:nnn |
| 439 |
% ,\pdfdict_remove:nn |
| 440 |
% ,\pdfdict_use:n |
| 441 |
% ,\pdfdict_put:nne |
| 442 |
% ,\pdfmanagement_add:nnn |
| 443 |
% ,\pdfmeta_standard_verify:nTF |
| 444 |
% ,\pdfxform_if_exist:nTF |
| 445 |
% ,\pdfxform_new:nnn |
| 446 |
% ,\pdfxform_ref:n |
| 447 |
% ,\phantom |
| 448 |
% ,\prg_do_nothing: |
| 449 |
% ,\ProvidesExplPackage |
| 450 |
% ,\rule |
| 451 |
% ,\seq_gput_right:Nn |
| 452 |
% ,\seq_if_exist:NTF |
| 453 |
% ,\seq_new:N |
| 454 |
% ,\seq_use:Nn |
| 455 |
% ,\seq_clear:N |
| 456 |
% ,\seq_put_right:NV |
| 457 |
% ,\str_if_empty:NTF |
| 458 |
% ,\str_if_in:NnTF |
| 459 |
% ,\str_new:N |
| 460 |
% ,\strut |
| 461 |
% ,\strutbox |
| 462 |
% ,\tl_if_empty:NTF |
| 463 |
% ,\tl_if_empty:NT |
| 464 |
% ,\tl_if_empty:NF |
| 465 |
% ,\tl_put_left:Nn |
| 466 |
% ,\tl_if_empty:nTF |
| 467 |
% ,\tl_if_head_eq_charcode:nNTF |
| 468 |
% ,\tl_put_right:Nn |
| 469 |
% ,\tl_new:N |
| 470 |
% ,\tl_set:Nn |
| 471 |
% ,\tl_to_str:n |
| 472 |
% ,\tl_const:cn |
| 473 |
% ,\tl_use:c |
| 474 |
% ,\use:c |
| 475 |
% } |
| 476 |
% \section{\pkg{l3pdffield-action} Implementation} |
| 477 |
% \begin{macrocode} |
| 478 |
%<*package> |
| 479 |
%<@@=pdffield> |
| 480 |
% \end{macrocode} |
| 481 |
% \subsection{Messages} |
| 482 |
% \begin{macrocode} |
| 483 |
\msg_new:nnn {pdffield}{action-name-undefined} |
| 484 |
{ |
| 485 |
The~'#1'~action~name~'#2'~is~not~defined~and~ |
| 486 |
will~be~ignored. |
| 487 |
} |
| 488 |
|
| 489 |
% \end{macrocode} |
| 490 |
% \subsection{Variables} |
| 491 |
% \begin{variable} |
| 492 |
% { |
| 493 |
% ,\l_@@_action_export_tl |
| 494 |
% ,\l_@@_action_Fields_seq |
| 495 |
% ,\l_@@_action_next_tl |
| 496 |
% } |
| 497 |
% We need to store the export, fields and next value into variables. |
| 498 |
% \begin{macrocode} |
| 499 |
\tl_new:N \l_@@_action_export_tl |
| 500 |
\seq_new:N \l_@@_action_Fields_seq |
| 501 |
\tl_new:N \l_@@_action_next_tl |
| 502 |
% \end{macrocode} |
| 503 |
% \end{variable} |
| 504 |
% \subsection{dictionaries} |
| 505 |
% \begin{macro}{l_@@/ResetForm,l_@@/SubmitForm} |
| 506 |
% We define two dictionaries to handle the reset and submit code. |
| 507 |
% \begin{macrocode} |
| 508 |
\pdfdict_new:n {l_@@/ResetForm} |
| 509 |
\pdfdict_put:nnn {l_@@/ResetForm}{Type}{/Action} |
| 510 |
\pdfdict_put:nnn {l_@@/ResetForm}{S}{/ResetForm} |
| 511 |
\pdfdict_new:n {l_@@/SubmitForm} |
| 512 |
\pdfdict_put:nnn {l_@@/SubmitForm}{Type}{/Action} |
| 513 |
\pdfdict_put:nnn {l_@@/SubmitForm}{S}{/SubmitForm} |
| 514 |
% \end{macrocode} |
| 515 |
% \end{macro} |
| 516 |
% \subsection{bitset for submit action} |
| 517 |
% \begin{variable}{\l_@@_Flags_bitset} |
| 518 |
% A bitset for the submit (and the one reset) flags: |
| 519 |
% \begin{macrocode} |
| 520 |
\bitset_new:Nn \l_@@_Flags_bitset |
| 521 |
{ |
| 522 |
Include/Exclude = 1 |
| 523 |
,IncludeNoValueFields = 2 |
| 524 |
,ExportFormat = 3 |
| 525 |
,GetMethod = 4 |
| 526 |
,SubmitCoordinates = 5 |
| 527 |
,XFDF = 6 |
| 528 |
,IncludeAppendSaves = 7 |
| 529 |
,IncludeAnnotations = 8 |
| 530 |
,SubmitPDF = 9 |
| 531 |
,CanonicalFormat = 10 |
| 532 |
,ExclNonUserAnnots = 11 |
| 533 |
,ExclFKey = 12 |
| 534 |
,EmbedForm = 14 |
| 535 |
,include/exclude = 1 |
| 536 |
,includenovaluefields = 2 |
| 537 |
,exportformat = 3 |
| 538 |
,getmethod = 4 |
| 539 |
,submitcoordinates = 5 |
| 540 |
,xfdf = 6 |
| 541 |
,includeappendsaves = 7 |
| 542 |
,includeannotations = 8 |
| 543 |
,submitpdf = 9 |
| 544 |
,canonicalformat = 10 |
| 545 |
,exclnonuserannots = 11 |
| 546 |
,exclfkey = 12 |
| 547 |
,embedform = 14 |
| 548 |
} |
| 549 |
% \end{macrocode} |
| 550 |
% \end{variable} |
| 551 |
% \begin{macro} |
| 552 |
% { |
| 553 |
% \@@_action_flags_pdf: |
| 554 |
% ,\@@_action_flags_html: |
| 555 |
% ,\@@_action_flags_fdf: |
| 556 |
% ,\@@_action_flags_xfdf: |
| 557 |
% } |
| 558 |
% The following commands sets the forced flags for the export options. |
| 559 |
% \begin{macrocode} |
| 560 |
\cs_new_protected:Npn \@@_action_flags_pdf: |
| 561 |
{ |
| 562 |
\bitset_clear:N \l_@@_Flags_bitset |
| 563 |
\bitset_set_true:Nn \l_@@_Flags_bitset { SubmitPDF } |
| 564 |
} |
| 565 |
|
| 566 |
\cs_new_protected:Npn \@@_action_flags_html: |
| 567 |
{ |
| 568 |
\bitset_set_true:Nn \l_@@_Flags_bitset { ExportFormat } |
| 569 |
\bitset_set_false:Nn \l_@@_Flags_bitset { XFDF } |
| 570 |
\bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAppendSaves } |
| 571 |
\bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAnnotations } |
| 572 |
\bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF } |
| 573 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExclNonUserAnnots } |
| 574 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExclFKey } |
| 575 |
\bitset_set_false:Nn \l_@@_Flags_bitset { EmbedForm } |
| 576 |
} |
| 577 |
|
| 578 |
\cs_new_protected:Npn \@@_action_flags_fdf: |
| 579 |
{ |
| 580 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExportFormat } |
| 581 |
\bitset_set_false:Nn \l_@@_Flags_bitset { GetMethod } |
| 582 |
\bitset_set_false:Nn \l_@@_Flags_bitset { SubmitCoordinates } |
| 583 |
\bitset_set_false:Nn \l_@@_Flags_bitset { XFDF } |
| 584 |
\bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF } |
| 585 |
} |
| 586 |
|
| 587 |
\cs_new_protected:Npn \@@_action_flags_xfdf: |
| 588 |
{ |
| 589 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExportFormat } |
| 590 |
\bitset_set_false:Nn \l_@@_Flags_bitset { GetMethod } |
| 591 |
\bitset_set_false:Nn \l_@@_Flags_bitset { SubmitCoordinates } |
| 592 |
\bitset_set_true:Nn \l_@@_Flags_bitset { XFDF } |
| 593 |
\bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAppendSaves } |
| 594 |
\bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAnnotations } |
| 595 |
\bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF } |
| 596 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExclNonUserAnnots } |
| 597 |
\bitset_set_false:Nn \l_@@_Flags_bitset { ExclFKey } |
| 598 |
\bitset_set_false:Nn \l_@@_Flags_bitset { EmbedForm } |
| 599 |
} |
| 600 |
% \end{macrocode} |
| 601 |
% \end{macro} |
| 602 |
% \subsection{Keys} |
| 603 |
% \begin{macro}{reset,submit,import} |
| 604 |
% These are the three additional keys for the field annotations |
| 605 |
% \begin{macrocode} |
| 606 |
\keys_define:nn { pdffield } |
| 607 |
{ |
| 608 |
reset .code:n = |
| 609 |
{ |
| 610 |
\cs_if_exist:cTF { @@_action_reset_#1: } |
| 611 |
{ |
| 612 |
\use:c { @@_action_reset_#1: } |
| 613 |
\pdfannot_dict_put:nne{widget} |
| 614 |
{A} |
| 615 |
{\tl_use:c { c_@@_action_reset_#1_tl } } |
| 616 |
} |
| 617 |
{ |
| 618 |
\msg_warning:nnnn{pdffield}{action-name-undefined}{reset}{#1} |
| 619 |
} |
| 620 |
} |
| 621 |
,reset .default:n = all |
| 622 |
} |
| 623 |
|
| 624 |
\keys_define:nn { pdffield } |
| 625 |
{ |
| 626 |
submit .code:n = |
| 627 |
{ |
| 628 |
\cs_if_exist:cTF { @@_action_submit_#1: } |
| 629 |
{ |
| 630 |
\use:c { @@_action_submit_#1: } |
| 631 |
\pdfannot_dict_put:nne{widget} |
| 632 |
{A} |
| 633 |
{\tl_use:c { c_@@_action_submit_#1_tl } } |
| 634 |
} |
| 635 |
{ |
| 636 |
\msg_warning:nnnn{pdffield}{action-name-undefined}{submit}{#1} |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
\keys_define:nn { pdffield } |
| 642 |
{ |
| 643 |
import .code:n = |
| 644 |
{ |
| 645 |
\pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_tmpa_str |
| 646 |
\pdf_object_unnamed_write:ne {dict}{/Type/Action/S/ImportData/F\l_@@_tmpa_str} |
| 647 |
\pdfannot_dict_put:nne{widget} |
| 648 |
{A} |
| 649 |
{\pdf_object_ref_last: } |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
% \end{macrocode} |
| 654 |
% \end{macro} |
| 655 |
% \begin{macro}{fields,exclude,include,export,charset,urlencode,next} |
| 656 |
% These are keys used when defining the actions. |
| 657 |
% \begin{macrocode} |
| 658 |
\keys_define:nn { pdffield / action } |
| 659 |
{ |
| 660 |
fields .code:n = |
| 661 |
{ |
| 662 |
\clist_map_inline:nn {#1} |
| 663 |
{ |
| 664 |
\pdf_string_from_unicode:nnN {utf8/string}{##1}\l_@@_tmpa_str |
| 665 |
\seq_put_right:NV\l_@@_action_Fields_seq \l_@@_tmpa_str |
| 666 |
} |
| 667 |
} |
| 668 |
,exclude .code:n = { \bitset_set_true:Nn \l_@@_Flags_bitset {Include/Exclude }} |
| 669 |
,include .code:n = { \bitset_set_false:Nn \l_@@_Flags_bitset {Include/Exclude }} |
| 670 |
,export .choices:nn = {pdf,fdf,html,xfdf} |
| 671 |
{ |
| 672 |
\tl_set:Nn \l_@@_action_export_tl {#1} |
| 673 |
} |
| 674 |
,export .initial:n = {html} |
| 675 |
,charset .choices:nn = |
| 676 |
{utf-8, utf-16, Shift-JIS, BigFive, GBK, UHC} |
| 677 |
{ \pdfdict_put:nnn { l_@@/SubmitForm }{#1} } |
| 678 |
,urlencode .bool_set:N = \l_@@_url_encode_bool |
| 679 |
,next .tl_set:N = \l_@@_action_next_tl |
| 680 |
} |
| 681 |
% \end{macrocode} |
| 682 |
% \end{macro} |
| 683 |
% \begin{macro}{setFlags,setsubmitflags,unsetFlags,unsetsubmitflags} |
| 684 |
% \begin{macrocode} |
| 685 |
\keys_define:nn { pdffield / action } |
| 686 |
{ |
| 687 |
,setFlags .code:n = |
| 688 |
{ |
| 689 |
\clist_map_inline:nn {#1} |
| 690 |
{ |
| 691 |
\bitset_set_true:Nn \l_@@_Flags_bitset {##1} |
| 692 |
} |
| 693 |
} |
| 694 |
,setsubmitflags .meta:n = {setFlags={#1}} |
| 695 |
,unsetFlags .multichoice: |
| 696 |
,unsetFlags / all .code:n = { \bitset_clear:N \l_@@_Flags_bitset} |
| 697 |
,unsetFlags / unknown .code:n = |
| 698 |
{ |
| 699 |
\bitset_set_false:Nn \l_@@_Flags_bitset {#1} |
| 700 |
} |
| 701 |
,unsetsubmitflags .meta:n = {unsetFlags={#1}} |
| 702 |
} |
| 703 |
% \end{macrocode} |
| 704 |
% \end{macro} |
| 705 |
% |
| 706 |
% \subsection{New reset action} |
| 707 |
% |
| 708 |
% \begin{macro}{ \@@_action_reset_new:nn } |
| 709 |
% The command defines a command which will setup the dictionary at first use, |
| 710 |
% and then store the reference in a constant. |
| 711 |
% \begin{macrocode} |
| 712 |
\cs_new_protected:Npn \@@_action_reset_new:nn #1 #2 %#1 name, #2 keyval |
| 713 |
{ |
| 714 |
\cs_new_protected:cpn {@@_action_reset_#1:} |
| 715 |
{ |
| 716 |
\group_begin: |
| 717 |
\seq_clear:N \l_@@_action_Fields_seq |
| 718 |
\keys_set:nn { pdffield / action }{ #2 } |
| 719 |
\pdf_object_unnamed_write:ne |
| 720 |
{ array } |
| 721 |
{ \seq_use:Nn \l_@@_action_Fields_seq {~} } |
| 722 |
\tl_if_empty:NF \l_@@_action_next_tl |
| 723 |
{ |
| 724 |
\pdfdict_put:nne {l_@@/ResetForm}{Next}{\l_@@_action_next_tl} |
| 725 |
} |
| 726 |
\pdfdict_put:nne |
| 727 |
{ l_@@/ResetForm } |
| 728 |
{ Fields } |
| 729 |
{ \pdf_object_ref_last: } |
| 730 |
\pdfdict_put:nne |
| 731 |
{ l_@@/ResetForm } |
| 732 |
{ Flags } |
| 733 |
{ \bitset_item:Nn\l_@@_Flags_bitset{Include/Exclude} } |
| 734 |
\pdf_object_unnamed_write:ne |
| 735 |
{ dict } |
| 736 |
{ \pdfdict_use:n{l_@@/ResetForm} } |
| 737 |
\tl_const:ce { c_@@_action_reset_#1_tl } { \pdf_object_ref_last: } |
| 738 |
\cs_gset_eq:cN {@@_action_reset_#1:} \prg_do_nothing: |
| 739 |
\group_end: |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
\@@_action_reset_new:nn {all}{fields={},exclude} |
| 744 |
% \end{macrocode} |
| 745 |
% \end{macro} |
| 746 |
% |
| 747 |
% \subsection{New submit action} |
| 748 |
% \begin{macro}{\@@_action_submit_new:nn} |
| 749 |
% Quite similar to the reset command, only that we have to use an auxiliary |
| 750 |
% to grab the URL with suitable catcodes. |
| 751 |
% \begin{macrocode} |
| 752 |
\cs_new_protected:Npn \@@_action_submit_new:nn #1 #2 %#1 name, #2 keyval |
| 753 |
{ |
| 754 |
\group_begin: |
| 755 |
\char_set_catcode_other:N \% |
| 756 |
\char_set_catcode_other:N \# |
| 757 |
\@@_action_submit_new:nnn {#1}{#2} |
| 758 |
} |
| 759 |
\cs_new_protected:Npn \@@_action_submit_new:nnn #1 #2 #3 %#1 name, #2 keyval, #3 url |
| 760 |
{ |
| 761 |
\group_end: |
| 762 |
\cs_new_protected:cpn {@@_action_submit_#1:} |
| 763 |
{ |
| 764 |
\group_begin: |
| 765 |
\seq_clear:N \l_@@_action_Fields_seq |
| 766 |
\bitset_clear:N \l_@@_Flags_bitset |
| 767 |
\keys_set:nn {pdffield/action}{#2} |
| 768 |
\use:c{ @@_action_flags_\l_@@_action_export_tl :} |
| 769 |
\pdfdict_put:nne |
| 770 |
{ l_@@/SubmitForm } |
| 771 |
{ Flags } |
| 772 |
{ \bitset_to_arabic:N \l_@@_Flags_bitset } |
| 773 |
\tl_if_empty:NF \l_@@_action_next_tl |
| 774 |
{ |
| 775 |
\pdfdict_put:nne {l_@@/SubmitForm}{Next}{\l_@@_action_next_tl} |
| 776 |
} |
| 777 |
\bool_if:NTF \l_@@_url_encode_bool |
| 778 |
{ \pdf_string_from_unicode:nnN { utf8/URI } {#3}\l_@@_tmpa_str } |
| 779 |
{ \pdf_string_from_unicode:nnN { utf8/string }{#3}\l_@@_tmpa_str } |
| 780 |
\pdf_object_unnamed_write:ne {dict} |
| 781 |
{ |
| 782 |
/FS/URL |
| 783 |
/F \l_@@_tmpa_str |
| 784 |
} |
| 785 |
\pdfdict_put:nne |
| 786 |
{ l_@@/SubmitForm } |
| 787 |
{ F } |
| 788 |
{ \pdf_object_ref_last: } |
| 789 |
\pdf_object_unnamed_write:ne |
| 790 |
{ dict } |
| 791 |
{ \pdfdict_use:n{ l_@@/SubmitForm } } |
| 792 |
\tl_const:ce { c_@@_action_submit_#1_tl } { \pdf_object_ref_last: } |
| 793 |
\cs_gset_eq:cN { @@_action_submit_#1: } \prg_do_nothing: |
| 794 |
\group_end: |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
% \end{macrocode} |
| 799 |
% \end{macro} |
| 800 |
% |
| 801 |
% \subsection{User commands} |
| 802 |
% \begin{macro}{\pdffield_reset_new:nn, \pdffield_submit_new:nnn} |
| 803 |
% \begin{macrocode} |
| 804 |
\cs_set_eq:NN \pdffield_reset_new:nn \@@_action_reset_new:nn |
| 805 |
\cs_set_eq:NN \pdffield_submit_new:nnn \@@_action_submit_new:nn |
| 806 |
%</package> |
| 807 |
% \end{macrocode} |
| 808 |
% \end{macro} |
| 809 |
%\end{implementation} |
| 810 |
|
| 811 |
% \PrintIndex |