PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
form_field.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_PDF_FORM_FIELD_H_INCLUDED_
4#define PDFSDK_CXX_PDF_FORM_FIELD_H_INCLUDED_
5
6#include <string>
7#include <vector>
8
10#include <pdfsdk/cxx/bytes.h>
11
12#include "forward_declarations.h"
13#include "ltv_handler.h"
14#include "timestamp_handler.h"
15#include "wrapper_base.h"
16
17namespace PDF {
18
20enum class SigChainStatus {
21 Ok,
22 Untrusted,
23 Incomplete,
24 Expired,
25 Error
26};
27
29enum class SigRevocationStatus {
30 Good,
31 Revoked,
32 Unknown,
33 Error
34};
35
37enum class SigTimeSource {
38 DocTimestamp,
39 ClaimedM,
40 None
41};
42
50 std::vector<std::vector<Byte>> trustAnchors;
51 bool requireRevocation = true;
52};
53
58 bool integrityValid = false;
59 bool documentCovered = false;
60 SigChainStatus chain = SigChainStatus::Error;
61 SigRevocationStatus revocation = SigRevocationStatus::Unknown;
62 SigTimeSource timeSource = SigTimeSource::None;
63 PDDateTime referenceTime = {};
64 bool ltvEnabled = false;
65
67 bool IsValidLTV() const {
69 chain == SigChainStatus::Ok &&
70 revocation == SigRevocationStatus::Good;
71 }
72};
73
86{
87public:
88 virtual ~SignHandler() = default;
89
106 virtual std::string GetFilter() = 0;
107
124 virtual std::string GetSubFilter() = 0;
125
141 virtual void CustomizeSigDict(Object dict) = 0;
142
159 virtual size_t GetNumCerts() = 0;
160
177 virtual std::vector<Byte> GetCertData(size_t index) = 0;
178
190 virtual size_t EstimateMaxSize() = 0;
191
216 virtual std::vector<Byte> Sign(std::span<const Byte> data) = 0;
217};
218
224class FormField : public detail::RefCountedHandle<PDField> {
225public:
236 static FormField CreateFromPdfObject(const Object& object);
237
249
262 PDAtom GetFieldType() const;
263
274 bool IsTerminal() const;
275
291 PDFieldFlags GetFlags() const;
292
307 std::wstring GetFullName() const;
308
317 std::wstring GetValue() const;
318
327 std::wstring GetDefaultValue() const;
328
337 void SetDefaultValue(std::wstring_view value);
338
347 void SetValue(std::wstring_view value);
348
349#ifndef SWIG
358 void SetValue(const wchar_t* value);
359#endif
360
375 size_t GetNumWidgets() const;
376
393 Annot GetWidget(size_t index) const;
394
408 size_t GetChoiceNumOptions() const;
409
423 std::wstring GetChoiceOption(size_t index) const;
424
432 int GetMaxLen() const;
433
441 void SetMaxLen(int maxLen);
442
449 bool IsSignBlank() const;
450
456 void SetSignLock(PDAtom action, Object fields, PDSignLockPerms perms);
457
461 PDAtom GetSignLockAction() const;
462
467
472
478 void SignApprove(std::shared_ptr<SignHandler> signer, const std::wstring& reason);
479
486 void SignCertify(std::shared_ptr<SignHandler> signer, const std::wstring& reason, PDSignLockPerms perms = kPDSignLockPermsAllowFormFill);
487
491 void SignClear();
492
497 bool SignVerify() const;
498
504
508 std::wstring GetSignReason() const;
509
514
519
524 std::vector<Byte> GetSignCertificate(size_t index) const;
525
531 int GetSignRevision() const;
532
539
540
551
564 void AddDocumentTimestamp(std::shared_ptr<TimestampHandler> handler);
565
580 void AddLTVData(LTVHandler& handler);
581
598
599 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(FormField, PDField)
600};
601
602} // namespace PDF
603
604#include "form_field_impl.inl"
605
606#endif // PDFSDK_CXX_PDF_FORM_FIELD_H_INCLUDED_
AcroForm API.
PDSignLockPerms
Controls the permissions and security settings of a signed PDF document.
Definition acroform.h:271
@ kPDSignLockPermsAllowFormFill
Definition acroform.h:274
Represents an annotation in a PDF document.
Definition annot.h:24
PDAtom GetSignLockAction() const
Get the lock action for a signature form field.
static FormField CreateFromPdfObject(const Object &object)
Creates an interactive form field from a PDF object.
void SetDefaultValue(std::wstring_view value)
Set the default value of the form field.
void SignApprove(std::shared_ptr< SignHandler > signer, const std::wstring &reason)
Sign the signature form field with an approval signature. A PDF document can have multiple approval s...
Object GetPdfObject() const
Gets the PDF object (interactive form field dictionary), associated with this form field.
std::wstring GetFullName() const
Get the full name of the form field.
int GetSignRevision() const
Get the revision number of the signed signature form field.
Object GetSignLockFields() const
Get the lock fields for a signature form field.
void SetSignLock(PDAtom action, Object fields, PDSignLockPerms perms)
Sets lock parameters for a signature form field.
bool IsDocumentTimestamp() const
Check if the signature form field contains a document timestamp.
PDSignLockPerms GetSignLockPerms() const
Get the lock permissions for a signature form field.
void SignCertify(std::shared_ptr< SignHandler > signer, const std::wstring &reason, PDSignLockPerms perms=kPDSignLockPermsAllowFormFill)
Sign the signature form field with a certification signature. A PDF document can have only one certif...
std::wstring GetDefaultValue() const
Get the default value of the form field as a string.
std::wstring GetSignReason() const
Get the reason string of the signed signature form field.
SignValidationResult ValidateLTV(const SignValidationOptions &options) const
Validate this signature offline using the document's /DSS material.
PDAtom GetFieldType() const
Gets the type of the form field.
void AddLTVData(LTVHandler &handler)
Embed LTV (Long-Term Validation) revocation data for this signature.
Annot GetWidget(size_t index) const
Get the widget annotation at the specified index.
void SignClear()
Clear the signature form field.
bool IsSignCertification() const
Check if the signature form field is signed with a certification signature.
size_t GetNumSignCertificates() const
Get the number of certificates in the signed signature form field.
bool SignVerify() const
Verify the signature integrity.
void SetValue(const wchar_t *value)
Overload to prevent string literals from resolving to SetValue(bool).
std::wstring GetChoiceOption(size_t index) const
Get the option at the specified index for a choice form field.
bool IsTerminal() const
Checks if the form field is a terminal field.
std::wstring GetValue() const
Get the value of the form field as a string.
void SetValue(std::wstring_view value)
Set the value of the form field from a string.
int GetMaxLen() const
Get the maximum length of a text form field.
void SetMaxLen(int maxLen)
Set the maximum length of a text form field.
PDDateTime GetSignDate() const
Get the signing date of the signed signature form field.
void AddDocumentTimestamp(std::shared_ptr< TimestampHandler > handler)
Add a document timestamp to the signature form field.
PDFieldFlags GetFlags() const
Gets the flags of the form field, which specify its characteristics.
size_t GetChoiceNumOptions() const
Get the number of options for a choice form field.
bool IsSignBlank() const
Check if a signature form field is blank.
bool SignDocModifiedAfterSign() const
Check if a document was modified after signing the signature form field.
std::vector< Byte > GetSignCertificate(size_t index) const
Get the certificate data from the signed signature form field.
size_t GetNumWidgets() const
Get the number of widget annotations associated with the form field.
A callback interface for providing revocation data for LTV (Long-Term Validation).
Definition ltv_handler.h:24
Represents a PDF object.
Definition object.h:25
A callback interface for signing a PDF document.
Definition form_field.h:86
virtual void CustomizeSigDict(Object dict)=0
Add custom entries to a signature dictionary.
virtual std::string GetFilter()=0
Get the name of the signature handler implementation to use for creating a signature.
virtual std::vector< Byte > Sign(std::span< const Byte > data)=0
Creates a CMS signature blob from the raw byte data to be signed.
virtual size_t EstimateMaxSize()=0
Estimate the maximum size of the PDF signature.
virtual std::vector< Byte > GetCertData(size_t index)=0
Get the DER-encoded X.509 certificate, from the certificate chain you have used.
virtual std::string GetSubFilter()=0
Get the name of the encoding for processing/validating a signature.
virtual size_t GetNumCerts()=0
Get the number of signing certificates, from the X.509 certificate chain you used.
Definition types.h:23
Inputs for FormField::ValidateLTV().
Definition form_field.h:49
bool requireRevocation
Missing revocation data => not valid.
Definition form_field.h:51
std::vector< std::vector< Byte > > trustAnchors
DER-encoded X.509 roots.
Definition form_field.h:50
Outcome of FormField::ValidateLTV().
Definition form_field.h:57
bool ltvEnabled
DSS material was present and used.
Definition form_field.h:64
bool documentCovered
Whole doc, or only permitted later changes.
Definition form_field.h:59
bool IsValidLTV() const
Definition form_field.h:67
bool integrityValid
Digest over the /ByteRange verifies.
Definition form_field.h:58