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_FlagChoiceMultiSelect = 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 
465  void SetDefaultAppearance(const DefaultAppearance& default_ap);
466 
474  WString GetMappingName() const;
475 
486  void SetMappingName(const wchar_t* name);
487 
495  int GetMaxLength() const;
496 
506  void SetMaxLength(int max_length);
507 
516  ChoiceOptionArray GetOptions() const;
517 
528  void SetOptions(const ChoiceOptionArray& option_array);
529 
539  int GetTopVisibleIndex();
540 
552  void SetTopVisibleIndex(int index);
553 
559  int GetControlCount() const;
560 
569  Control GetControl(int index);
570 
578  int GetControlCount(const foxit::pdf::PDFPage& page) const;
579 
590  Control GetControl(const foxit::pdf::PDFPage& page, int index);
591 
597  bool Reset();
598 
604  objects::PDFDictionary* GetDict() const;
613  objects::PDFObject* GetValueObj() const;
614 
623  objects::PDFObject* GetDefaultValueObj() const;
634  objects::PDFObject* GetInheritedAttribute(const char* attribute_name) const;
635 
636  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
637  explicit Field(FS_HANDLE handle = NULL);
638 };
639 
665 class Form FS_FINAL : public Base {
666  public:
675  explicit Form(const pdf::PDFDoc& document);
681  Form(const Form& other);
689  Form& operator = (const Form& other);
690 
698  bool operator == (const Form& other) const;
706  bool operator != (const Form& other) const;
707 
709  ~Form();
710 
718  bool IsEmpty() const;
719 
732 
747  void SetAlignment(common::Alignment alignment);
748 
754  bool NeedConstructAppearances() const;
755 
764  void SetConstructAppearances(bool need_construct);
765 
784  Control GetControlAtDevicePoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type,
785  const Matrix* matrix = NULL);
786 
801  Control GetControlAtPoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type);
802 
809 
821  void SetDefaultAppearance(const DefaultAppearance& default_ap);
822 
828  PDFDoc GetDocument() const;
829 
839 
850  void SetFieldsInCalculationOrder(const FieldArray& field_array);
851 
864  bool ValidateFieldName(Field::Type type, const WString& field_name);
865 
874  bool RenameField(Field& field, const wchar_t* new_field_name);
875 
922  Control AddControl(const PDFPage& page, const wchar_t* field_name, Field::Type field_type, const RectF& rect);
923 
946  bool MoveControl(Control& control, const wchar_t* field_name);
947 
960  void RemoveField(Field& field);
961 
973  void RemoveControl(Control& control);
974 
987  int GetFieldCount(const wchar_t* filter = NULL) const;
988 
1004  Field GetField(int index, const wchar_t* filter = NULL);
1005 
1013  int GetControlCount(const PDFPage& page) const;
1014 
1025  Control GetControl(const PDFPage& page, int index);
1026 
1027 #ifndef _FX_NO_JSE_
1028 
1035  Filler GetFormFiller() const;
1036 #endif
1037 
1043  bool Reset();
1044 
1053  bool ExportToXML(const char* file_path);
1054 
1063  bool ImportFromXML(const char* file_path);
1064 
1071 
1082  void FixPageFields(int page_index);
1083 
1084  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1085  explicit Form(FS_HANDLE handle = NULL);
1086 };
1087 
1103 class Control FS_FINAL : public Base {
1104  public:
1110  Control(const Control& other);
1118  Control& operator = (const Control& other);
1119 
1127  bool operator == (const Control& other) const;
1135  bool operator != (const Control& other) const;
1136 
1138  ~Control();
1139 
1147  bool IsEmpty() const;
1148 
1154  Field GetField() const;
1155 
1162 
1168  annots::Widget GetWidget() const;
1169 
1175  int GetIndex() const;
1176 
1185  WString GetExportValue() const;
1186 
1197  void SetExportValue(const wchar_t* value);
1198 
1207  bool IsChecked() const;
1208 
1219  void SetChecked(bool checked_status);
1220 
1230  bool IsDefaultChecked() const;
1231 
1242  void SetDefaultChecked(bool checked_status);
1243 
1250 
1262  void SetDefaultAppearance(const DefaultAppearance& default_ap);
1263 
1264  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1265  explicit Control(FS_HANDLE handle = NULL);
1266 
1267 };
1268 } // namespace interform
1269 } // namespace pdf
1270 } // namespace foxit
1271 #endif // FS_PDFFORM_H_
1272 
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:217
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.
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
Definition: fs_annot.h:51
Definition: fs_annot.h:4761
WIDE STRING CLASS.
Definition: fx_string.h:1452
Form & operator=(const Form &other)
Assign operator.
void SetDefaultAppearance(const DefaultAppearance &default_ap)
Set default appearance data.
Definition: fs_pdfdoc.h:389
Definition: fs_pdfform.h:665
Definition: fs_pdfform.h:1103
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 SetDefaultAppearance(const DefaultAppearance &default_ap)
Set default appearance data.
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 operator !=(const Form &other) const
Not equal operator.
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:196
Definition: fs_pdfpage.h:367
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:214
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:74
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:397
DefaultAppearance GetDefaultAppearance() const
Get the default appearance data.
annots::Widget GetWidget() const
Get the related widget annotation.
bool operator !=(const Control &other) const
Not equal operator.
Definition: fs_pdfobject.h:785
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:767
PDFDoc GetDocument() const
Get the PDF document, with which current form object is associated.
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:1076
bool operator==(const Control &other) const
Equal operator.
Control(const Control &other)
Constructor, with another form control object.
bool MoveControl(Control &control, const wchar_t *field_name)
Move the control to a field specified by field name.
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:771
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.