Form.h
1 #pragma once
2 // Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved.
3 
4 // C# preprocessor directive: #if !NETCORE
5 
6 
7 // C# preprocessor directive: #endif
8 
9 
10 #include <system/enum_helpers.h>
11 #include <system/array.h>
12 #include <cstdint>
13 
14 #include "Aspose.PDF.Cpp/Facades/Facade.h"
15 #include "Aspose.PDF.Cpp/aspose_pdf_api_defs.h"
16 
17 namespace Aspose
18 {
19 namespace Pdf
20 {
21 namespace Annotations
22 {
23 class WidgetAnnotation;
24 } // namespace Annotations
25 namespace Collections
26 {
27 template <typename, typename> class AsposeHashDictionary;
28 } // namespace Collections
29 enum class ContentDisposition;
30 class Document;
31 namespace Engine
32 {
33 namespace CommonData
34 {
35 class ITreeNode;
36 } // namespace CommonData
37 namespace Data
38 {
39 class IPdfArray;
40 class IPdfDictionary;
41 class IPdfNumber;
42 class IPdfObject;
43 class ITrailerable;
44 } // namespace Data
45 } // namespace Engine
46 namespace Facades
47 {
48 enum class FieldType;
49 class Form;
50 class FormEditor;
51 class FormFieldFacade;
52 enum class PropertyFlag;
53 enum class SubmitFormFlag;
54 } // namespace Facades
55 namespace Forms
56 {
57 class ChoiceField;
58 class Field;
59 class OptionCollection;
60 } // namespace Forms
61 class Operator;
62 class OperatorCollection;
63 enum class PdfFormat;
64 class SaveOptions;
65 namespace Tests
66 {
67 namespace OriginalKit
68 {
69 namespace New
70 {
71 class RegressionTests_v4_8;
72 } // namespace New
73 } // namespace OriginalKit
74 } // namespace Tests
75 } // namespace Pdf
76 } // namespace Aspose
77 namespace System
78 {
79 namespace Collections
80 {
81 namespace Generic
82 {
83 template <typename, typename> class Dictionary;
84 template <typename> class ICollection;
85 template <typename> class List;
86 } // namespace Generic
87 } // namespace Collections
88 namespace IO
89 {
90 class Stream;
91 } // namespace IO
92 namespace Web
93 {
94 class HttpResponse;
95 } // namespace Web
96 namespace Xml
97 {
98 class XmlDocument;
99 class XmlNamespaceManager;
100 class XmlNode;
101 class XmlNodeList;
102 class XmlTextWriter;
103 } // namespace Xml
104 } // namespace System
105 
106 namespace Aspose {
107 
108 namespace Pdf {
109 
110 namespace Facades {
111 
115 class ASPOSE_PDF_SHARED_CLASS Form final : public Aspose::Pdf::Facades::SaveableFacade
116 {
117  typedef Form ThisType;
119 
120  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
121  ASPOSE_PDF_SHARED_RTTI_INFO_DECL();
122 
124  friend class Aspose::Pdf::Tests::OriginalKit::New::RegressionTests_v4_8;
125 
126 public:
127 
131  enum class ImportStatus
132  {
136  Success,
140  FieldNotFound
141  };
142 
143 
144 public:
145 
149  class ASPOSE_PDF_SHARED_CLASS FormImportResult : public System::Object
150  {
151  typedef FormImportResult ThisType;
152  typedef System::Object BaseType;
153 
154  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
155  ASPOSE_PDF_SHARED_RTTI_INFO_DECL();
156 
158 
159  public:
160 
164  ASPOSE_PDF_SHARED_API Form::ImportStatus get_Status() const;
168  ASPOSE_PDF_SHARED_API System::String get_FieldName() const;
169 
170  protected:
171 
173 
174  MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(FormImportResult, CODEPORTING_ARGS(System::String fieldName, Form::ImportStatus status));
175 
176  private:
177 
178  Form::ImportStatus _status;
179  System::String _fieldName;
180 
181  };
182 
183 
184 public:
185 
196  ASPOSE_PDF_SHARED_API System::String get_SrcFileName() const;
203  ASPOSE_PDF_SHARED_API void set_SrcFileName(System::String value);
208  ASPOSE_PDF_SHARED_API void set_ConvertTo(PdfFormat value);
215  ASPOSE_PDF_SHARED_API System::String get_DestFileName() const;
222  ASPOSE_PDF_SHARED_API void set_DestFileName(System::String value);
229  ASPOSE_PDF_SHARED_API System::SharedPtr<System::IO::Stream> get_SrcStream() const;
236  ASPOSE_PDF_SHARED_API void set_SrcStream(System::SharedPtr<System::IO::Stream> value);
243  ASPOSE_PDF_SHARED_API System::SharedPtr<System::IO::Stream> get_DestStream() const;
250  ASPOSE_PDF_SHARED_API void set_DestStream(System::SharedPtr<System::IO::Stream> value);
256  ASPOSE_PDF_SHARED_API System::ArrayPtr<System::String> get_FieldNames();
267  ASPOSE_PDF_SHARED_API Aspose::Pdf::ContentDisposition get_ContentDisposition() const;
272  ASPOSE_PDF_SHARED_API void set_ContentDisposition(Aspose::Pdf::ContentDisposition value);
276  ASPOSE_PDF_SHARED_API System::SharedPtr<System::Web::HttpResponse> get_Response() const;
280  ASPOSE_PDF_SHARED_API void set_Response(System::SharedPtr<System::Web::HttpResponse> value);
285  ASPOSE_PDF_SHARED_API System::SharedPtr<Aspose::Pdf::SaveOptions> get_SaveOptions() const;
290  ASPOSE_PDF_SHARED_API void set_SaveOptions(System::SharedPtr<Aspose::Pdf::SaveOptions> value);
294  ASPOSE_PDF_SHARED_API System::String get_AttachmentName() const;
298  ASPOSE_PDF_SHARED_API void set_AttachmentName(System::String value);
299 
307  ASPOSE_PDF_SHARED_API System::SharedPtr<FormFieldFacade> GetFieldFacade(System::String fieldName);
308 
318  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<System::IO::Stream> srcStream, System::SharedPtr<System::IO::Stream> destStream);
324  ASPOSE_PDF_SHARED_API Form();
325 
340  ASPOSE_PDF_SHARED_API bool FillField(System::String fieldName, System::String fieldValue);
372  ASPOSE_PDF_SHARED_API bool FillField(System::String fieldName, int32_t index);
386  ASPOSE_PDF_SHARED_API bool FillField(System::String fieldName, bool beChecked);
407  ASPOSE_PDF_SHARED_API System::String GetButtonOptionCurrentValue(System::String fieldName);
424  ASPOSE_PDF_SHARED_API System::String GetField(System::String fieldName);
432  ASPOSE_PDF_SHARED_API System::String GetFullFieldName(System::String fieldName);
440  ASPOSE_PDF_SHARED_API int32_t GetFieldLimit(System::String fieldName);
447  ASPOSE_PDF_SHARED_API void Save();
452  ASPOSE_PDF_SHARED_API void Save(System::String destFile) override;
457  ASPOSE_PDF_SHARED_API void Save(System::SharedPtr<System::IO::Stream> destStream) override;
461  ASPOSE_PDF_SHARED_API void Close() override;
467  ASPOSE_PDF_SHARED_API void FlattenAllFields();
476  ASPOSE_PDF_SHARED_API void FlattenField(System::String fieldName);
485  ASPOSE_PDF_SHARED_API bool FillBarcodeField(System::String fieldName, System::String data);
492  ASPOSE_PDF_SHARED_API void ImportFdf(System::SharedPtr<System::IO::Stream> inputFdfStream);
499  ASPOSE_PDF_SHARED_API void ExportFdf(System::SharedPtr<System::IO::Stream> outputFdfStream);
506  ASPOSE_PDF_SHARED_API void ImportXml(System::SharedPtr<System::IO::Stream> inputXmlStream);
514  ASPOSE_PDF_SHARED_API void ExportXml(System::SharedPtr<System::IO::Stream> outputXmlStream);
519  ASPOSE_PDF_SHARED_API void ExtractXfaData(System::SharedPtr<System::IO::Stream> outputXmlStream);
524  ASPOSE_PDF_SHARED_API void SetXfaData(System::SharedPtr<System::IO::Stream> inputXmlStream);
531  ASPOSE_PDF_SHARED_API void ImportXfdf(System::SharedPtr<System::IO::Stream> inputXfdfStream);
539  ASPOSE_PDF_SHARED_API void ExportXfdf(System::SharedPtr<System::IO::Stream> outputXfdfStream);
547  ASPOSE_PDF_SHARED_API void FillField(System::String fieldName, System::ArrayPtr<System::String> fieldValues);
556  ASPOSE_PDF_SHARED_API void RenameField(System::String fieldName, System::String newFieldName);
564  ASPOSE_PDF_SHARED_API System::String GetRichText(System::String fieldName);
572  ASPOSE_PDF_SHARED_API SubmitFormFlag GetSubmitFlags(System::String fieldName);
573 
580  ASPOSE_PDF_SHARED_API Form(System::String srcFileName);
587  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<System::IO::Stream> srcStream);
597  ASPOSE_PDF_SHARED_API Form(System::String srcFileName, System::String destFileName);
606  ASPOSE_PDF_SHARED_API Form(System::String srcFileName, System::SharedPtr<System::IO::Stream> destStream);
615  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<System::IO::Stream> srcStream, System::String destFileName);
616 
624  ASPOSE_PDF_SHARED_API FieldType GetFieldType(System::String fieldName);
630  ASPOSE_PDF_SHARED_API bool IsRequiredField(System::String fieldName);
638  ASPOSE_PDF_SHARED_API PropertyFlag GetFieldFlag(System::String fieldName);
647  ASPOSE_PDF_SHARED_API void FillImageField(System::String fieldName, System::String imageFileName);
656  ASPOSE_PDF_SHARED_API void FillImageField(System::String fieldName, System::SharedPtr<System::IO::Stream> imageStream);
657 
664  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<Aspose::Pdf::Document> document);
675  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<Aspose::Pdf::Document> document, System::String destFileName);
686  ASPOSE_PDF_SHARED_API Form(System::SharedPtr<Aspose::Pdf::Document> document, System::SharedPtr<System::IO::Stream> destStream);
687 
693  ASPOSE_PDF_SHARED_API void ImportXml(System::SharedPtr<System::IO::Stream> inputXmlStream, bool IgnoreFormTemplateChanges);
701  ASPOSE_PDF_SHARED_API bool FillField(System::String fieldName, System::String value, bool fitFontSize);
702 
716  ASPOSE_PDF_SHARED_API Form(System::String inputFile, System::SharedPtr<System::Web::HttpResponse> response);
717 
718 protected:
719 
725  ASPOSE_PDF_SHARED_API void BindPdf(System::SharedPtr<System::IO::Stream> srcStream, System::String password) override;
731  ASPOSE_PDF_SHARED_API void BindPdf(System::String srcFile, System::String password) override;
735 
736 private:
737 
740  bool _closeStream;
741  bool _formChanged;
742  System::String sourceFileName;
743  System::String destFileName;
744  PdfFormat _convertTo;
745  bool _executeConvert;
746  Aspose::Pdf::ContentDisposition _contentDisposition;
748  System::String _attachmentName;
751 
752  bool IsIncrementalUpdates();
753  void CloseSource();
754  void CloseDest();
755  System::String RemoveLines(System::String s);
771  void ReadFieldsFromTeamplate(System::SharedPtr<System::Xml::XmlTextWriter> writer);
772  bool IsDataPacketEmpty(System::SharedPtr<Aspose::Pdf::Document> doc);
773  void UpdateStaticFormAfterXfaReplace();
781  int32_t findPage(System::SharedPtr<Aspose::Pdf::Forms::Field> field);
786  bool isSingleCheckbox(System::SharedPtr<Aspose::Pdf::Forms::Field> field);
789  bool hasChildFields(System::SharedPtr<System::Xml::XmlNode> node);
794  bool IsXfaFieldMultiline(System::String path);
816  System::SharedPtr<Aspose::Pdf::Engine::Data::IPdfDictionary> GetStructParentElement(int32_t index);
822  System::SharedPtr<Aspose::Pdf::Engine::Data::IPdfNumber> GetElementMcid(int32_t structParentIndex);
831 
832 };
833 
834 } // namespace Facades
835 } // namespace Pdf
836 } // namespace Aspose
837 
838 
ASPOSE_PDF_SHARED_API void RenameField(System::String fieldName, System::String newFieldName)
Renames a field. Either AcroForm field or XFA field is OK.
String class used across the library. Is a substitute for C# System.String when translating code...
Definition: string.h:121
static bool IsImageField(System::SharedPtr< Aspose::Pdf::Annotations::WidgetAnnotation > annotation)
ASPOSE_PDF_SHARED_API void BindPdf(System::SharedPtr< System::IO::Stream > srcStream, System::String password) override
Initializes the facade.
ASPOSE_PDF_SHARED_API void ImportFdf(System::SharedPtr< System::IO::Stream > inputFdfStream)
Imports the content of the fields from the fdf file and put them into the new pdf.
ASPOSE_PDF_SHARED_API void set_SrcFileName(System::String value)
Sets source file name.
Base class for all saveable facades.
Definition: Facade.h:151
ASPOSE_PDF_SHARED_API void SetXfaData(System::SharedPtr< System::IO::Stream > inputXmlStream)
Replaces XFA data with specified data packet. Data packet may be extracted using ExtractXfaData.
ASPOSE_PDF_SHARED_API Aspose::Pdf::ContentDisposition get_ContentDisposition() const
Gets how content will be stored when result of operation is stored into HttpResponse object...
ASPOSE_PDF_SHARED_API System::ArrayPtr< System::SharedPtr< Form::FormImportResult > > get_ImportResult()
Result of last import operation. Array of objects which descibre result of import for each field...
Class representing Acro form object.
Definition: Form.h:115
PropertyFlag
Enumeration of possible field flags.
Definition: PropertyFlag.h:13
ASPOSE_PDF_SHARED_API void ExportXml(System::SharedPtr< System::IO::Stream > outputXmlStream)
Exports the content of the fields of the pdf into the xml stream. The button field&#39;s value will not b...
ImportStatus
Status of imported field
Definition: Form.h:131
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:64
ASPOSE_PDF_SHARED_API bool FillField(System::String fieldName, System::String fieldValue)
Fills the field with a valid value according to a fully qualified field name. Before filling the fiel...
Definition: Artifact.h:67
ASPOSE_PDF_SHARED_API void set_AttachmentName(System::String value)
Sets name of attachment when result of operation is stored into HttpResponse objects as attachment...
Base facade class.
Definition: Facade.h:57
ASPOSE_PDF_SHARED_API void ImportXml(System::SharedPtr< System::IO::Stream > inputXmlStream)
Imports the content of the fields from the xml file and put them into the new pdf.
System::SharedPtr< System::Xml::XmlNode > GetFieldTemplate(System::String fieldName)
ASPOSE_PDF_SHARED_API SubmitFormFlag GetSubmitFlags(System::String fieldName)
Returns the submit button&#39;s submission flags
ASPOSE_PDF_SHARED_API System::SharedPtr< Aspose::Pdf::SaveOptions > get_SaveOptions() const
Gets save options when result is stored as HttpResponse. Default value: PdfSaveOptions.
ASPOSE_PDF_SHARED_API void ExportFdf(System::SharedPtr< System::IO::Stream > outputFdfStream)
Exports the content of the fields of the pdf into the fdf stream.
PdfFormat
This class represents an pdf format.
Definition: PdfFormat.h:16
ASPOSE_PDF_SHARED_API System::String get_AttachmentName() const
Gets name of attachment when result of operation is stored into HttpResponse objects as attachment...
ASPOSE_PDF_SHARED_API System::String get_SrcFileName() const
Gets source file name.
ASPOSE_PDF_SHARED_API System::String GetButtonOptionCurrentValue(System::String fieldName)
Returns the current value for radio button option fields.
ASPOSE_PDF_SHARED_API bool IsRequiredField(System::String fieldName)
Determines whether field is required or not.
ASPOSE_PDF_SHARED_API void set_SrcStream(System::SharedPtr< System::IO::Stream > value)
Sets source stream.
Definition: signed_info.h:13
ASPOSE_PDF_SHARED_API System::String GetField(System::String fieldName)
Gets the field&#39;s value according to its field name.
ASPOSE_PDF_SHARED_API void set_Response(System::SharedPtr< System::Web::HttpResponse > value)
Sets Response object where result of operation will be stored.
ASPOSE_PDF_SHARED_API void FlattenField(System::String fieldName)
Flattens a specified field with the fully qualified field name. Any other field will remain unchangab...
ASPOSE_PDF_SHARED_API System::SharedPtr< System::IO::Stream > get_SrcStream() const
Gets source stream.
Specifies that the member is a field.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: fwd.h:22
ASPOSE_PDF_SHARED_API System::SharedPtr< System::Collections::Generic::Dictionary< System::String, System::String > > GetButtonOptionValues(System::String fieldName)
Gets the radio button option fields and related values based on the field name. This method has meani...
ASPOSE_PDF_SHARED_API Form()
Construtcor of Form without parameters.
ASPOSE_PDF_SHARED_API void FlattenAllFields()
Flattens all the fields.
General facade interface that defines common facades methods.
Definition: IFacade.h:33
ASPOSE_PDF_SHARED_API bool FillBarcodeField(System::String fieldName, System::String data)
Fill a barcode field according to its fully qualified field name.
ASPOSE_PDF_SHARED_API FieldType GetFieldType(System::String fieldName)
Returns type of field.
Definition: AFRelationship.h:4
SubmitFormFlag
Enumeration of possible submit form flags.
Definition: SubmitFormFlag.h:15
ASPOSE_PDF_SHARED_API System::SharedPtr< System::IO::Stream > get_DestStream() const
Gets destination stream.
Class which describes result if field import.
Definition: Form.h:149
ASPOSE_PDF_SHARED_API void ExtractXfaData(System::SharedPtr< System::IO::Stream > outputXmlStream)
Extracts XFA data packet
ASPOSE_PDF_SHARED_API System::String GetRichText(System::String fieldName)
Get a Rich Text field&#39;s value, including the formattinf information of every character.
FieldType
Enumeration of possible field types.
Definition: FieldType.h:18
ASPOSE_PDF_SHARED_API void Close() override
Closes opened files without any changes.
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: Form.h:84
ASPOSE_PDF_SHARED_API void set_ContentDisposition(Aspose::Pdf::ContentDisposition value)
Sets how content will be stored when result of operation is stored into HttpResponse object...
List forward declaration.
Definition: Artifact.h:74
ASPOSE_PDF_SHARED_API void set_SaveOptions(System::SharedPtr< Aspose::Pdf::SaveOptions > value)
Sets save options when result is stored as HttpResponse. Default value: PdfSaveOptions.
ASPOSE_PDF_SHARED_API int32_t GetFieldLimit(System::String fieldName)
Get the limitation of text field.
ASPOSE_PDF_SHARED_API bool FillFields(System::ArrayPtr< System::String > fieldNames, System::ArrayPtr< System::String > fieldValues, System::SharedPtr< System::IO::Stream > &output)
Fills the text box fields with a text values and save the document. Relevant for signed documents...
ASPOSE_PDF_SHARED_API void FillImageField(System::String fieldName, System::String imageFileName)
Pastes an image onto the existing button field as its appearance according to its fully qualified fie...
ASPOSE_PDF_SHARED_API System::SharedPtr< System::Web::HttpResponse > get_Response() const
Gets Response object where result of operation will be stored.
ASPOSE_PDF_SHARED_API void set_DestStream(System::SharedPtr< System::IO::Stream > value)
Sets destination stream.
ASPOSE_PDF_SHARED_API void set_ConvertTo(PdfFormat value)
Sets PDF file format. Result file will be saved in specified file format. If this property is not spe...
ContentDisposition
MIME protocol Content-Disposition header.
Definition: ContentDisposition.h:11
ASPOSE_PDF_SHARED_API System::String get_DestFileName() const
Gets destiination file name.
ASPOSE_PDF_SHARED_API System::SharedPtr< FormFieldFacade > GetFieldFacade(System::String fieldName)
Returns FrofmFieldFacade object containing all appearance attributes.
ASPOSE_PDF_SHARED_API System::ArrayPtr< System::String > get_FormSubmitButtonNames()
Gets all form submit button names.
ASPOSE_PDF_SHARED_API System::ArrayPtr< System::String > get_FieldNames()
Gets list of field names on the form.
ASPOSE_PDF_SHARED_API System::String GetFullFieldName(System::String fieldName)
Gets the full field name according to its short field name.
ASPOSE_PDF_SHARED_API PropertyFlag GetFieldFlag(System::String fieldName)
Returns flags of the field.
ASPOSE_PDF_SHARED_API void ExportXfdf(System::SharedPtr< System::IO::Stream > outputXfdfStream)
Exports the content of the fields of the pdf into the xml stream. The button field&#39;s value will not b...
ASPOSE_PDF_SHARED_API void set_DestFileName(System::String value)
Sets destiination file name.
ASPOSE_PDF_SHARED_API void ImportXfdf(System::SharedPtr< System::IO::Stream > inputXfdfStream)
Imports the content of the fields from the xfdf(xml) file and put them into the new pdf...
static FieldType getFieldType(System::SharedPtr< Aspose::Pdf::Annotations::WidgetAnnotation > annotation)
Class for editing forms (ading/deleting field etc)
Definition: FormEditor.h:73
ASPOSE_PDF_SHARED_API void Save()
Saves the value of the filled fields and close the opened Pdf document.
Whole PDF file will be submitted.