Poppler Qt5 25.03.90
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
542 {
543 X509,
544 PGP
545 };
546
551 {
552 CommonName,
553 DistinguishedName,
554 EmailAddress,
555 Organization,
556 };
557
568 enum class KeyLocation
569 {
570 Unknown,
571 Other,
572 Computer,
573 HardwareToken
574 };
575
577 explicit CertificateInfo(CertificateInfoPrivate *priv);
579
583 bool isNull() const;
584
588 int version() const;
589
593 QByteArray serialNumber() const;
594
598 QString issuerInfo(EntityInfoKey key) const;
599
603 QString subjectInfo(EntityInfoKey key) const;
604
610 QString nickName() const;
611
615 QDateTime validityStart() const;
616
620 QDateTime validityEnd() const;
621
625 KeyUsageExtensions keyUsageExtensions() const;
626
630 QByteArray publicKey() const;
631
636
640 int publicKeyStrength() const;
641
645 bool isSelfSigned() const;
646
653
657 QByteArray certificateData() const;
658
664 bool checkPassword(const QString &password) const;
665
672
673 CertificateInfo(const CertificateInfo &other);
674 CertificateInfo &operator=(const CertificateInfo &other);
675
676private:
677 Q_DECLARE_PRIVATE(CertificateInfo)
678
679 QSharedPointer<CertificateInfoPrivate> d_ptr;
680};
681Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
682
683
688class SignatureValidationInfoPrivate;
689class POPPLER_QT5_EXPORT SignatureValidationInfo
690{
691public:
705
720
726 {
727 HashAlgorithmUnknown,
728 HashAlgorithmMd2,
729 HashAlgorithmMd5,
730 HashAlgorithmSha1,
731 HashAlgorithmSha256,
732 HashAlgorithmSha384,
733 HashAlgorithmSha512,
734 HashAlgorithmSha224
735 };
736
738 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
741
746
751
755 QString signerName() const;
756
761 QString signerSubjectDN() const;
762
767 QString location() const;
768
773 QString reason() const;
774
780
784 time_t signingTime() const;
785
790 QByteArray signature() const;
791
796 QList<qint64> signedRangeBounds() const;
797
803 bool signsTotalDocument() const;
804
810
812 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
813
814private:
815 Q_DECLARE_PRIVATE(SignatureValidationInfo)
816 friend class FormFieldSignature;
817 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
818};
819
825class AsyncObjectPrivate;
826class POPPLER_QT5_EXPORT AsyncObject : public QObject // clazy:exclude=ctor-missing-parent-argument
827{
828 Q_OBJECT
829public:
830 /* Constructor. On purpose not having a QObject parameter
831 It will be returned by shared_ptr or unique_ptr
832 */
833 AsyncObject();
834 ~AsyncObject() override;
835Q_SIGNALS:
836 void done();
837
838private:
839 std::unique_ptr<AsyncObjectPrivate> d;
840};
841
847class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
848{
849public:
855 {
856 AdbePkcs7sha1,
857 AdbePkcs7detached,
858 EtsiCAdESdetached,
862 };
863
868 {
869 ValidateVerifyCertificate = 1,
870 ValidateForceRevalidation = 2,
871 ValidateWithoutOCSPRevocationCheck = 4,
872 ValidateUseAIACertFetch = 8
873 };
874
876 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
878 ~FormFieldSignature() override;
879
880 FormType type() const override;
881
887
901 POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const;
902
918 POPPLER_QT5_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
919
937 std::pair<SignatureValidationInfo, std::shared_ptr<AsyncObject>> validateAsync(ValidateOptions opt, const QDateTime &validationTime = {}) const;
938
947
952 {
954 GenericSigningError,
955 SigningSuccess
956 };
957
965 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
966
967private:
968 Q_DISABLE_COPY(FormFieldSignature)
969};
970
977{
978 NSS,
979 GPG
980};
981
987QVector<CryptoSignBackend> POPPLER_QT5_EXPORT availableCryptoSignBackends();
988
996std::optional<CryptoSignBackend> POPPLER_QT5_EXPORT activeCryptoSignBackend();
997
1005bool POPPLER_QT5_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
1006
1013
1020
1028bool POPPLER_QT5_DEPRECATED POPPLER_QT5_EXPORT hasNSSSupport();
1029
1035QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
1036
1042QString POPPLER_QT5_EXPORT getNSSDir();
1043
1049void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
1050
1056void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
1057
1066void POPPLER_QT5_EXPORT setPgpSignaturesAllowed(bool allowed);
1067
1073bool POPPLER_QT5_EXPORT arePgpSignaturesAllowed();
1074}
1075
1076#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition poppler-annotation.h:481
Definition poppler-form.h:827
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.
CertificateType certificateType() const
QString subjectInfo(EntityInfoKey key) const
Information about the subject.
CertificateType
The type of the certificate.
Definition poppler-form.h:542
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:551
KeyLocation
A signing key can be located in different places sometimes.
Definition poppler-form.h:569
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:848
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:855
@ UnknownSignatureType
Definition poppler-form.h:859
@ G10cPgpSignatureDetached
non standard signature type
Definition poppler-form.h:861
@ UnsignedSignature
Definition poppler-form.h:860
SigningResult
Definition poppler-form.h:952
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition poppler-form.h:953
ValidateOptions
The validation options of this signature.
Definition poppler-form.h:868
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:690
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:710
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition poppler-form.h:712
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition poppler-form.h:713
@ CertificateGenericError
The certificate could not be verified.
Definition poppler-form.h:716
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition poppler-form.h:714
@ CertificateTrusted
The certificate is considered trusted.
Definition poppler-form.h:711
@ CertificateNotVerified
The certificate is not yet verified.
Definition poppler-form.h:717
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition poppler-form.h:715
HashAlgorithm
The hash algorithm of the signature.
Definition poppler-form.h:726
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition poppler-form.h:696
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition poppler-form.h:699
@ SignatureGenericError
The signature could not be verified.
Definition poppler-form.h:701
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition poppler-form.h:700
@ SignatureValid
The signature is cryptographically valid.
Definition poppler-form.h:697
@ SignatureNotFound
The requested signature is not present in the document.
Definition poppler-form.h:702
@ SignatureInvalid
The signature is cryptographically invalid.
Definition poppler-form.h:698
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.
bool arePgpSignaturesAllowed()
void setPgpSignaturesAllowed(bool allowed)
Allow pgp signatures in pdf files (standard-extension, experimental) Not supported for NSS backend.
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:977
CryptoSignBackendFeature
Definition poppler-form.h:1008
@ 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.