Foxit PDF SDK
fs_pdfform.h
Go to the documentation of this file.
1 
15 #ifndef FS_PDFFORM_H_
16 #define FS_PDFFORM_H_
17 
18 #include "common/fs_common.h"
19 #include "fdf/fs_fdfdoc.h"
22 
28 namespace foxit {
32 namespace pdf {
33 class PDFDoc;
34 class PDFPage;
38 namespace interform {
39 // forward declaration
40 class Control;
41 class Field;
42 
44 FSDK_DEFINE_ARRAY(FieldArray,Field)
45 
46 
47 class ChoiceOption FS_FINAL : public Object {
48  public:
51  : option_value(WString())
52  , option_label(WString())
53  , selected(false)
54  , default_selected(false) {}
55 
66  ChoiceOption(const wchar_t* option_value, const wchar_t* option_label, bool selected, bool default_selected)
67  : option_value(option_value)
68  , option_label(option_label)
69  , selected(selected)
70  , default_selected(default_selected) {}
71 
77  ChoiceOption(const ChoiceOption& option)
78  : option_value(option.option_value)
79  , option_label(option.option_label)
80  , selected(option.selected)
81  , default_selected(option.default_selected) {}
82 
90  ChoiceOption& operator = (const ChoiceOption& option) {
91  option_value = option.option_value;
92  option_label = option.option_label;
93  selected = option.selected;
94  default_selected = option.default_selected;
95  return *this;
96  }
97 
110  void Set(const wchar_t* option_value, const wchar_t* option_label, bool selected, bool default_selected) {
111  this->option_value = option_value;
112  this->option_label = option_label;
113  this->selected = selected;
114  this->default_selected = default_selected;
115  }
118 
121 
123  bool selected;
124 
127 };
128 
130 FSDK_DEFINE_ARRAY(ChoiceOptionArray, ChoiceOption)
131 
132 
145 class Field : public Base {
146  public:
152  typedef enum _Type {
154  e_TypeUnknown = 0,
156  e_TypePushButton = 1,
158  e_TypeCheckBox = 2,
160  e_TypeRadioButton = 3,
162  e_TypeComboBox = 4,
164  e_TypeListBox = 5,
166  e_TypeTextField = 6,
168  e_TypeSignature = 7
169  } Type;
170 
176  typedef enum _Flags {
183  e_FlagReadOnly = 0x01,
185  e_FlagRequired = 0x02,
187  e_FlagNoExport = 0x04,
193  e_FlagButtonNoToggleToOff = 0x100,
199  e_FlagButtonRadiosInUnison = 0x200,
204  e_FlagTextMultiline = 0x100,
212  e_FlagTextPassword = 0x200,
218  e_FlagTextDoNotScroll = 0x400,
224  e_FlagTextComb = 0x800,
229  e_FlagComboEdit = 0x100,
234  e_FlagChoiseMultiSelect = 0x100
235  } Flags;
236 
237 
245  Field(const PDFDoc& document, objects::PDFDictionary* field_dict);
246 
252  Field(const Field& field);
260  Field& operator = (const Field& other);
261 
269  bool operator == (const Field& other) const;
277  bool operator != (const Field& other) const;
278 
280  ~Field();
281 
289  bool IsEmpty() const;
290 
297  Type GetType() const;
298 
307  uint32 GetFlags() const;
308 
319  void SetFlags(uint32 flags);
320 
326  WString GetName() const;
327 
336  WString GetDefaultValue() const;
337 
348  void SetDefaultValue(const wchar_t* value);
349 
359  WString GetValue() const;
360 
386  void SetValue(const wchar_t* value);
387 
400  common::Alignment GetAlignment() const;
401 
418  void SetAlignment(common::Alignment alignment);
419 
430  WString GetAlternateName() const;
431 
445  void SetAlternateName(const wchar_t* alternate_name);
446 
452  DefaultAppearance GetDefaultAppearance() const;
453 
463  void SetDefaultAppearance(const DefaultAppearance& default_ap);
464 
472  WString GetMappingName() const;
473 
484  void SetMappingName(const wchar_t* name);
485 
493  int GetMaxLength() const;
494 
504  void SetMaxLength(int max_length);
505 
514  ChoiceOptionArray GetOptions() const;
515 
526  void SetOptions(const ChoiceOptionArray& option_array);
527 
537  int GetTopVisibleIndex();
538 
550  void SetTopVisibleIndex(int index);
551 
557  int GetControlCount() const;
558 
567  Control GetControl(int index);
568 
576  int GetControlCount(const foxit::pdf::PDFPage& page) const;
577 
588  Control GetControl(const foxit::pdf::PDFPage& page, int index);
589 
595  bool Reset();
596 
602  objects::PDFDictionary* GetDict() const;
611  objects::PDFObject* GetValueObj() const;
612 
621  objects::PDFObject* GetDefaultValueObj() const;
632  objects::PDFObject* GetInheritedAttribute(const char* attribute_name) const;
633 
634  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
635  explicit Field(FS_HANDLE handle = NULL);
636 };
637 
663 class Form FS_FINAL : public Base {
664  public:
673  explicit Form(const pdf::PDFDoc& document);
679  Form(const Form& other);
687  Form& operator = (const Form& other);
688 
696  bool operator == (const Form& other) const;
704  bool operator != (const Form& other) const;
705 
707  ~Form();
708 
716  bool IsEmpty() const;
717 
730 
745  void SetAlignment(common::Alignment alignment);
746 
752  bool NeedConstructAppearances() const;
753 
762  void SetConstructAppearances(bool need_construct);
763 
782  Control GetControlAtDevicePoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type,
783  const Matrix* matrix = NULL);
784 
799  Control GetControlAtPoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type);
800 
807 
817  void SetDefaultAppearance(const DefaultAppearance& default_ap);
818 
824  PDFDoc GetDocument() const;
825 
835 
846  void SetFieldsInCalculationOrder(const FieldArray& field_array);
847 
860  bool ValidateFieldName(Field::Type type, const WString& field_name);
861 
870  bool RenameField(Field& field, const wchar_t* new_field_name);
871 
918  Control AddControl(const PDFPage& page, const wchar_t* field_name, Field::Type field_type, const RectF& rect);
919 
932  void RemoveField(Field& field);
933 
945  void RemoveControl(Control& control);
946 
959  int GetFieldCount(const wchar_t* filter = NULL) const;
960 
976  Field GetField(int index, const wchar_t* filter = NULL);
977 
985  int GetControlCount(const PDFPage& page) const;
986 
997  Control GetControl(const PDFPage& page, int index);
998 
999 #ifndef _FX_NO_JSE_
1000 
1007  Filler GetFormFiller() const;
1008 #endif
1009 
1015  bool Reset();
1016 
1025  bool ExportToXML(const char* file_path);
1026 
1035  bool ImportFromXML(const char* file_path);
1036 
1043 
1054  void FixPageFields(int page_index);
1055 
1056  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1057  explicit Form(FS_HANDLE handle = NULL);
1058 };
1059 
1075 class Control FS_FINAL : public Base {
1076  public:
1082  Control(const Control& other);
1090  Control& operator = (const Control& other);
1091 
1099  bool operator == (const Control& other) const;
1107  bool operator != (const Control& other) const;
1108 
1110  ~Control();
1111 
1119  bool IsEmpty() const;
1120 
1126  Field GetField() const;
1127 
1134 
1140  annots::Widget GetWidget() const;
1141 
1147  int GetIndex() const;
1148 
1157  WString GetExportValue() const;
1158 
1169  void SetExportValue(const wchar_t* value);
1170 
1179  bool IsChecked() const;
1180 
1191  void SetChecked(bool checked_status);
1192 
1202  bool IsDefaultChecked() const;
1203 
1214  void SetDefaultChecked(bool checked_status);
1215 
1216  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1217  explicit Control(FS_HANDLE handle = NULL);
1218 
1219 };
1220 } // namespace interform
1221 } // namespace pdf
1222 } // namespace foxit
1223 #endif // FS_PDFFORM_H_
1224 
Control GetControl(const PDFPage &page, int index)
Get a form control by index, in a specified PDF page.
void SetChecked(bool checked_status)
Set the check state of current form control when related form field is check box or radio button.
int GetIndex() const
Get the index of current form control among all the controls of related form field.
objects::PDFDictionary * GetWidgetDict() const
Get the dictionary of related widget annotation.
void Set(const wchar_t *option_value, const wchar_t *option_label, bool selected, bool default_selected)
Set value.
Definition: fs_pdfform.h:110
DefaultAppearance GetDefaultAppearance() const
Get the default appearance data.
bool IsEmpty() const
Check whether current object is empty or not.
Filler GetFormFiller() const
Get the form filler.
CFX_Object Object
Object type.
Definition: fs_basictypes.h:219
Header file for form filler related definitions and classes.
common::Alignment GetAlignment() const
Get the alignment value which is used as document-wide default value.
void SetExportValue(const wchar_t *value)
Set export mapping name when related form field is check box or radio button.
bool IsDefaultChecked() const
Check if the current form control is checked by default when related form field is check box or radio...
Header file for FDF doucument related definitions and classes.
bool default_selected
Used to indicate whether the option would be selected by default or not.
Definition: fs_pdfform.h:126
Definition: fs_formfiller.h:160
Control GetControlAtDevicePoint(const PDFPage &page, const PointF &point, float tolerance, Field::Type type, const Matrix *matrix=0)
Get the form control at a specified position, in device coordination system.
bool operator!=(const Control &other) const
Not equal operator.
void SetDefaultChecked(bool checked_status)
Set the default check state of current form control when related form field is check box or radio but...
Definition: fx_coordinates.h:30
ChoiceOption(const wchar_t *option_value, const wchar_t *option_label, bool selected, bool default_selected)
Constructor, with parameters.
Definition: fs_pdfform.h:66
bool operator!=(const Form &other) const
Not equal operator.
Definition: fs_annot.h:51
Definition: fs_annot.h:4367
WIDE STRING CLASS.
Definition: fx_string.h:1459
Form & operator=(const Form &other)
Assign operator.
void SetDefaultAppearance(const DefaultAppearance &default_ap)
Set default appearance data.
Definition: fs_pdfdoc.h:347
Definition: fs_pdfform.h:663
Definition: fs_pdfform.h:1075
bool RenameField(Field &field, const wchar_t *new_field_name)
Rename a field with a new name.
void FixPageFields(int page_index)
Fix the fields which are in a PDF page but cannot be counted by current form object.
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
bool Reset()
Reset data of all fields (except signature fields) to their default value.
Control GetControlAtPoint(const PDFPage &page, const PointF &point, float tolerance, Field::Type type)
Get the form control at a specified position, in PDF coordinate system.
void RemoveField(Field &field)
Remove a form field. (Not support signature field)
void SetFieldsInCalculationOrder(const FieldArray &field_array)
Set an array of form fields in calculation order.
Control & operator=(const Control &other)
Assign operator.
WString GetExportValue() const
Get export mapping name when related form field is check box or radio button.
bool NeedConstructAppearances() const
Check whether to construct appearance when loading form controls.
WString option_value
The option string value.
Definition: fs_pdfform.h:117
ChoiceOption()
Constructor.
Definition: fs_pdfform.h:50
bool IsChecked() const
Check if the current form control is checked when related form field is check box or radio button.
FieldArray GetFieldsInCalculationOrder()
Get an array of form fields in calculation order.
Field GetField() const
Get the related form field.
Definition: fs_pdfform.h:145
bool operator==(const Form &other) const
Equal operator.
bool ImportFromXML(const char *file_path)
Import the form data from an XML file.
FX_UINT32 uint32
32-bit unsigned integer.
Definition: fs_basictypes.h:198
Definition: fs_pdfpage.h:313
void SetConstructAppearances(bool need_construct)
Set a flag that specifies whether to construct appearances when loading form controls.
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:216
bool selected
Used to indicate whether the option is selected or not.
Definition: fs_pdfform.h:123
Header file for common definitions and classes.
void SetAlignment(common::Alignment alignment)
Set alignment value which is used as document-wide default value.
bool IsEmpty() const
Check whether current object is empty or not.
Alignment
Enumeration for alignment (horizontal).
Definition: fs_common.h:293
Header file for PDF object related definitions and classes.
Control AddControl(const PDFPage &page, const wchar_t *field_name, Field::Type field_type, const RectF &rect)
Add a new form control to a specified form field. If the form field does not exist,...
Definition: fs_basictypes.h:375
annots::Widget GetWidget() const
Get the related widget annotation.
Definition: fs_pdfobject.h:763
ChoiceOption(const ChoiceOption &option)
Constructor, with another choice option object.
Definition: fs_pdfform.h:77
bool ExportToXML(const char *file_path)
Export the form data to an XML file.
Foxit namespace.
Definition: fs_compare.h:27
Definition: fs_pdfobject.h:55
Type
Enumeration for form field type.
Definition: fs_pdfform.h:152
WString option_label
The displayed string value for the option.
Definition: fs_pdfform.h:120
Definition: fs_pdfform.h:47
Definition: fs_pdfform.h:44
void RemoveControl(Control &control)
Remove a form control. (Not support to remove a form control from a signature field)
Form(const pdf::PDFDoc &document)
Constructor, with PDF document.
objects::PDFDictionary * GetDict() const
Get the dictionary of current object.
#define NULL
The null-pointer value.
Definition: fx_system.h:771
PDFDoc GetDocument() const
Get the PDF document, with which current form object is associated.
bool operator!=(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are not equal.
Definition: fs_basictypes.h:140
int GetFieldCount(const wchar_t *filter=0) const
Get the count of form fields, whose names satisfy the specified name filter.
Definition: fx_coordinates.h:1056
bool operator==(const Control &other) const
Equal operator.
Control(const Control &other)
Constructor, with another form control object.
Definition: fs_pdfform.h:130
Field GetField(int index, const wchar_t *filter=0)
Get a form field by index, whose names satisfy the specified name filter.
int GetControlCount(const PDFPage &page) const
Get count of form controls in a specified PDF page.
Definition: fx_coordinates.h:766
bool ValidateFieldName(Field::Type type, const WString &field_name)
Validate whether a field name can be used for a new field in specified field type.