Poppler Qt5 24.09.0
poppler-form.h
1/* poppler-form.h: qt interface to poppler
2 * Copyright (C) 2007-2008, Pino Toscano <pino@kde.org>
3 * Copyright (C) 2008, 2011, 2016, 2017, 2019-2022, Albert Astals Cid <aacid@kde.org>
4 * Copyright (C) 2012, Adam Reichold <adamreichold@myopera.com>
5 * Copyright (C) 2016, Hanno Meyer-Thurow <h.mth@web.de>
6 * Copyright (C) 2017, Hans-Ulrich Jüttner <huj@froreich-bioscientia.de>
7 * Copyright (C) 2017, Tobias C. Berner <tcberner@freebsd.org>
8 * Copyright (C) 2018, Andre Heinecke <aheinecke@intevation.de>
9 * Copyright (C) 2018, Chinmoy Ranjan Pradhan <chinmoyrp65@protonmail.com>
10 * Copyright (C) 2018, Oliver Sander <oliver.sander@tu-dresden.de>
11 * Copyright (C) 2019 João Netto <joaonetto901@gmail.com>
12 * Copyright (C) 2019, Adrian Johnson <ajohnson@redneon.com>
13 * Copyright (C) 2020, Thorsten Behrens <Thorsten.Behrens@CIB.de>
14 * Copyright (C) 2020, Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
15 * Copyright (C) 2021, Theofilos Intzoglou <int.teo@gmail.com>
16 * Copyright (C) 2023, 2024, g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk>
17 * Copyright (C) 2024, Pratham Gandhi <ppg.1382@gmail.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
22 * any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 */
33
34#ifndef _POPPLER_QT5_FORM_H_
35#define _POPPLER_QT5_FORM_H_
36
37#include <functional>
38#include <memory>
39#include <ctime>
40#include <optional>
41#include <QtCore/QDateTime>
42#include <QtCore/QVector>
43#include <QtCore/QList>
44#include <QtCore/QRectF>
45#include <QtCore/QStringList>
46#include <QtCore/QSharedPointer>
47#include "poppler-export.h"
48#include "poppler-annotation.h"
49#include "poppler-qt5.h"
50
51class Object;
52class Page;
53class FormWidget;
54class FormWidgetButton;
55class FormWidgetText;
56class FormWidgetChoice;
57class FormWidgetSignature;
58
59namespace Poppler {
60
61class DocumentData;
62class Link;
63
64class FormFieldData;
65class FormFieldIconData;
66
73class POPPLER_QT5_EXPORT FormFieldIcon
74{
75
76 friend class FormFieldIconData;
77
78public:
79 explicit FormFieldIcon(FormFieldIconData *data);
80 FormFieldIcon(const FormFieldIcon &ffIcon);
82
83 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
84
85private:
86 FormFieldIconData *d_ptr;
87};
93class POPPLER_QT5_EXPORT FormField
94{
95
96 friend class FormFieldData;
97
98public:
103 {
107 FormSignature
108 };
109
110 virtual ~FormField();
111
115 virtual FormType type() const = 0;
116
121 QRectF rect() const;
122
126 int id() const;
127
131 QString name() const;
132
137 void setName(const QString &name) const;
138
143 QString fullyQualifiedName() const;
144
149 QString uiName() const;
150
154 bool isReadOnly() const;
155
160 void setReadOnly(bool value);
161
165 bool isVisible() const;
166
171 void setVisible(bool value);
172
177 bool isPrintable() const;
178
183 void setPrintable(bool value);
184
191
210
217
218protected:
220 explicit FormField(std::unique_ptr<FormFieldData> dd);
221
222 std::unique_ptr<FormFieldData> m_formData;
224
225private:
226 Q_DISABLE_COPY(FormField)
227};
228
234class POPPLER_QT5_EXPORT FormFieldButton : public FormField
235{
236public:
241 {
244 Radio
245 };
246
248 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
250 ~FormFieldButton() override;
251
252 FormType type() const override;
253
258
262 QString caption() const;
263
270
277 void setIcon(const FormFieldIcon &icon);
278
282 bool state() const;
283
287 void setState(bool state);
288
295 QList<int> siblings() const;
296
297private:
298 Q_DISABLE_COPY(FormFieldButton)
299};
300
306class POPPLER_QT5_EXPORT FormFieldText : public FormField
307{
308public:
313 {
316 FileSelect
317 };
318
320 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
322 ~FormFieldText() override;
323
324 FormType type() const override;
325
330
334 QString text() const;
335
340 void setText(const QString &text);
341
347 void setAppearanceText(const QString &text);
348
355 bool isPassword() const;
356
360 bool isRichText() const;
361
365 int maximumLength() const;
366
370 Qt::Alignment textAlignment() const;
371
376 bool canBeSpellChecked() const;
377
381 double getFontSize() const;
382
386 void setFontSize(int fontSize);
387
388private:
389 Q_DISABLE_COPY(FormFieldText)
390};
391
397class POPPLER_QT5_EXPORT FormFieldChoice : public FormField
398{
399public:
404 {
406 ListBox
407 };
408
410 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
412 ~FormFieldChoice() override;
413
414 FormType type() const override;
415
420
424 QStringList choices() const;
425
432 QVector<QPair<QString, QString>> choicesWithExportValues() const;
433
440 bool isEditable() const;
441
448 bool multiSelect() const;
449
453 QList<int> currentChoices() const;
454
458 void setCurrentChoices(const QList<int> &choice);
459
465 QString editChoice() const;
466
472 void setEditChoice(const QString &text);
473
477 Qt::Alignment textAlignment() const;
478
485 bool canBeSpellChecked() const;
486
493 void setAppearanceChoiceText(const QString &text);
494
495private:
496 Q_DISABLE_COPY(FormFieldChoice)
497};
498
504class CertificateInfoPrivate;
505class POPPLER_QT5_EXPORT CertificateInfo
506{
507public:
512 {
513 RsaKey,
514 DsaKey,
515 EcKey,
516 OtherKey
517 };
518
523 {
524 KuDigitalSignature = 0x80,
525 KuNonRepudiation = 0x40,
526 KuKeyEncipherment = 0x20,
527 KuDataEncipherment = 0x10,
528 KuKeyAgreement = 0x08,
529 KuKeyCertSign = 0x04,
530 KuClrSign = 0x02,
531 KuEncipherOnly = 0x01,
532 KuNone = 0x00
533 };
534 Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
535
536
540 {
541 CommonName,
542 DistinguishedName,
543 EmailAddress,
544 Organization,
545 };
546
557 enum class KeyLocation
558 {
559 Unknown,
560 Other,
561 Computer,
562 HardwareToken
563 };
564
566 explicit CertificateInfo(CertificateInfoPrivate *priv);
568
572 bool isNull() const;
573
577 int version() const;
578
582 QByteArray serialNumber() const;
583
587 QString issuerInfo(EntityInfoKey key) const;
588
592 QString subjectInfo(EntityInfoKey key) const;
593
599 QString nickName() const;
600
604 QDateTime validityStart() const;
605
609 QDateTime validityEnd() const;
610
614 KeyUsageExtensions keyUsageExtensions() const;
615
619 QByteArray publicKey() const;
620
625
629 int publicKeyStrength() const;
630
634 bool isSelfSigned() const;
635
639 QByteArray certificateData() const;
640
646 bool checkPassword(const QString &password) const;
647
654
655 CertificateInfo(const CertificateInfo &other);
656 CertificateInfo &operator=(const CertificateInfo &other);
657
658private:
659 Q_DECLARE_PRIVATE(CertificateInfo)
660
661 QSharedPointer<CertificateInfoPrivate> d_ptr;
662};
663Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
664
665
670class SignatureValidationInfoPrivate;
671class POPPLER_QT5_EXPORT SignatureValidationInfo
672{
673public:
687
702
708 {
709 HashAlgorithmUnknown,
710 HashAlgorithmMd2,
711 HashAlgorithmMd5,
712 HashAlgorithmSha1,
713 HashAlgorithmSha256,
714 HashAlgorithmSha384,
715 HashAlgorithmSha512,
716 HashAlgorithmSha224
717 };
718
720 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
723
728
733
737 QString signerName() const;
738
743 QString signerSubjectDN() const;
744
749 QString location() const;
750
755 QString reason() const;
756
762
766 time_t signingTime() const;
767
772 QByteArray signature() const;
773
778 QList<qint64> signedRangeBounds() const;
779
785 bool signsTotalDocument() const;
786
792
794 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
795
796private:
797 Q_DECLARE_PRIVATE(SignatureValidationInfo)
798 friend class FormFieldSignature;
799 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
800};
801
807class AsyncObjectPrivate;
808class POPPLER_QT5_EXPORT AsyncObject : public QObject // clazy:exclude=ctor-missing-parent-argument
809{
810 Q_OBJECT
811public:
812 /* Constructor. On purpose not having a QObject parameter
813 It will be returned by shared_ptr or unique_ptr
814 */
815 AsyncObject();
816 ~AsyncObject() override;
817Q_SIGNALS:
818 void done();
819public Q_SLOTS:
820private:
821 std::unique_ptr<AsyncObjectPrivate> d;
822};
823
829class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
830{
831public:
837 {
838 AdbePkcs7sha1,
839 AdbePkcs7detached,
840 EtsiCAdESdetached,
842 UnsignedSignature
843 };
844
849 {
850 ValidateVerifyCertificate = 1,
851 ValidateForceRevalidation = 2,
852 ValidateWithoutOCSPRevocationCheck = 4,
853 ValidateUseAIACertFetch = 8
854 };
855
857 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
859 ~FormFieldSignature() override;
860
861 FormType type() const override;
862
868
882 POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const;
883
899 POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
900
918 std::pair<SignatureValidationInfo, std::shared_ptr<AsyncObject>> validateAsync(ValidateOptions opt, const QDateTime &validationTime = {}) const;
919
928
933 {
935 GenericSigningError,
936 SigningSuccess
937 };
938
946 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
947
948private:
949 Q_DISABLE_COPY(FormFieldSignature)
950};
951
958{
959 NSS,
960 GPG
961};
962
968QVector<CryptoSignBackend> POPPLER_QT5_EXPORT availableCryptoSignBackends();
969
977std::optional<CryptoSignBackend> POPPLER_QT5_EXPORT activeCryptoSignBackend();
978
986bool POPPLER_QT5_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
987
994
1001
1009bool POPPLER_QT5_DEPRECATED POPPLER_QT5_EXPORT hasNSSSupport();
1010
1016QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
1017
1023QString POPPLER_QT5_EXPORT getNSSDir();
1024
1030void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
1031
1037void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
1038}
1039
1040#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition poppler-annotation.h:481
Definition poppler-form.h:809
Definition poppler-form.h:506
PublicKeyType publicKeyType() const
The public key type.
bool isSelfSigned() const
Returns true if certificate is self-signed otherwise returns false.
QByteArray certificateData() const
The DER encoded certificate.
QString issuerInfo(EntityInfoKey key) const
Information about the issuer.
QString subjectInfo(EntityInfoKey key) const
Information about the subject.
KeyLocation keyLocation() const
The storage location for this key.
bool checkPassword(const QString &password) const
Checks if the given password is the correct one for this certificate.
int version() const
The certificate version string.
int publicKeyStrength() const
The strength of public key in bits.
bool isNull() const
Returns true if certificate has no contents; otherwise returns false.
QDateTime validityEnd() const
The date-time when certificate expires.
QByteArray serialNumber() const
The certificate serial number.
KeyUsageExtension
Certificate key usage extensions.
Definition poppler-form.h:523
PublicKeyType
The algorithm of public key.
Definition poppler-form.h:512
KeyUsageExtensions keyUsageExtensions() const
The uses allowed for the certificate.
QDateTime validityStart() const
The date-time when certificate becomes valid.
QByteArray publicKey() const
The public key value.
EntityInfoKey
Predefined keys for elements in an entity's distinguished name.
Definition poppler-form.h:540
KeyLocation
A signing key can be located in different places sometimes.
Definition poppler-form.h:558
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition poppler-form.h:235
ButtonType buttonType() const
The particular type of the button field.
QString caption() const
The caption to be used for the button.
void setIcon(const FormFieldIcon &icon)
Sets a new icon for the button, it has to be a icon returned by FormFieldButton::icon.
QList< int > siblings() const
The list with the IDs of siblings (ie, buttons belonging to the same group as the current one.
FormType type() const override
The type of the field.
void setState(bool state)
Sets the state of the button to the new state .
FormFieldIcon icon() const
Gets the icon used by the button.
ButtonType
The types of button field.
Definition poppler-form.h:241
@ CheckBox
A check box.
Definition poppler-form.h:243
@ Push
A simple push button.
Definition poppler-form.h:242
bool state() const
The state of the button.
A form field that represents a choice field.
Definition poppler-form.h:398
bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
ChoiceType
The particular type of this choice field.
Definition poppler-form.h:404
@ ComboBox
A simple singleline text field.
Definition poppler-form.h:405
QVector< QPair< QString, QString > > choicesWithExportValues() const
The possible choices of the choice field.
ChoiceType choiceType() const
The choice type of the choice field.
bool multiSelect() const
Whether more than one choice of this FormFieldChoice::ListBox can be selected at the same time.
QList< int > currentChoices() const
The currently selected choices.
void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
QString editChoice() const
The text entered into an editable combo box choice field.
void setCurrentChoices(const QList< int > &choice)
Sets the selected choices to choice.
void setAppearanceChoiceText(const QString &text)
Sets the text inside the Appearance Stream to the specified text.
Qt::Alignment textAlignment() const
The horizontal alignment for the text of this text field.
FormType type() const override
The type of the field.
QStringList choices() const
The possible choices of the choice field.
bool isEditable() const
Whether this FormFieldChoice::ComboBox is editable, i.e.
The class containing the appearance information.
Definition poppler-form.h:74
A form field that represents a signature.
Definition poppler-form.h:830
std::pair< SignatureValidationInfo, std::shared_ptr< AsyncObject > > validateAsync(ValidateOptions opt, const QDateTime &validationTime={}) const
Validate the signature with validationTime as validation time.
POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const
Validate the signature with validationTime as validation time.
SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const
Signs a field of UnsignedSignature type.
FormType type() const override
The type of the field.
SignatureType signatureType() const
The signature type.
POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const
Validate the signature with now as validation time.
SignatureType
The types of signature fields.
Definition poppler-form.h:837
@ UnknownSignatureType
Definition poppler-form.h:841
SigningResult
Definition poppler-form.h:933
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition poppler-form.h:934
ValidateOptions
The validation options of this signature.
Definition poppler-form.h:849
SignatureValidationInfo::CertificateStatus validateResult() const
A form field that represents a text input.
Definition poppler-form.h:307
void setAppearanceText(const QString &text)
Sets the text inside the Appearance Stream to the specified text.
TextType
The particular type of this text field.
Definition poppler-form.h:313
@ Multiline
A multiline text field.
Definition poppler-form.h:315
@ Normal
A simple singleline text field.
Definition poppler-form.h:314
void setText(const QString &text)
Sets the text associated with the text field to the specified text.
QString text() const
The text associated with the text field.
double getFontSize() const
The font size of the text in the form field.
void setFontSize(int fontSize)
Set the font size of the text in the form field (currently only as integer)
bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
TextType textType() const
The text type of the text field.
Qt::Alignment textAlignment() const
The horizontal alignment for the text of this text field.
FormType type() const override
The type of the field.
int maximumLength() const
The maximum length for the text of this field, or -1 if not set.
bool isRichText() const
Whether this text field should allow rich text.
The base class representing a form field.
Definition poppler-form.h:94
bool isPrintable() const
Whether this field is printable.
Link * activationAction() const
The activation action of this form field.
Link * additionalAction(Annotation::AdditionalActionType type) const
Returns a given widget annotation additional action.
int id() const
The ID of the field.
QString name() const
The internal name (T) of the field.
void setVisible(bool value)
Set whether this form field is visible.
bool isVisible() const
Whether this form field is visible.
void setReadOnly(bool value)
Set whether this form field is read-only.
void setPrintable(bool value)
Set whether this field is printable.
QRectF rect() const
Link * additionalAction(AdditionalActionType type) const
Returns a given form additional action.
bool isReadOnly() const
Whether this form field is read-only.
QString fullyQualifiedName() const
The internal fully qualified name of the field.
QString uiName() const
The name of the field to be used in user interface (eg messages to the user).
void setName(const QString &name) const
Sets the internal name (T) of the field.
virtual FormType type() const =0
The type of the field.
AdditionalActionType
Describes the flags from the form 'AA' dictionary.
Definition poppler-form.h:198
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition poppler-form.h:202
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition poppler-form.h:200
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition poppler-form.h:201
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition poppler-form.h:199
FormType
The different types of form field.
Definition poppler-form.h:103
@ FormButton
A button field. See ButtonType.
Definition poppler-form.h:104
@ FormText
A text field. See TextType.
Definition poppler-form.h:105
@ FormChoice
A single choice field. See ChoiceType.
Definition poppler-form.h:106
Holds data for a new signature.
Definition poppler-qt5.h:2240
Definition poppler-form.h:672
QString signerName() const
The signer name associated with the signature.
QList< qint64 > signedRangeBounds() const
Get the bounds of the ranges of the document which are signed.
QByteArray signature() const
Get the signature binary data.
HashAlgorithm hashAlgorithm() const
The hash algorithm used for the signature.
bool signsTotalDocument() const
Checks whether the signature authenticates the total document except for the signature itself.
CertificateInfo certificateInfo() const
The signer certificate info.
CertificateStatus
The verification result of the certificate.
Definition poppler-form.h:692
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition poppler-form.h:694
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition poppler-form.h:695
@ CertificateGenericError
The certificate could not be verified.
Definition poppler-form.h:698
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition poppler-form.h:696
@ CertificateTrusted
The certificate is considered trusted.
Definition poppler-form.h:693
@ CertificateNotVerified
The certificate is not yet verified.
Definition poppler-form.h:699
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition poppler-form.h:697
HashAlgorithm
The hash algorithm of the signature.
Definition poppler-form.h:708
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition poppler-form.h:678
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition poppler-form.h:681
@ SignatureGenericError
The signature could not be verified.
Definition poppler-form.h:683
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition poppler-form.h:682
@ SignatureValid
The signature is cryptographically valid.
Definition poppler-form.h:679
@ SignatureNotFound
The requested signature is not present in the document.
Definition poppler-form.h:684
@ SignatureInvalid
The signature is cryptographically invalid.
Definition poppler-form.h:680
SignatureStatus signatureStatus() const
The signature status of the signature.
QString signerSubjectDN() const
The signer subject distinguished name associated with the signature.
QString reason() const
Get signing reason.
CertificateStatus certificateStatus() const
The certificate status of the signature.
QString location() const
Get signing location.
The Poppler Qt5 binding.
Definition poppler-annotation.h:50
QVector< CertificateInfo > getAvailableSigningCertificates()
Return vector of suitable signing certificates.
bool hasCryptoSignBackendFeature(CryptoSignBackend, CryptoSignBackendFeature)
Queries if a backend supports or not supports a given feature.
QString getNSSDir()
Gets the current NSS CertDB directory.
std::optional< CryptoSignBackend > activeCryptoSignBackend()
Returns current active backend or nullopt if none is active.
void setNSSPasswordCallback(const std::function< char *(const char *)> &f)
Sets the callback for NSS password requests.
bool setActiveCryptoSignBackend(CryptoSignBackend backend)
Sets active backend.
bool POPPLER_QT5_DEPRECATED hasNSSSupport()
Returns is poppler was compiled with NSS support.
void setNSSDir(const QString &pathURL)
Set a custom NSS CertDB directory.
CryptoSignBackend
Possible compiled in backends for signature handling.
Definition poppler-form.h:958
CryptoSignBackendFeature
Definition poppler-form.h:989
@ BackendAsksPassphrase
If the backend itself out of band requests passwords or if the host applicaion somehow must do it.
QVector< CryptoSignBackend > availableCryptoSignBackends()
The available compiled-in backends.