Foxit PDF SDK
fs_pdfform.h
浏览该文件的文档.
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 {
182  e_FlagReadOnly = 0x01,
184  e_FlagRequired = 0x02,
186  e_FlagNoExport = 0x04,
192  e_FlagButtonNoToggleToOff = 0x100,
198  e_FlagButtonRadiosInUnison = 0x200,
203  e_FlagTextMultiline = 0x100,
210  e_FlagTextPassword = 0x200,
215  e_FlagTextFileSelect = 0x400,
217  e_FlagTextNoSpellCheck = 0x800,
223  e_FlagTextDoNotScroll = 0x1000,
229  e_FlagTextComb = 0x2000,
234  e_FlagComboEdit = 0x100,
239  e_FlagChoiceMultiSelect = 0x100,
241  e_FlagTextRichText = 0x4000,
243  e_FlagChoiceSort = 0x200,
248  e_FlagChoiceCommitOnSelChange = 0x400
249  } Flags;
250 
251 
258  Field(const PDFDoc& document, objects::PDFDictionary* field_dict);
259 
265  Field(const Field& field);
273  Field& operator = (const Field& other);
274 
282  bool operator == (const Field& other) const;
290  bool operator != (const Field& other) const;
291 
293  ~Field();
294 
302  bool IsEmpty() const;
303 
310  Type GetType() const;
311 
320  uint32 GetFlags() const;
321 
332  void SetFlags(uint32 flags);
333 
339  WString GetName() const;
340 
348  WString GetDefaultValue() const;
349 
360  void SetDefaultValue(const wchar_t* value);
361 
372  WString GetValue() const;
373 
399  void SetValue(const wchar_t* value);
400 
412  common::Alignment GetAlignment() const;
413 
429  void SetAlignment(common::Alignment alignment);
430 
440  WString GetAlternateName() const;
441 
454  void SetAlternateName(const wchar_t* alternate_name);
455 
461  DefaultAppearance GetDefaultAppearance() const;
462 
474  void SetDefaultAppearance(const DefaultAppearance& default_ap);
475 
483  WString GetMappingName() const;
484 
495  void SetMappingName(const wchar_t* name);
496 
504  int GetMaxLength() const;
505 
515  void SetMaxLength(int max_length);
516 
525  ChoiceOptionArray GetOptions() const;
526 
537  void SetOptions(const ChoiceOptionArray& option_array);
538 
548  int GetTopVisibleIndex();
549 
561  void SetTopVisibleIndex(int index);
562 
568  int GetControlCount() const;
569 
578  Control GetControl(int index);
579 
587  int GetControlCount(const foxit::pdf::PDFPage& page) const;
588 
599  Control GetControl(const foxit::pdf::PDFPage& page, int index);
600 
606  bool Reset();
607 
613  objects::PDFDictionary* GetDict() const;
614 
623  objects::PDFObject* GetValueObj() const;
624 
633  objects::PDFObject* GetDefaultValueObj() const;
634 
646  objects::PDFObject* GetInheritedAttribute(const char* attribute_name) const;
647 
648  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
649  explicit Field(FS_HANDLE handle = NULL);
650 };
651 
675 class Form FS_FINAL : public Base {
676  public:
685  explicit Form(const pdf::PDFDoc& document);
691  Form(const Form& other);
699  Form& operator = (const Form& other);
700 
708  bool operator == (const Form& other) const;
716  bool operator != (const Form& other) const;
717 
719  ~Form();
720 
728  bool IsEmpty() const;
729 
742 
757  void SetAlignment(common::Alignment alignment);
758 
764  bool NeedConstructAppearances() const;
765 
774  void SetConstructAppearances(bool need_construct);
775 
794  Control GetControlAtDevicePoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type,
795  const Matrix* matrix = NULL);
796 
811  Control GetControlAtPoint(const PDFPage& page, const PointF& point, float tolerance, Field::Type type);
812 
819 
831  void SetDefaultAppearance(const DefaultAppearance& default_ap);
832 
838  PDFDoc GetDocument() const;
839 
849 
860  void SetFieldsInCalculationOrder(const FieldArray& field_array);
861 
874  bool ValidateFieldName(Field::Type type, const WString& field_name);
875 
884  bool RenameField(Field& field, const wchar_t* new_field_name);
885 
928  Control AddControl(const PDFPage& page, const wchar_t* field_name, Field::Type field_type, const RectF& rect);
929 
948  bool MoveControl(Control& control, const wchar_t* field_name);
949 
962  void RemoveField(Field& field);
963 
974  void RemoveControl(Control& control);
975 
988  int GetFieldCount(const wchar_t* filter = NULL) const;
989 
1005  Field GetField(int index, const wchar_t* filter = NULL);
1006 
1014  int GetControlCount(const PDFPage& page) const;
1015 
1026  Control GetControl(const PDFPage& page, int index);
1027 
1028 #ifndef _FX_NO_JSE_
1029 
1036  Filler GetFormFiller() const;
1037 #endif // #ifndef _FX_NO_JSE_
1038 
1044  bool Reset();
1045 
1054  bool ExportToXML(const char* file_path);
1055 
1068  bool ExportToXML(const wchar_t* file_path, const FieldArray& field_array, bool is_include);
1069 
1083  bool ExportToXML(foxit::common::file::WriterCallback* xml_file, const FieldArray& field_array, bool is_include);
1084 
1093  bool ImportFromXML(const char* file_path);
1094 
1107  bool ExportToCSV(const wchar_t* csv_file_path, const wchar_t* pdf_file_name, bool is_append);
1108 
1121  bool ExportToCSV(foxit::common::file::StreamCallback* csv_file, const wchar_t* pdf_file_name, bool is_append);
1122 
1135  bool ExportToHTML(const wchar_t* html_file_path, const FieldArray& field_array, bool is_include);
1136 
1149  bool ExportToHTML(foxit::common::file::WriterCallback* html_file, const FieldArray& field_array, bool is_include);
1150 
1163  bool ExportToTXT(const wchar_t* txt_file_path, const FieldArray& field_array, bool is_include);
1164 
1177  bool ExportToTXT(foxit::common::file::WriterCallback* txt_file, const FieldArray& field_array, bool is_include);
1178 
1185 
1196  void FixPageFields(int page_index);
1197 
1198  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1199  explicit Form(FS_HANDLE handle = NULL);
1200 };
1201 
1217 class Control FS_FINAL : public Base {
1218  public:
1224  Control(const Control& other);
1232  Control& operator = (const Control& other);
1233 
1241  bool operator == (const Control& other) const;
1249  bool operator != (const Control& other) const;
1250 
1252  ~Control();
1253 
1261  bool IsEmpty() const;
1262 
1268  Field GetField() const;
1269 
1276 
1282  annots::Widget GetWidget() const;
1283 
1289  int GetIndex() const;
1290 
1299  WString GetExportValue() const;
1300 
1311  void SetExportValue(const wchar_t* value);
1312 
1321  bool IsChecked() const;
1322 
1333  void SetChecked(bool checked_status);
1334 
1343  bool IsDefaultChecked() const;
1344 
1355  void SetDefaultChecked(bool checked_status);
1356 
1363 
1375  void SetDefaultAppearance(const DefaultAppearance& default_ap);
1376 
1390 
1406  void SetAlignment(common::Alignment alignment);
1407 
1408  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1409  explicit Control(FS_HANDLE handle = NULL);
1410 
1411 };
1412 } // namespace interform
1413 } // namespace pdf
1414 } // namespace foxit
1415 #endif // FS_PDFFORM_H_
1416 
Control GetControl(const PDFPage &page, int index)
在指定PDF页面中通过索引获取表单控件。
void SetChecked(bool checked_status)
当相关表单字段是复选框或单选按钮时,设置当前表单控件的选中状态。
int GetIndex() const
获取当前表单控件在相关表单字段的所有控件中的索引。
objects::PDFDictionary * GetWidgetDict() const
获取相关控件注释的字典。
void Set(const wchar_t *option_value, const wchar_t *option_label, bool selected, bool default_selected)
设置值。
Definition: fs_pdfform.h:110
文件写入接口。
Definition: fx_stream.h:470
DefaultAppearance GetDefaultAppearance() const
获取默认外观数据。
bool IsEmpty() const
检查当前对象是否为空。
bool ExportToHTML(const wchar_t *html_file_path, const FieldArray &field_array, bool is_include)
将指定表单字段的数据导出到HTML文件。
Filler GetFormFiller() const
获取表单填写器。
CFX_Object Object
对象类型。
Definition: fs_basictypes.h:221
表单填充器相关定义和类的头文件。
common::Alignment GetAlignment() const
获取用作文档范围默认值的对齐值。
void SetExportValue(const wchar_t *value)
当相关表单字段是复选框或单选按钮时,设置导出映射名称。
bool IsDefaultChecked() const
检查当相关表单字段是复选框或单选按钮时,当前表单控件是否默认被选中。
FDF文档相关定义和类的头文件。
bool default_selected
用于指示选项是否默认被选择。
Definition: fs_pdfform.h:126
Definition: fs_formfiller.h:271
Control GetControlAtDevicePoint(const PDFPage &page, const PointF &point, float tolerance, Field::Type type, const Matrix *matrix=0)
在设备坐标系统中的指定位置获取表单控件。
void SetDefaultChecked(bool checked_status)
当相关表单字段是复选框或单选按钮时,设置当前表单控件的默认选中状态。
Definition: fx_coordinates.h:30
ChoiceOption(const wchar_t *option_value, const wchar_t *option_label, bool selected, bool default_selected)
带参数的构造函数。
Definition: fs_pdfform.h:66
Definition: fs_annot.h:50
Definition: fs_annot.h:5011
宽字符串类
Definition: fx_string.h:1457
Form & operator=(const Form &other)
赋值操作符。
void SetDefaultAppearance(const DefaultAppearance &default_ap)
设置默认外观数据。
Definition: fs_pdfdoc.h:771
Definition: fs_pdfform.h:675
Definition: fs_pdfform.h:1217
bool RenameField(Field &field, const wchar_t *new_field_name)
用新名称重命名字段。
void FixPageFields(int page_index)
修复在PDF页面中但无法被当前表单对象计数的字段。
bool operator==(const char *str1, const CFX_ByteString &str2)
检查两个字节字符串是否相等。
Definition: fs_basictypes.h:128
bool Reset()
将所有字段(签名字段除外)的数据重置为其默认值。
Control GetControlAtPoint(const PDFPage &page, const PointF &point, float tolerance, Field::Type type)
在PDF坐标系统中的指定位置获取表单控件。
void SetDefaultAppearance(const DefaultAppearance &default_ap)
设置默认外观数据。
void RemoveField(Field &field)
删除表单字段。(不支持签名字段)
void SetFieldsInCalculationOrder(const FieldArray &field_array)
设置按计算顺序排列的表单字段数组。
Control & operator=(const Control &other)
赋值操作符。
WString GetExportValue() const
当相关表单字段是复选框或单选按钮时,获取导出映射名称。
文件流接口,用于读取和写入。
Definition: fx_stream.h:692
bool NeedConstructAppearances() const
检查加载表单控件时是否构造外观。
WString option_value
选项字符串值。
Definition: fs_pdfform.h:117
ChoiceOption()
构造函数
Definition: fs_pdfform.h:50
bool operator !=(const Form &other) const
不等于操作符。
bool IsChecked() const
检查当相关表单字段是复选框或单选按钮时,当前表单控件是否被选中。
FieldArray GetFieldsInCalculationOrder()
获取按计算顺序排列的表单字段数组。
Field GetField() const
获取相关的表单字段。
Definition: fs_pdfform.h:145
bool operator==(const Form &other) const
等于操作符。
bool ImportFromXML(const char *file_path)
从XML文件导入表单数据。
FX_UINT32 uint32
无符号 32 位整数。
Definition: fs_basictypes.h:196
Definition: fs_pdfpage.h:421
void SetConstructAppearances(bool need_construct)
设置指定加载表单控件时是否构造外观的标志。
void * FS_HANDLE
句柄类型。
Definition: fs_basictypes.h:214
bool selected
用于指示选项是否被选择。
Definition: fs_pdfform.h:123
通用定义和类的头文件。
void SetAlignment(common::Alignment alignment)
设置用作文档范围默认值的对齐值。
bool IsEmpty() const
检查当前对象是否为空。
bool ExportToCSV(const wchar_t *csv_file_path, const wchar_t *pdf_file_name, bool is_append)
将表单数据导出到CSV文件。
Alignment
对齐方式(水平)枚举。
Definition: fs_common.h:94
PDF对象相关定义和类的头文件。
Control AddControl(const PDFPage &page, const wchar_t *field_name, Field::Type field_type, const RectF &rect)
向指定表单字段添加新的表单控件。如果表单字段不存在,此函数也将 添加表单字段。(不支持签名字段)
Definition: fs_basictypes.h:449
DefaultAppearance GetDefaultAppearance() const
获取默认外观数据。
annots::Widget GetWidget() const
获取相关的控件注释。
bool operator !=(const Control &other) const
不等于操作符。
Definition: fs_pdfobject.h:848
ChoiceOption(const ChoiceOption &option)
复制构造函数。
Definition: fs_pdfform.h:77
bool ExportToXML(const char *file_path)
将表单数据导出到XML文件。
Foxit命名空间。
Definition: fs_taggedpdf.h:27
Definition: fs_pdfobject.h:55
Type
表单字段类型的枚举。
Definition: fs_pdfform.h:152
WString option_label
选项的显示字符串值。
Definition: fs_pdfform.h:120
Definition: fs_pdfform.h:47
Definition: fs_pdfform.h:44
common::Alignment GetAlignment()
获取对齐值。
void RemoveControl(Control &control)
删除表单控件。(不支持从签名字段删除表单控件)
Form(const pdf::PDFDoc &document)
构造函数,使用PDF文档。
objects::PDFDictionary * GetDict() const
获取当前对象的字典。
#define NULL
空指针值。
Definition: fx_system.h:792
PDFDoc GetDocument() const
获取与当前表单对象关联的PDF文档。
int GetFieldCount(const wchar_t *filter=0) const
获取名称满足指定名称过滤器的表单字段数量。
bool ExportToTXT(const wchar_t *txt_file_path, const FieldArray &field_array, bool is_include)
将指定表单字段的数据导出到TXT文件。
Definition: fx_coordinates.h:1076
bool operator==(const Control &other) const
等于操作符。
Control(const Control &other)
构造函数,使用另一个表单控件对象。
bool MoveControl(Control &control, const wchar_t *field_name)
将控件移动到由字段名称指定的字段。
Definition: fs_pdfform.h:130
Field GetField(int index, const wchar_t *filter=0)
通过索引获取名称满足指定名称过滤器的表单字段。
void SetAlignment(common::Alignment alignment)
设置当前表单控件的对齐属性。
int GetControlCount(const PDFPage &page) const
获取指定PDF页面中的表单控件数量。
Definition: fx_coordinates.h:771
bool ValidateFieldName(Field::Type type, const WString &field_name)
验证字段名称是否可用于指定字段类型的新字段。