summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/pdfmanagement-testphase/l3pdffield-action.dtx
blob: ef7f1a5c4c5649ae00a0884b34feaa2821835fd4 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
% \iffalse meta-comment
%
%% File: l3pdfpdffield-action.dtx
%
% Copyright (C) 2021-2023 The LaTeX Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    http://www.latex-project.org/lppl.txt
%
% This file is part of the "LaTeX PDF management testphase bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/latex3/pdfresources
%
% for those people who are interested.
%
%<*driver>
\DocumentMetadata{}
\documentclass[full]{l3doc}
\usepackage{array,booktabs,siunitx}
\usepackage{l3pdffield-testphase,bearwear}
\hypersetup{pdfauthor=The LaTeX Project,
 pdftitle=l3pdffield (LaTeX PDF management testphase bundle)}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \providecommand\hook[1]{\texttt{#1}}
% \title{^^A
%   The \pkg{l3pdffield-action} module\\ Commands to handle actions of form fields   ^^A
%   \\ \LaTeX{} PDF management testphase bundle
% }
%
% \author{^^A
%  The \LaTeX{} Project\thanks
%    {^^A
%      E-mail:
%        \href{mailto:latex-team@latex-project.org}
%          {latex-team@latex-project.org}^^A
%    }^^A
% }
%
% \date{Version 0.96d, released 2023-12-09}
%
% \maketitle
% \begin{documentation}
% \section{\pkg{l3pdffield-action} Introduction}
% This is the documentation for actions for formular fields, for general information about form fields
% check the documentation l3pdffield.
%
% \begin{center}
%  \ExplSyntaxOn
%  A:~ \pdffield_checkbox:n {name=A}\quad B:~\pdffield_checkbox:n {name=B}\par\bigskip
%  \pdffield_pushbutton:n{name=all,caption=Reset~All,reset}\quad
%  \pdffield_reset_new:nn{B}{fields=B}
%  \pdffield_pushbutton:n{name=all,caption=Reset~B,reset=B}\quad
%  \ExplSyntaxOff
% \end{center}
%
% Please keep in mind
% \begin{itemize}
% \item Not every PDF viewer supports form fields.
% \item Even if they support it, that doesn't mean that
%  they support actions like Submit.
% \item The handling can depend on settings in the PDF viewer.
% \item Standards like pdf/A disable features of form fields too
% (as you typically can't change the PDF).
% \end{itemize}
%
% \section{Actions}
%
% Actions must be handled in three places: In the action dictionary (|/A|)
% of the annotation(s), in the additional action dictionary of the field (|/AA|),
% and in the additional action dictionary (|/AA|) of the annotation(s). The distinction
% between the two |/AA| dictionaries is relevant as field actions can only be
% added when the field is initialized, so typically with the first field command
% for a specific name, while annotation actions can be added for example only to
% one specific instance of a checkbox or to pushbuttons belonging to the same field.
%
% \subsection{The additional action dictionaries (AA)}
% The actions in the |/AA| dictionaries are JavaScript (ECMAScript) actions.
% An example is the |calculate|/|AA/C| action, which is added with the |/C| key:
%
% \begin{verbatim}
% Netto~\pdffield_textfield:n{name=netto}~
% \pdf_object_unnamed_write:ne{stream}
%   {
%     {}
%     {
%      var~f_netto = this.getField("netto");
%      event.value = 1.19*f_netto.value;
%     }
%   }
% \tl_set:Ne\l_tmpa_tl{\pdf_object_ref_last:}
% Brutto~\pdffield_textfield:n{name=brutto,AA/C={\l_tmpa_tl}}
% \end{verbatim}
%
% The main problem with scripts is to get the escaping right. While it is possible
% to pass the script as string, it is less error prone to include it as (file) stream
% and to reference the object number as done in the example.
%
% \subsection{The action dictionary (A)}
%
% The action dictionary can contain much more action types. The PDF reference lists 20
% different types\footnote{Sound and Movie are deprecated in PDF~2.0}:
% GoTo, GoToR, GoToE, GoToDp, Launch, Thread, URI, Sound, Movie,
% Hide, Named, SubmitForm, ResetForm, ImportData, SetOCGState, Rendition,
% Trans, GoTo3DView, JavaScript, RichMediaExecute.
%
% And action dictionary typically looks like this:
% \begin{verbatim}
% /A << /Type /Action
%       /S    ... % type name, e.g. /URI
%       /Next ... % optional, next action
%       ...   ... % more keys
%    >>
% \end{verbatim}
%
% The |/Next| key allows to chain actions. The value can be a reference to a
% single action, or an array of actions.
%
% It depends on the action type which other keys should be used.
%
% While almost all actions are usable in the annotations of a field, the three
% actions |SubmitForm|, |ResetForm| and |ImportData| are specific to fields and need
% explicit support. This support is the main task of this module.
%
% \subsubsection{ResetForm}
% The |ResetForm| action resets the fields of a form. The action is typically
% attached to a pushbutton.
%
% In simple cases the action only need to contain the subtype entry and then resets
% everything (sadly with some side-effect on the appearance of the pushbutton, sigh).
%
% \begin{verbatim}
% \group_begin:
% \pdfannot_dict_put:nnn{widget}{A}{<</Type/Action/S/ResetForm>>}
% \pdffield_pushbutton:n{name=R,caption=Reset}
% \group_end:
% \end{verbatim}
%
% A |ResetForm| action knows two optional keys: |/Fields| allows to describe or restrict
% the fields which should be reset. Depending on the setting of the |/Flags| key
% the value of |/Fields| describes the fields to reset or the fields to leave unchanged.
%
% The commands of this module allow to store actions under a name which can then be
% used in the key-val list of a field annotation.
%
% A reset action can be defined and used like this
% \begin{verbatim}
% \pdffield_reset_new:nn
%   {myreset}
%   {
%     fields= {A,B,C},
%     exclude     % or include
%   }
% \pdffield_pushbutton:n{name=r,caption=Reset,reset=myreset}
% \end{verbatim}
%
% |myreset| is the name the action can be referred to with the |reset| key.
%
% It is possible to define and use a reset action before all fields it
% refers too have been created.
% The list of names can contain names that are actually not used by the form.
%
% The reset action |all| is predefined.
%
% \subsubsection{ImportData}
% The |ImportData| action allows to import field data from an external file, for example
% a |.fdf| created with the submit action.
% The action is typically attached to a pushbutton, its only value is a file name.
%
% \subsubsection{SubmitForm}
%
% |SubmitForm| is the most challenging action. There are more keys in the dictionary,
% 13 flags, and there are four export options, which require each some flag settings.
% And the main argument is an url, which can contain special chars like \# or \% and
% so need special handling.
%
% A submit action can be defined like this
% \begin{verbatim}
% \pdffield_submit_new:nnn
%   {mysubmit}
%   {
%     export = fdf,
%     fields= {A,B,C},
%     exclude,     % or include
%     setsubmitflags={...}
%     ...
%   }
%   {URL}
% \pdffield_pushbutton:n{name=s,caption={Submit~A,B,C},submit=mysubmit}
% \end{verbatim}
%
% The export options are |html|, |pdf|, |fdf| and |xfdf|. The |html| export uses
% my default the |POST| method, the |GET| method can be forced by setting the
% |GetMethod| flag---at least according to the reference, I wasn't able yet to test it.
%
%
% The following tabular describes the relation between these export options and the
% flags. |0| and |1| in the tabular means that the value is set by the code. |*|
% can be set by the user with the |setFlags| or |setsubmitflags| key.
%
% \begin{center}
% \begin{tabular}{lcccc}
%     Flag                 & html  & pdf & fdf   & xfdf \\\hline
%     Include/Exclude      & *     & 0   &  *    &  *   \\
%     IncludeNoValueFields & *     & 0   &  *    &  *   \\
%     ExportFormat         & 1     & 0   &  0    &  0   \\
%     GetMethod            & *     & 0   &  0    &  0   \\
%     SubmitCoordinates    & *     & 0   &  0    &  0   \\
%     XFDF                 & 0     & 0   &  0    &  1   \\
%     IncludeAppendSaves   & 0     & 0   &  *    &  0   \\
%     IncludeAnnotations   & 0     & 0   &  *    &  0   \\
%     SubmitPDF            & 0     & 1   &  0    &  0   \\
%     CanonicalFormat      & *     & 0   &  *    &  *   \\
%     ExclNonUserAnnots    & 0     & 0   &  *    &  0   \\
%     ExclFKey             & 0     & 0   &  *    &  0   \\
%     EmbedForm            & 0     & 0   &  *    &  0   \\%
% \end{tabular}
% \end{center}
%
% \bigskip
% \subsection{Commands}
% \begin{function}{\pdffield_reset_new:nn}
% \begin{syntax}
% \cs{pdffield_reset_new:nn}\Arg{name}\Arg{key val list}
% \end{syntax}
% This defines an new reset action with the name \meta{name}.
% The keys are described below.
% \end{function}
%
% \begin{function}{\pdffield_submit_new:nnn}
% \begin{syntax}
% \cs{pdffield_submit_new:nn}\Arg{name}\Arg{key val list}\Arg{URL}
% \end{syntax}
% This defines an submit action with the name \meta{name}.
% The keys are described below. \meta{URL} should be given verbatim.
% That means \#  and \% should not be escaped. The URL should be
% correctly percent encoded, or the |urlencode| key should
% be used then the code will create the percent encoding.
%
% \meta{URL} can be a mail address and should then start with |mailto:|.
% A subject can be attached with |?subject=...|.
% This normally works quite fine as it only needs a correctly working mail programm.
% (But for some unknown reason my mail program don't like mail addresses with hyphens in them).
%
% Alternativly it should be an URL of a script, which should return the correct
% answer (which one this is, is rather unclear).
%
% \end{function}
%
% \subsection{Keys for the commands to create actions}
% \begin{function}{fields}
% \begin{syntax}
% |fields| = \Arg{comma list of fully qualified field names}
% \end{syntax}
% |fields| is a comma list of \emph{fully qualified} field names, typically this can
% be the short name set with |name| in a field declaration, but in complex fieldsets
% it is needed to include the parents in the name too, separated by periods.
% If |exclude| is set, this list describes the fields that should
% be excluded from the reset or the submission.
% The default is |include|: the list describes the fields
% to reset or submit. Descendant of fields are reset or submitted too!
%
% The key is relevant for reset and submit actions.
% \end{function}
%
% \begin{function}{include, exclude}
% \begin{syntax}
% |include| \\
% |exclude|
% \end{syntax}
% These keys are shorthands to unset/set the |Include/Exclude| flag and decide
% if the list of fields in the |fields| key are included or
% excluded. The default is |include|: the list describes the fields
% to reset or submit.
%
% The keys are relevant for reset and submit actions.
% \end{function}

% \begin{function}{urlencode}
% \begin{syntax}
% |urlencode| = |true|\verb+|+|false|
% \end{syntax}
% When this is true the code will percent encode the submission URL.
% This is needed if the URL contains for example non-ascii chars or spaces.
% \end{function}
%
% \begin{function}{setsubmitflags,setFlags,unsetsubmitflags,unsetFlags}
%  \begin{syntax}
%   |setsubmitflags| = \Arg{comma list of flags}\\
%   |setFlags| = \Arg{comma list of flags}\\
%   |unsetsubmitflags| = |all| \verb"|" \Arg{comma list of flags}\\
%   |unsetFlags| = |all| \verb"|" \Arg{comma list of flags}
%  \end{syntax}
% These keys accept a list of flag names and then sets or unsets them, the resulting value
% is then used with the \texttt{/Flags} key of a submit action. |Include/Exclude|
% is also used by a reset action andcan also be set with the |exclude| and |include|
% keys.  Depending on the export type of the submit action some flags are set by the code.
% See the tabular above for details.
% The flag name can be given in PDF spelling (\texttt{IncludeNoValueFields}),
% in lowercase (\texttt{includenovaluefields}), and as number. |unsetFlags| and its
% alias |unsetsubmitflags|  know the special value |all| which clears all the fields.
%
% The list of flags are:
% |Include/Exclude|, |IncludeNoValueFields|, |ExportFormat|, |GetMethod|,
% |SubmitCoordinates|, |XFDF|, |IncludeAppendSaves|, |IncludeAnnotations|,
% |SubmitPDF|, |CanonicalFormat|, |ExclNonUserAnnots|, |ExclFKey|, |EmbedForm|
% \end{function}
%
% \begin{function}{next}
% \begin{syntax}
% |next| = \meta{object reference}
% \end{syntax}
% This allows to add a follow up action to the |/Next| key. The value is expanded, so can
% be given as |\pdf_object_ref:n{name}| and point to a suitable object.
% \end{function}
%
% \subsection{Keys for fields}
% With the following keys actions can be attached to the annotation of a form field,
% for example a pushbutton.
%
% \begin{function}{reset,submit}
% \begin{syntax}
% |reset|  = \meta{name}\\
% |submit| = \meta{name}
% \end{syntax}
% This adds the reset or submit action \meta{name} as action to the annotation.
% The action should be
% been defined first. The actions are mutually exclusive, only one action can
% be added. If more actions are needed use the |next| key.
% For reset the default value |all| exists and it is used if the key is used
% without value.
% \end{function}
%
% \begin{function}{import}
% \begin{syntax}
% |import| = \meta{file name}
% \end{syntax}
% This adds an import action to the annotation. \meta{file name} should
% be for example the name of a |.fdf| file. If the name contains a path use a
% slash as separator. non-ascii chars should work, but ascii is safer.
% The action is mutually exclusive to submit and reset.
% \end{function}
% \end{documentation}
%
% \begin{implementation}
% \DoNotIndex
%  {\\
%  ,\%,\#
% ,\bitset_clear:N
% ,\bitset_new:Nn
% ,\bitset_set_false:Nn
% ,\bitset_set_true:Nn
% ,\bitset_to_arabic:N
% ,\bitset_item:Nn
% ,\bool_new:N
% ,\bool_if:NTF
% ,\box_dp:N
% ,\box_ht:N
% ,\l_tmpa_box
% ,\char_set_catcode_other:N
% ,\clist_map_inline:nn
% ,\color_export:nnN
% ,\color_set:nn
% ,\color_set:nnn
% ,\cs_new_protected:Npn
% ,\cs_new_protected:cpn
% ,\cs_set_eq:NN
% ,\cs_gset_eq:cN
% ,\cs_if_exist:cTF
% ,\cs_set_protected:Npn
% ,\cs_generate_variant:Nn
% ,\cs_gset_eq:NN
% ,\csname
% ,\dim_eval:n
% ,\dim_new:N
% ,\dim_set:N
% ,\endcsname
% ,\exp_args:Ne
% ,\exp_args:Nne
% ,\exp_args:Ne
% ,\fboxsep
% ,\group_begin:
% ,\group_end:
% ,\hbox_to_wd:nn
% ,\hbox_set:Nn
% ,\hfill
% ,\hook_gput_code:nnn
% ,\int_eval:n
% ,\int_gincr:N
% ,\int_new:N
% ,\int_use:N
% ,\l_keys_choice_int
% ,\keys_define:nn
% ,\keys_set:nn
% ,\mode_leave_vertical:
% ,\makebox
% ,\msg_error:nnn
% ,\msg_error:nnnn
% ,\msg_new:nnn
% ,\msg_warning:nn
% ,\msg_warning:nnn
% ,\msg_warning:nnnnn
% ,\msg_warning:nnnn
% ,\NeedsTeXFormat
% ,\normalsize
% ,\pdf_name_from_unicode_e:n
% ,\pdf_object_if_exist:nTF
% ,\pdf_object_if_exist:nF
% ,\pdf_object_new:n
% ,\pdf_object_ref:n
% ,\pdf_object_ref_last:
% ,\pdf_object_unnamed_write:nn
% ,\pdf_object_unnamed_write:ne
% ,\pdf_object_write:nnn
% ,\pdf_string_from_unicode:nnN
% ,\pdfannot_box_ref_last:
% ,\pdfannot_dict_put:nnn
% ,\pdfannot_dict_put:nne
% ,\pdfannot_dict_remove:nn
% ,\pdfannot_widget_box:nnn
% ,\pdfdict_if_empty:nTF
% ,\pdfdict_get:nnN
% ,\pdfdict_new:n
% ,\pdfdict_put:nnn
% ,\pdfdict_remove:nn
% ,\pdfdict_use:n
% ,\pdfdict_put:nne
% ,\pdfmanagement_add:nnn
% ,\pdfmeta_standard_verify:nTF
% ,\pdfxform_if_exist:nTF
% ,\pdfxform_new:nnn
% ,\pdfxform_ref:n
% ,\phantom
% ,\prg_do_nothing:
% ,\ProvidesExplPackage
% ,\rule
% ,\seq_gput_right:Nn
% ,\seq_if_exist:NTF
% ,\seq_new:N
% ,\seq_use:Nn
% ,\seq_clear:N
% ,\seq_put_right:NV
% ,\str_if_empty:NTF
% ,\str_if_in:NnTF
% ,\str_new:N
% ,\strut
% ,\strutbox
% ,\tl_if_empty:NTF
% ,\tl_if_empty:NT
% ,\tl_if_empty:NF
% ,\tl_put_left:Nn
% ,\tl_if_empty:nTF
% ,\tl_if_head_eq_charcode:nNTF
% ,\tl_put_right:Nn
% ,\tl_new:N
% ,\tl_set:Nn
% ,\tl_to_str:n
% ,\tl_const:cn
% ,\tl_use:c
% ,\use:c
%   }
% \section{\pkg{l3pdffield-action} Implementation}
%    \begin{macrocode}
%<*package>
%<@@=pdffield>
%    \end{macrocode}
% \subsection{Messages}
%    \begin{macrocode}
\msg_new:nnn {pdffield}{action-name-undefined}
  {
    The~'#1'~action~name~'#2'~is~not~defined~and~
    will~be~ignored.
  }

%    \end{macrocode}
% \subsection{Variables}
% \begin{variable}
%  {
%     ,\l_@@_action_export_tl
%     ,\l_@@_action_Fields_seq
%     ,\l_@@_action_next_tl
%  }
% We need to store the export, fields and next value into variables.
%    \begin{macrocode}
\tl_new:N  \l_@@_action_export_tl
\seq_new:N \l_@@_action_Fields_seq
\tl_new:N  \l_@@_action_next_tl
%    \end{macrocode}
% \end{variable}
% \subsection{dictionaries}
% \begin{macro}{l_@@/ResetForm,l_@@/SubmitForm}
%  We define two dictionaries to handle the reset and submit code.
%    \begin{macrocode}
\pdfdict_new:n   {l_@@/ResetForm}
\pdfdict_put:nnn {l_@@/ResetForm}{Type}{/Action}
\pdfdict_put:nnn {l_@@/ResetForm}{S}{/ResetForm}
\pdfdict_new:n   {l_@@/SubmitForm}
\pdfdict_put:nnn {l_@@/SubmitForm}{Type}{/Action}
\pdfdict_put:nnn {l_@@/SubmitForm}{S}{/SubmitForm}
%    \end{macrocode}
% \end{macro}
% \subsection{bitset for submit action}
% \begin{variable}{\l_@@_Flags_bitset}
% A bitset for the submit (and the one reset) flags:
%    \begin{macrocode}
\bitset_new:Nn \l_@@_Flags_bitset
  {
     Include/Exclude      = 1
    ,IncludeNoValueFields = 2
    ,ExportFormat         = 3
    ,GetMethod            = 4
    ,SubmitCoordinates    = 5
    ,XFDF                 = 6
    ,IncludeAppendSaves   = 7
    ,IncludeAnnotations   = 8
    ,SubmitPDF            = 9
    ,CanonicalFormat      = 10
    ,ExclNonUserAnnots    = 11
    ,ExclFKey             = 12
    ,EmbedForm            = 14
    ,include/exclude      = 1
    ,includenovaluefields = 2
    ,exportformat         = 3
    ,getmethod            = 4
    ,submitcoordinates    = 5
    ,xfdf                 = 6
    ,includeappendsaves   = 7
    ,includeannotations   = 8
    ,submitpdf            = 9
    ,canonicalformat      = 10
    ,exclnonuserannots    = 11
    ,exclfkey             = 12
    ,embedform            = 14
  }
%    \end{macrocode}
% \end{variable}
% \begin{macro}
%  {
%   \@@_action_flags_pdf:
%   ,\@@_action_flags_html:
%   ,\@@_action_flags_fdf:
%   ,\@@_action_flags_xfdf:
%  }
% The following commands sets the forced flags for the export options.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_action_flags_pdf:
  {
    \bitset_clear:N \l_@@_Flags_bitset
    \bitset_set_true:Nn \l_@@_Flags_bitset { SubmitPDF }
  }

\cs_new_protected:Npn \@@_action_flags_html:
  {
    \bitset_set_true:Nn \l_@@_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l_@@_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAppendSaves }
    \bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAnnotations }
    \bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF }
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExclNonUserAnnots }
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExclFKey }
    \bitset_set_false:Nn \l_@@_Flags_bitset { EmbedForm }
  }

