Poppler Qt6 23.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, g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
31 */
32
33#ifndef _POPPLER_QT6_FORM_H_
34#define _POPPLER_QT6_FORM_H_
35
36#include <functional>
37#include <memory>
38#include <ctime>
39#include <optional>
40#include <QtCore/QDateTime>
41#include <QtCore/QVector>
42#include <QtCore/QList>
43#include <QtCore/QRectF>
44#include <QtCore/QStringList>
45#include <QtCore/QSharedPointer>
46#include "poppler-export.h"
47#include "poppler-annotation.h"
48#include "poppler-qt6.h"
49
50class Object;
51class Page;
52class FormWidget;
53class FormWidgetButton;
54class FormWidgetText;
55class FormWidgetChoice;
56class FormWidgetSignature;
57
58namespace Poppler {
59
60class DocumentData;
61class Link;
62
63class FormFieldData;
64class FormFieldIconData;
65
70class POPPLER_QT6_EXPORT FormFieldIcon
71{
72
73 friend class FormFieldIconData;
74
75public:
76 explicit FormFieldIcon(FormFieldIconData *data);
77 FormFieldIcon(const FormFieldIcon &ffIcon);
79
80 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
81
82private:
83 FormFieldIconData *d_ptr;
84};
88class POPPLER_QT6_EXPORT FormField
89{
90
91 friend class FormFieldData;
92
93public:
98 {
102 FormSignature
103 };
104
105 virtual ~FormField();
106
110 virtual FormType type() const = 0;
111
116 QRectF rect() const;
117
121 int id() const;
122
126 QString name() const;
127
131 void setName(const QString &name) const;
132
136 QString fullyQualifiedName() const;
137
142 QString uiName() const;
143
147 bool isReadOnly() const;
148
152 void setReadOnly(bool value);
153
157 bool isVisible() const;
158
162 void setVisible(bool value);
163
167 bool isPrintable() const;
168
172 void setPrintable(bool value);
173
179 std::unique_ptr<Link> activationAction() const;
180
194 std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
195
199 std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
200
201protected:
203 explicit FormField(std::unique_ptr<FormFieldData> dd);
204
205 std::unique_ptr<FormFieldData> m_formData;
207
208private:
209 Q_DISABLE_COPY(FormField)
210};
211
215class POPPLER_QT6_EXPORT FormFieldButton : public FormField
216{
217public:
222 {
225 Radio
226 };
227
229 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
232
233 FormType type() const override;
234
239
243 QString caption() const;
244
249
254 void setIcon(const FormFieldIcon &icon);
255
259 bool state() const;
260
264 void setState(bool state);
265
272 QList<int> siblings() const;
273
274private:
275 Q_DISABLE_COPY(FormFieldButton)
276};
277
281class POPPLER_QT6_EXPORT FormFieldText : public FormField
282{
283public:
288 {
291 FileSelect
292 };
293
295 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
297 ~FormFieldText() override;
298
299 FormType type() const override;
300
305
309 QString text() const;
310
315 void setText(const QString &text);
316
321 void setAppearanceText(const QString &text);
322
329 bool isPassword() const;
330
334 bool isRichText() const;
335
339 int maximumLength() const;
340
344 Qt::Alignment textAlignment() const;
345
350 bool canBeSpellChecked() const;
351
355 double getFontSize() const;
356
360 void setFontSize(int fontSize);
361
362private:
363 Q_DISABLE_COPY(FormFieldText)
364};
365
369class POPPLER_QT6_EXPORT FormFieldChoice : public FormField
370{
371public:
376 {
378 ListBox
379 };
380
382 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
385
386 FormType type() const override;
387
392
396 QStringList choices() const;
397
403 QVector<QPair<QString, QString>> choicesWithExportValues() const;
404
411 bool isEditable() const;
412
419 bool multiSelect() const;
420
424 QList<int> currentChoices() const;
425
429 void setCurrentChoices(const QList<int> &choice);
430
434 QString editChoice() const;
435
439 void setEditChoice(const QString &text);
440
444 Qt::Alignment textAlignment() const;
445
452 bool canBeSpellChecked() const;
453
454private:
455 Q_DISABLE_COPY(FormFieldChoice)
456};
457
461class CertificateInfoPrivate;
462class POPPLER_QT6_EXPORT CertificateInfo
463{
464public:
469 {
470 RsaKey,
471 DsaKey,
472 EcKey,
473 OtherKey
474 };
475
480 {
481 KuDigitalSignature = 0x80,
482 KuNonRepudiation = 0x40,
483 KuKeyEncipherment = 0x20,
484 KuDataEncipherment = 0x10,
485 KuKeyAgreement = 0x08,
486 KuKeyCertSign = 0x04,
487 KuClrSign = 0x02,
488 KuEncipherOnly = 0x01,
489 KuNone = 0x00
490 };
492
493
496 enum EntityInfoKey
497 {
498 CommonName,
499 DistinguishedName,
500 EmailAddress,
501 Organization,
502 };
503
514 enum class KeyLocation
515 {
516 Unknown,
517 Other,
518 Computer,
519 HardwareToken
520 };
521
523 explicit CertificateInfo(CertificateInfoPrivate *priv);
525
529 bool isNull() const;
530
534 int version() const;
535
539 QByteArray serialNumber() const;
540
544 QString issuerInfo(EntityInfoKey key) const;
545
549 QString subjectInfo(EntityInfoKey key) const;
550
556 QString nickName() const;
557
561 QDateTime validityStart() const;
562
566 QDateTime validityEnd() const;
567
571 KeyUsageExtensions keyUsageExtensions() const;
572
576 QByteArray publicKey() const;
577
582
586 int publicKeyStrength() const;
587
591 bool isSelfSigned() const;
592
596 QByteArray certificateData() const;
597
603 bool checkPassword(const QString &password) const;
604
611
612 CertificateInfo(const CertificateInfo &other);
613 CertificateInfo &operator=(const CertificateInfo &other);
614
615private:
616 Q_DECLARE_PRIVATE(CertificateInfo)
617
618 QSharedPointer<CertificateInfoPrivate> d_ptr;
619};
620Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
621
622
625class SignatureValidationInfoPrivate;
626class POPPLER_QT6_EXPORT SignatureValidationInfo
627{
628public:
642
656
661 {
662 HashAlgorithmUnknown,
663 HashAlgorithmMd2,
664 HashAlgorithmMd5,
665 HashAlgorithmSha1,
666 HashAlgorithmSha256,
667 HashAlgorithmSha384,
668 HashAlgorithmSha512,
669 HashAlgorithmSha224
670 };
671
673 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
676
681
686
690 QString signerName() const;
691
695 QString signerSubjectDN() const;
696
700 QString location() const;
701
705 QString reason() const;
706
711
715 time_t signingTime() const;
716
720 QByteArray signature() const;
721
725 QList<qint64> signedRangeBounds() const;
726
731 bool signsTotalDocument() const;
732
737
739 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
740
741private:
742 Q_DECLARE_PRIVATE(SignatureValidationInfo)
743
744 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
745};
746
750class POPPLER_QT6_EXPORT FormFieldSignature : public FormField
751{
752public:
757 {
758 UnknownSignatureType,
759 AdbePkcs7sha1,
760 AdbePkcs7detached,
761 EtsiCAdESdetached,
762 UnsignedSignature
763 };
764
769 {
770 ValidateVerifyCertificate = 1,
771 ValidateForceRevalidation = 2,
772 ValidateWithoutOCSPRevocationCheck = 4,
773 ValidateUseAIACertFetch = 8
774 };
775
777 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
780
781 FormType type() const override;
782
787
800
812 SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
813
818 {
820 GenericSigningError,
821 SigningSuccess
822 };
823
831 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
832
833private:
834 Q_DISABLE_COPY(FormFieldSignature)
835};
842{
843 NSS,
844 GPG
845};
846
852QVector<CryptoSignBackend> POPPLER_QT6_EXPORT availableCryptoSignBackends();
853
861std::optional<CryptoSignBackend> POPPLER_QT6_EXPORT activeCryptoSignBackend();
862
870bool POPPLER_QT6_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
871
878
885
893bool POPPLER_QT6_DEPRECATED POPPLER_QT6_EXPORT hasNSSSupport();
894
900QVector<CertificateInfo> POPPLER_QT6_EXPORT getAvailableSigningCertificates();
901
907QString POPPLER_QT6_EXPORT getNSSDir();
908
914void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL);
915
921void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
922}
923
924#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition poppler-annotation.h:435
Definition poppler-form.h:463
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:491
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:480
PublicKeyType
The algorithm of public key.
Definition poppler-form.h:469
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:515
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition poppler-form.h:216
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:222
@ CheckBox
A check box.
Definition poppler-form.h:224
@ Push
A simple push button.
Definition poppler-form.h:223
bool state() const
The state of the button.
A form field that represents a choice field.
Definition poppler-form.h:370
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:376
@ ComboBox
A simple singleline text field.
Definition poppler-form.h:377
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.
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:71
A form field that represents a signature.
Definition poppler-form.h:751
SignatureValidationInfo validate(ValidateOptions opt) const
Validate the signature with now 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.
SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const
Validate the signature with validationTime as validation time.
SignatureType
The types of signature fields.
Definition poppler-form.h:757
SigningResult
Definition poppler-form.h:818
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition poppler-form.h:819
ValidateOptions
The validation options of this signature.
Definition poppler-form.h:769
~FormFieldSignature() override
*‍/
A form field that represents a text input.
Definition poppler-form.h:282
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:288
@ Multiline
A multiline text field.
Definition poppler-form.h:290
@ Normal
A simple singleline text field.
Definition poppler-form.h:289
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:89
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:185
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition poppler-form.h:189
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition poppler-form.h:187
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition poppler-form.h:188
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition poppler-form.h:186
FormType
The different types of form field.
Definition poppler-form.h:98
@ FormButton
A button field. See ButtonType.
Definition poppler-form.h:99
@ FormText
A text field. See TextType.
Definition poppler-form.h:100
@ FormChoice
A single choice field. See ChoiceType.
Definition poppler-form.h:101
Holds data for a new signature.
Definition poppler-qt6.h:1983
Definition poppler-form.h:627
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:647
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition poppler-form.h:649
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition poppler-form.h:650
@ CertificateGenericError
The certificate could not be verified.
Definition poppler-form.h:653
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition poppler-form.h:651
@ CertificateTrusted
The certificate is considered trusted.
Definition poppler-form.h:648
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition poppler-form.h:652
HashAlgorithm
The hash algorithm of the signature.
Definition poppler-form.h:661
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition poppler-form.h:633
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition poppler-form.h:636
@ SignatureGenericError
The signature could not be verified.
Definition poppler-form.h:638
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition poppler-form.h:637
@ SignatureValid
The signature is cryptographically valid.
Definition poppler-form.h:634
@ SignatureNotFound
The requested signature is not present in the document.
Definition poppler-form.h:639
@ SignatureInvalid
The signature is cryptographically invalid.
Definition poppler-form.h:635
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:842
CryptoSignBackendFeature
Definition poppler-form.h:873
@ 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.