Poppler Qt6 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, 2021 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_QT6_FORM_H_
35#define _POPPLER_QT6_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-qt6.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
71class POPPLER_QT6_EXPORT FormFieldIcon
72{
73
74 friend class FormFieldIconData;
75
76public:
77 explicit FormFieldIcon(FormFieldIconData *data);
78 FormFieldIcon(const FormFieldIcon &ffIcon);
80
81 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
82
83private:
84 FormFieldIconData *d_ptr;
85};
89class POPPLER_QT6_EXPORT FormField
90{
91
92 friend class FormFieldData;
93
94public:
99 {
103 FormSignature
104 };
105
106 virtual ~FormField();
107
111 virtual FormType type() const = 0;
112
117 QRectF rect() const;
118
122 int id() const;
123
127 QString name() const;
128
132 void setName(const QString &name) const;
133
137 QString fullyQualifiedName() const;
138
143 QString uiName() const;
144
148 bool isReadOnly() const;
149
153 void setReadOnly(bool value);
154
158 bool isVisible() const;
159
163 void setVisible(bool value);
164
168 bool isPrintable() const;
169
173 void setPrintable(bool value);
174
180 std::unique_ptr<Link> activationAction() const;
181
195 std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
196
200 std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
201
202protected:
204 explicit FormField(std::unique_ptr<FormFieldData> dd);
205
206 std::unique_ptr<FormFieldData> m_formData;
208
209private:
210 Q_DISABLE_COPY(FormField)
211};
212
216class POPPLER_QT6_EXPORT FormFieldButton : public FormField
217{
218public:
223 {
226 Radio
227 };
228
230 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
233
234 FormType type() const override;
235
240
244 QString caption() const;
245
250
255 void setIcon(const FormFieldIcon &icon);
256
260 bool state() const;
261
265 void setState(bool state);
266
273 QList<int> siblings() const;
274
275private:
276 Q_DISABLE_COPY(FormFieldButton)
277};
278
282class POPPLER_QT6_EXPORT FormFieldText : public FormField
283{
284public:
289 {
292 FileSelect
293 };
294
296 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
298 ~FormFieldText() override;
299
300 FormType type() const override;
301
306
310 QString text() const;
311
316 void setText(const QString &text);
317
322 void setAppearanceText(const QString &text);
323
330 bool isPassword() const;
331
335 bool isRichText() const;
336
340 int maximumLength() const;
341
345 Qt::Alignment textAlignment() const;
346
351 bool canBeSpellChecked() const;
352
356 double getFontSize() const;
357
361 void setFontSize(int fontSize);
362
363private:
364 Q_DISABLE_COPY(FormFieldText)
365};
366
370class POPPLER_QT6_EXPORT FormFieldChoice : public FormField
371{
372public:
377 {
379 ListBox
380 };
381
383 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
386
387 FormType type() const override;
388
393
397 QStringList choices() const;
398
404 QVector<QPair<QString, QString>> choicesWithExportValues() const;
405
412 bool isEditable() const;
413
420 bool multiSelect() const;
421
425 QList<int> currentChoices() const;
426
430 void setCurrentChoices(const QList<int> &choice);
431
435 QString editChoice() const;
436
440 void setEditChoice(const QString &text);
441
445 Qt::Alignment textAlignment() const;
446
453 bool canBeSpellChecked() const;
454
461 void setAppearanceChoiceText(const QString &text);
462
463private:
464 Q_DISABLE_COPY(FormFieldChoice)
465};
466
470class CertificateInfoPrivate;
471class POPPLER_QT6_EXPORT CertificateInfo
472{
473public:
478 {
479 RsaKey,
480 DsaKey,
481 EcKey,
482 OtherKey
483 };
484
489 {
490 KuDigitalSignature = 0x80,
491 KuNonRepudiation = 0x40,
492 KuKeyEncipherment = 0x20,
493 KuDataEncipherment = 0x10,
494 KuKeyAgreement = 0x08,
495 KuKeyCertSign = 0x04,
496 KuClrSign = 0x02,
497 KuEncipherOnly = 0x01,
498 KuNone = 0x00
499 };
501
502
505 enum EntityInfoKey
506 {
507 CommonName,
508 DistinguishedName,
509 EmailAddress,
510 Organization,
511 };
512
523 enum class KeyLocation
524 {
525 Unknown,
526 Other,
527 Computer,
528 HardwareToken
529 };
530
532 explicit CertificateInfo(CertificateInfoPrivate *priv);
534
538 bool isNull() const;
539
543 int version() const;
544
548 QByteArray serialNumber() const;
549
553 QString issuerInfo(EntityInfoKey key) const;
554
558 QString subjectInfo(EntityInfoKey key) const;
559
565 QString nickName() const;
566
570 QDateTime validityStart() const;
571
575 QDateTime validityEnd() const;
576
580 KeyUsageExtensions keyUsageExtensions() const;
581
585 QByteArray publicKey() const;
586
591
595 int publicKeyStrength() const;
596
600 bool isSelfSigned() const;
601
605 QByteArray certificateData() const;
606
612 bool checkPassword(const QString &password) const;
613
620
621 CertificateInfo(const CertificateInfo &other);
622 CertificateInfo &operator=(const CertificateInfo &other);
623
624private:
625 Q_DECLARE_PRIVATE(CertificateInfo)
626
627 QSharedPointer<CertificateInfoPrivate> d_ptr;
628};
629Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
630
631
634class SignatureValidationInfoPrivate;
635class POPPLER_QT6_EXPORT SignatureValidationInfo
636{
637public:
651
666
671 {
672 HashAlgorithmUnknown,
673 HashAlgorithmMd2,
674 HashAlgorithmMd5,
675 HashAlgorithmSha1,
676 HashAlgorithmSha256,
677 HashAlgorithmSha384,
678 HashAlgorithmSha512,
679 HashAlgorithmSha224
680 };
681
683 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
686
691
696
700 QString signerName() const;
701
705 QString signerSubjectDN() const;
706
710 QString location() const;
711
715 QString reason() const;
716
721
725 time_t signingTime() const;
726
730 QByteArray signature() const;
731
735 QList<qint64> signedRangeBounds() const;
736
741 bool signsTotalDocument() const;
742
747
749 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
750
751private:
752 Q_DECLARE_PRIVATE(SignatureValidationInfo)
753 friend class FormFieldSignature;
754 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
755};
756
762class AsyncObjectPrivate;
763class POPPLER_QT6_EXPORT AsyncObject : public QObject // clazy:exclude=ctor-missing-parent-argument
764{
765 Q_OBJECT
766public:
767 /* Constructor. On purpose not having a QObject parameter
768 It will be returned by shared_ptr or unique_ptr
769 */
770 AsyncObject();
771 ~AsyncObject() override;
772Q_SIGNALS:
773 void done();
774public Q_SLOTS:
775private:
776 std::unique_ptr<AsyncObjectPrivate> d;
777};
778
782class POPPLER_QT6_EXPORT FormFieldSignature : public FormField
783{
784public:
789 {
790 UnknownSignatureType,
791 AdbePkcs7sha1,
792 AdbePkcs7detached,
793 EtsiCAdESdetached,
794 UnsignedSignature
795 };
796
801 {
802 ValidateVerifyCertificate = 1,
803 ValidateForceRevalidation = 2,
804 ValidateWithoutOCSPRevocationCheck = 4,
805 ValidateUseAIACertFetch = 8
806 };
807
809 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
812
813 FormType type() const override;
814
819
833 POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const;
834
848 POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
849
867 std::pair<SignatureValidationInfo, std::shared_ptr<AsyncObject>> validateAsync(ValidateOptions opt, const QDateTime &validationTime = {}) const;
868
877
882 {
884 GenericSigningError,
885 SigningSuccess
886 };
887
895 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
896
897private:
898 Q_DISABLE_COPY(FormFieldSignature)
899};
906{
907 NSS,
908 GPG
909};
910
916QVector<CryptoSignBackend> POPPLER_QT6_EXPORT availableCryptoSignBackends();
917
925std::optional<CryptoSignBackend> POPPLER_QT6_EXPORT activeCryptoSignBackend();
926
934bool POPPLER_QT6_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
935
942
949
957bool POPPLER_QT6_DEPRECATED POPPLER_QT6_EXPORT hasNSSSupport();
958
964QVector<CertificateInfo> POPPLER_QT6_EXPORT getAvailableSigningCertificates();
965
971QString POPPLER_QT6_EXPORT getNSSDir();
972
978void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL);
979
985void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
986}
987
988#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition poppler-annotation.h:435
Definition poppler-form.h:764
Definition poppler-form.h:472
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.
Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension) enum EntityInfoKey
Predefined keys for elements in an entity's distinguished name.
Definition poppler-form.h:500
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:489
PublicKeyType
The algorithm of public key.
Definition poppler-form.h:478
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.
KeyLocation
A signing key can be located in different places sometimes.
Definition poppler-form.h:524
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition poppler-form.h:217
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.
~FormFieldButton() override
*‍/
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:223
@ CheckBox
A check box.
Definition poppler-form.h:225
@ Push
A simple push button.
Definition poppler-form.h:224
bool state() const
The state of the button.
A form field that represents a choice field.
Definition poppler-form.h:371
bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
~FormFieldChoice() override
*‍/
ChoiceType
The particular type of this choice field.
Definition poppler-form.h:377
@ ComboBox
A simple singleline text field.
Definition poppler-form.h:378
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:72
A form field that represents a signature.
Definition poppler-form.h:783
std::pair< SignatureValidationInfo, std::shared_ptr< AsyncObject > > validateAsync(ValidateOptions 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.
SignatureType
The types of signature fields.
Definition poppler-form.h:789
POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const
Validate the signature with validationTime as validation time.
SigningResult
Definition poppler-form.h:882
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition poppler-form.h:883
ValidateOptions
The validation options of this signature.
Definition poppler-form.h:801
~FormFieldSignature() override
*‍/
POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const
Validate the signature with now as validation time.
SignatureValidationInfo::CertificateStatus validateResult() const
A form field that represents a text input.
Definition poppler-form.h:283
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:289
@ Multiline
A multiline text field.
Definition poppler-form.h:291
@ Normal
A simple singleline text field.
Definition poppler-form.h:290
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)
~FormFieldText() override
*‍/
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:90
bool isPrintable() const
Whether this field is printable.
std::unique_ptr< Link > activationAction() const
The activation action of this form field.
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.
std::unique_ptr< Link > additionalAction(AdditionalActionType type) const
Returns a given form additional action.
void setReadOnly(bool value)
Set whether this form field is read-only.
void setPrintable(bool value)
Set whether this field is printable.
std::unique_ptr< Link > additionalAction(Annotation::AdditionalActionType type) const
Returns a given widget annotation additional action.
QRectF rect() const
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:186
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition poppler-form.h:190
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition poppler-form.h:188
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition poppler-form.h:189
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition poppler-form.h:187
FormType
The different types of form field.
Definition poppler-form.h:99
@ FormButton
A button field. See ButtonType.
Definition poppler-form.h:100
@ FormText
A text field. See TextType.
Definition poppler-form.h:101
@ FormChoice
A single choice field. See ChoiceType.
Definition poppler-form.h:102
Holds data for a new signature.
Definition poppler-qt6.h:2016
Definition poppler-form.h:636
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:656
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition poppler-form.h:658
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition poppler-form.h:659
@ CertificateGenericError
The certificate could not be verified.
Definition poppler-form.h:662
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition poppler-form.h:660
@ CertificateTrusted
The certificate is considered trusted.
Definition poppler-form.h:657
@ CertificateNotVerified
The certificate is not yet verified.
Definition poppler-form.h:663
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition poppler-form.h:661
HashAlgorithm
The hash algorithm of the signature.
Definition poppler-form.h:671
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition poppler-form.h:642
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition poppler-form.h:645
@ SignatureGenericError
The signature could not be verified.
Definition poppler-form.h:647
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition poppler-form.h:646
@ SignatureValid
The signature is cryptographically valid.
Definition poppler-form.h:643
@ SignatureNotFound
The requested signature is not present in the document.
Definition poppler-form.h:648
@ SignatureInvalid
The signature is cryptographically invalid.
Definition poppler-form.h:644
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 Qt6 binding.
Definition poppler-annotation.h:49
bool POPPLER_QT6_DEPRECATED POPPLER_QT6_EXPORT hasNSSSupport()
Returns is poppler was compiled with NSS support.
std::optional< CryptoSignBackend > POPPLER_QT6_EXPORT activeCryptoSignBackend()
Returns current active backend or nullopt if none is active.
QVector< CertificateInfo > POPPLER_QT6_EXPORT getAvailableSigningCertificates()
Return vector of suitable signing certificates.
QVector< CryptoSignBackend > POPPLER_QT6_EXPORT availableCryptoSignBackends()
The available compiled-in backends.
QString POPPLER_QT6_EXPORT getNSSDir()
Gets the current NSS CertDB directory.
Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions) class SignatureValidationInfoPrivate
A signature validation info helper class.
CryptoSignBackend
Possible compiled in backends for signature handling.
Definition poppler-form.h:906
CryptoSignBackendFeature
Definition poppler-form.h:937
@ BackendAsksPassphrase
If the backend itself out of band requests passwords or if the host applicaion somehow must do it.
void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL)
Set a custom NSS CertDB directory.
bool POPPLER_QT6_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend)
Sets active backend.
void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function< char *(const char *)> &f)
Sets the callback for NSS password requests.
bool POPPLER_QT6_EXPORT hasCryptoSignBackendFeature(CryptoSignBackend, CryptoSignBackendFeature)
Queries if a backend supports or not supports a given feature.