\cs_new_protected:Npn \@@_action_flags_fdf:
  {
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l_@@_Flags_bitset { GetMethod }
    \bitset_set_false:Nn \l_@@_Flags_bitset { SubmitCoordinates }
    \bitset_set_false:Nn \l_@@_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF }
  }

\cs_new_protected:Npn \@@_action_flags_xfdf:
  {
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l_@@_Flags_bitset { GetMethod }
    \bitset_set_false:Nn \l_@@_Flags_bitset { SubmitCoordinates }
    \bitset_set_true:Nn \l_@@_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAppendSaves }
    \bitset_set_false:Nn \l_@@_Flags_bitset { IncludeAnnotations }
    \bitset_set_false:Nn \l_@@_Flags_bitset { SubmitPDF }
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExclNonUserAnnots }
    \bitset_set_false:Nn \l_@@_Flags_bitset { ExclFKey }
    \bitset_set_false:Nn \l_@@_Flags_bitset { EmbedForm }
  }
%    \end{macrocode}
% \end{macro}
% \subsection{Keys}
% \begin{macro}{reset,submit,import}
% These are the three additional keys for the field annotations
%    \begin{macrocode}
\keys_define:nn { pdffield }
  {
    reset .code:n =
      {
        \cs_if_exist:cTF { @@_action_reset_#1: }
          {
            \use:c { @@_action_reset_#1: }
            \pdfannot_dict_put:nne{widget}
             {A}
             {\tl_use:c { c_@@_action_reset_#1_tl } }
          }
          {
            \msg_warning:nnnn{pdffield}{action-name-undefined}{reset}{#1}
          }
      }
   ,reset .default:n = all
  }

\keys_define:nn { pdffield }
  {
    submit .code:n =
      {
        \cs_if_exist:cTF { @@_action_submit_#1: }
          {
            \use:c { @@_action_submit_#1: }
            \pdfannot_dict_put:nne{widget}
             {A}
             {\tl_use:c { c_@@_action_submit_#1_tl } }
          }
          {
            \msg_warning:nnnn{pdffield}{action-name-undefined}{submit}{#1}
          }
      }
  }

\keys_define:nn { pdffield }
  {
    import .code:n =
      {
        \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_tmpa_str
        \pdf_object_unnamed_write:ne {dict}{/Type/Action/S/ImportData/F\l_@@_tmpa_str}
        \pdfannot_dict_put:nne{widget}
          {A}
          {\pdf_object_ref_last: }
      }
  }

%    \end{macrocode}
% \end{macro}
% \begin{macro}{fields,exclude,include,export,charset,urlencode,next}
% These are keys used when defining the actions.
%    \begin{macrocode}
\keys_define:nn { pdffield / action }
  {
    fields .code:n  =
      {
        \clist_map_inline:nn {#1}
          {
            \pdf_string_from_unicode:nnN {utf8/string}{##1}\l_@@_tmpa_str
            \seq_put_right:NV\l_@@_action_Fields_seq \l_@@_tmpa_str
          }
      }
    ,exclude .code:n = { \bitset_set_true:Nn \l_@@_Flags_bitset {Include/Exclude }}
    ,include .code:n = { \bitset_set_false:Nn \l_@@_Flags_bitset {Include/Exclude }}
    ,export .choices:nn = {pdf,fdf,html,xfdf}
      {
        \tl_set:Nn \l_@@_action_export_tl {#1}
      }
    ,export .initial:n = {html}
    ,charset .choices:nn =
      {utf-8, utf-16, Shift-JIS, BigFive, GBK, UHC}
      { \pdfdict_put:nnn { l_@@/SubmitForm }{#1} }
    ,urlencode .bool_set:N = \l_@@_url_encode_bool
    ,next .tl_set:N = \l_@@_action_next_tl
 }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{setFlags,setsubmitflags,unsetFlags,unsetsubmitflags}
%    \begin{macrocode}
\keys_define:nn { pdffield / action }
  {
    ,setFlags .code:n =
      {
        \clist_map_inline:nn {#1}
          {
            \bitset_set_true:Nn \l_@@_Flags_bitset {##1}
          }
      }
    ,setsubmitflags .meta:n = {setFlags={#1}}
    ,unsetFlags .multichoice:
    ,unsetFlags / all .code:n = { \bitset_clear:N \l_@@_Flags_bitset}
    ,unsetFlags / unknown .code:n =
      {
        \bitset_set_false:Nn \l_@@_Flags_bitset {#1}
      }
    ,unsetsubmitflags .meta:n = {unsetFlags={#1}}
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{New reset action}
%
% \begin{macro}{ \@@_action_reset_new:nn }
% The command defines a command which will setup the dictionary at first use,
% and then store the reference in a constant.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_action_reset_new:nn #1 #2 %#1 name, #2 keyval
  {
    \cs_new_protected:cpn {@@_action_reset_#1:}
      {
        \group_begin:
        \seq_clear:N \l_@@_action_Fields_seq
        \keys_set:nn { pdffield / action }{ #2 }
        \pdf_object_unnamed_write:ne
          { array }
          { \seq_use:Nn \l_@@_action_Fields_seq {~} }
        \tl_if_empty:NF \l_@@_action_next_tl
          {
            \pdfdict_put:nne {l_@@/ResetForm}{Next}{\l_@@_action_next_tl}
          }
        \pdfdict_put:nne
          { l_@@/ResetForm }
          { Fields }
          { \pdf_object_ref_last: }
        \pdfdict_put:nne
          { l_@@/ResetForm }
          { Flags }
          { \bitset_item:Nn\l_@@_Flags_bitset{Include/Exclude} }
        \pdf_object_unnamed_write:ne
          { dict }
          { \pdfdict_use:n{l_@@/ResetForm} }
        \tl_const:ce { c_@@_action_reset_#1_tl } { \pdf_object_ref_last: }
        \cs_gset_eq:cN {@@_action_reset_#1:} \prg_do_nothing:
        \group_end:
      }
  }

\@@_action_reset_new:nn  {all}{fields={},exclude}
%    \end{macrocode}
% \end{macro}
%
% \subsection{New submit action}
% \begin{macro}{\@@_action_submit_new:nn}
% Quite similar to the reset command, only that we have to use an auxiliary
% to grab the URL with suitable catcodes.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_action_submit_new:nn #1 #2 %#1 name, #2 keyval
  {
    \group_begin:
    \char_set_catcode_other:N \%
    \char_set_catcode_other:N \#
    \@@_action_submit_new:nnn {#1}{#2}
  }
\cs_new_protected:Npn \@@_action_submit_new:nnn #1 #2 #3 %#1 name, #2 keyval, #3 url
  {
    \group_end:
    \cs_new_protected:cpn {@@_action_submit_#1:}
      {
        \group_begin:
        \seq_clear:N    \l_@@_action_Fields_seq
        \bitset_clear:N \l_@@_Flags_bitset
        \keys_set:nn {pdffield/action}{#2}
        \use:c{ @@_action_flags_\l_@@_action_export_tl :}
        \pdfdict_put:nne
          { l_@@/SubmitForm }
          { Flags }
          { \bitset_to_arabic:N \l_@@_Flags_bitset }
        \tl_if_empty:NF \l_@@_action_next_tl
          {
            \pdfdict_put:nne {l_@@/SubmitForm}{Next}{\l_@@_action_next_tl}
          }
        \bool_if:NTF \l_@@_url_encode_bool
          { \pdf_string_from_unicode:nnN { utf8/URI }   {#3}\l_@@_tmpa_str }
          { \pdf_string_from_unicode:nnN { utf8/string }{#3}\l_@@_tmpa_str }
        \pdf_object_unnamed_write:ne {dict}
          {
            /FS/URL
            /F \l_@@_tmpa_str
          }
        \pdfdict_put:nne
          { l_@@/SubmitForm }
          { F }
          { \pdf_object_ref_last: }
        \pdf_object_unnamed_write:ne
          { dict }
          { \pdfdict_use:n{ l_@@/SubmitForm } }
        \tl_const:ce { c_@@_action_submit_#1_tl } { \pdf_object_ref_last: }
        \cs_gset_eq:cN { @@_action_submit_#1: } \prg_do_nothing:
        \group_end:
      }
  }

%    \end{macrocode}
% \end{macro}
%
% \subsection{User commands}
% \begin{macro}{\pdffield_reset_new:nn, \pdffield_submit_new:nnn}
%    \begin{macrocode}
\cs_set_eq:NN \pdffield_reset_new:nn   \@@_action_reset_new:nn
\cs_set_eq:NN \pdffield_submit_new:nnn \@@_action_submit_new:nn
%</package>
%    \end{macrocode}
% \end{macro}
%\end{implementation}

% \PrintIndex