Poppler Qt5 24.04.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, 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_QT5_FORM_H_
34#define _POPPLER_QT5_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-qt5.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
72class POPPLER_QT5_EXPORT FormFieldIcon
73{
74
75 friend class FormFieldIconData;
76
77public:
78 explicit FormFieldIcon(FormFieldIconData *data);
79 FormFieldIcon(const FormFieldIcon &ffIcon);
81
82 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
83
84private:
85 FormFieldIconData *d_ptr;
86};
92class POPPLER_QT5_EXPORT FormField
93{
94
95 friend class FormFieldData;
96
97public:
102 {
106 FormSignature
107 };
108
109 virtual ~FormField();
110
114 virtual FormType type() const = 0;
115
120 QRectF rect() const;
121
125 int id() const;
126
130 QString name() const;
131
136 void setName(const QString &name) const;
137
142 QString fullyQualifiedName() const;
143
148 QString uiName() const;
149
153 bool isReadOnly() const;
154
159 void setReadOnly(bool value);
160
164 bool isVisible() const;
165
170 void setVisible(bool value);
171
176 bool isPrintable() const;
177
182 void setPrintable(bool value);
183
190
209
216
217protected:
219 explicit FormField(std::unique_ptr<FormFieldData> dd);
220
221 std::unique_ptr<FormFieldData> m_formData;
223
224private:
225 Q_DISABLE_COPY(FormField)
226};
227
233class POPPLER_QT5_EXPORT FormFieldButton : public FormField
234{
235public:
240 {
243 Radio
244 };
245
247 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
249 ~FormFieldButton() override;
250
251 FormType type() const override;
252
257
261 QString caption() const;
262
269
276 void setIcon(const FormFieldIcon &icon);
277
281 bool state() const;
282
286 void setState(bool state);
287
294 QList<int> siblings() const;
295
296private:
297 Q_DISABLE_COPY(FormFieldButton)
298};
299
305class POPPLER_QT5_EXPORT FormFieldText : public FormField
306{
307public:
312 {
315 FileSelect
316 };
317
319 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
321 ~FormFieldText() override;
322
323 FormType type() const override;
324
329
333 QString text() const;
334
339 void setText(const QString &text);
340
346 void setAppearanceText(const QString &text);
347
354 bool isPassword() const;
355
359 bool isRichText() const;
360
364 int maximumLength() const;
365
369 Qt::Alignment textAlignment() const;
370
375 bool canBeSpellChecked() const;
376
380 double getFontSize() const;
381
385 void setFontSize(int fontSize);
386
387private:
388 Q_DISABLE_COPY(FormFieldText)
389};
390
396class POPPLER_QT5_EXPORT FormFieldChoice : public FormField
397{
398public:
403 {
405 ListBox
406 };
407
409 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
411 ~FormFieldChoice() override;
412
413 FormType type() const override;
414
419
423 QStringList choices() const;
424
431 QVector<QPair<QString, QString>> choicesWithExportValues() const;
432
439 bool isEditable() const;
440
447 bool multiSelect() const;
448
452 QList<int> currentChoices() const;
453
457 void setCurrentChoices(const QList<int> &choice);
458
464 QString editChoice() const;
465
471 void setEditChoice(const QString &text);
472
476 Qt::Alignment textAlignment() const;
477
484 bool canBeSpellChecked() const;
485
486private:
487 Q_DISABLE_COPY(FormFieldChoice)
488};
489
495class CertificateInfoPrivate;
496class POPPLER_QT5_EXPORT CertificateInfo
497{
498public:
503 {
504 RsaKey,
505 DsaKey,
506 EcKey,
507 OtherKey
508 };
509
514 {
515 KuDigitalSignature = 0x80,
516 KuNonRepudiation = 0x40,
517 KuKeyEncipherment = 0x20,
518 KuDataEncipherment = 0x10,
519 KuKeyAgreement = 0x08,
520 KuKeyCertSign = 0x04,
521 KuClrSign = 0x02,
522 KuEncipherOnly = 0x01,
523 KuNone = 0x00
524 };
525 Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
526
527
531 {
532 CommonName,
533 DistinguishedName,
534 EmailAddress,
535 Organization,
536 };
537
548 enum class KeyLocation
549 {
550 Unknown,
551 Other,
552 Computer,
553 HardwareToken
554 };
555
557 explicit CertificateInfo(CertificateInfoPrivate *priv);
559
563 bool isNull() const;
564
568 int version() const;
569
573 QByteArray serialNumber() const;
574
578 QString issuerInfo(EntityInfoKey key) const;
579
583 QString subjectInfo(EntityInfoKey key) const;
584
590 QString nickName() const;
591
595 QDateTime validityStart() const;
596
600 QDateTime validityEnd() const;
601
605 KeyUsageExtensions keyUsageExtensions() const;
606
610 QByteArray publicKey() const;
611
616
620 int publicKeyStrength() const;
621
625 bool isSelfSigned() const;
626
630 QByteArray certificateData() const;
631
637 bool checkPassword(const QString &password) const;
638
645
646 CertificateInfo(const CertificateInfo &other);
647 CertificateInfo &operator=(const CertificateInfo &other);
648
649private:
650 Q_DECLARE_PRIVATE(CertificateInfo)
651
652 QSharedPointer<CertificateInfoPrivate> d_ptr;
653};
654Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
655
656
661class SignatureValidationInfoPrivate;
662class POPPLER_QT5_EXPORT SignatureValidationInfo
663{
664public:
678
692
698 {
699 HashAlgorithmUnknown,
700 HashAlgorithmMd2,
701 HashAlgorithmMd5,
702 HashAlgorithmSha1,
703 HashAlgorithmSha256,
704 HashAlgorithmSha384,
705 HashAlgorithmSha512,
706 HashAlgorithmSha224
707 };
708
710 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
713
718
723
727 QString signerName() const;
728
733 QString signerSubjectDN() const;
734
739 QString location() const;
740
745 QString reason() const;
746
752
756 time_t signingTime() const;
757
762 QByteArray signature() const;
763
768 QList<qint64> signedRangeBounds() const;
769
775 bool signsTotalDocument() const;
776
782
784 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
785
786private:
787 Q_DECLARE_PRIVATE(SignatureValidationInfo)
788
789 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
790};
791
797class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
798{
799public:
805 {
806 AdbePkcs7sha1,
807 AdbePkcs7detached,
808 EtsiCAdESdetached,
810 UnsignedSignature
811 };
812
817 {
818 ValidateVerifyCertificate = 1,
819 ValidateForceRevalidation = 2,
820 ValidateWithoutOCSPRevocationCheck = 4,
821 ValidateUseAIACertFetch = 8
822 };
823
825 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
827 ~FormFieldSignature() override;
828
829 FormType type() const override;
830
836
849
863 SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
864
869 {
871 GenericSigningError,
872 SigningSuccess
873 };
874
882 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
883
884private:
885 Q_DISABLE_COPY(FormFieldSignature)
886};
887
894{
895 NSS,
896 GPG
897};
898
904QVector<CryptoSignBackend> POPPLER_QT5_EXPORT availableCryptoSignBackends();
905
913std::optional<CryptoSignBackend> POPPLER_QT5_EXPORT activeCryptoSignBackend();
914
922bool POPPLER_QT5_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
923
930
937
945bool POPPLER_QT5_DEPRECATED POPPLER_QT5_EXPORT hasNSSSupport();
946
952QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
953
959QString POPPLER_QT5_EXPORT getNSSDir();
960
966void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
967
973void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
974}
975
976#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition poppler-annotation.h:481
Definition poppler-form.h:497
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:514
PublicKeyType
The algorithm of public key.
Definition poppler-form.h:503
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:531
KeyLocation
A signing key can be located in different places sometimes.
Definition poppler-form.h:549
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition poppler-form.h:234
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:240
@ CheckBox
A check box.
Definition poppler-form.h:242
@ Push
A simple push button.
Definition poppler-form.h:241
bool state() const
The state of the button.
A form field that represents a choice field.
Definition poppler-form.h:397
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:403
@ ComboBox
A simple singleline text field.
Definition poppler-form.h:404
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:73
A form field that represents a signature.
Definition poppler-form.h:798
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:805
@ UnknownSignatureType
Definition poppler-form.h:809
SigningResult
Definition poppler-form.h:869
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition poppler-form.h:870
ValidateOptions
The validation options of this signature.
Definition poppler-form.h:817
A form field that represents a text input.
Definition poppler-form.h:306
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:312
@ Multiline
A multiline text field.
Definition poppler-form.h:314
@ Normal
A simple singleline text field.
Definition poppler-form.h:313
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:93
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:197
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition poppler-form.h:201
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition poppler-form.h:199
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition poppler-form.h:200
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition poppler-form.h:198
FormType
The different types of form field.
Definition poppler-form.h:102
@ FormButton
A button field. See ButtonType.
Definition poppler-form.h:103
@ FormText
A text field. See TextType.
Definition poppler-form.h:104
@ FormChoice
A single choice field. See ChoiceType.
Definition poppler-form.h:105
Holds data for a new signature.
Definition poppler-qt5.h:2207
Definition poppler-form.h:663
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:683
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition poppler-form.h:685
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition poppler-form.h:686
@ CertificateGenericError
The certificate could not be verified.
Definition poppler-form.h:689
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition poppler-form.h:687
@ CertificateTrusted
The certificate is considered trusted.
Definition poppler-form.h:684
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition poppler-form.h:688
HashAlgorithm
The hash algorithm of the signature.
Definition poppler-form.h:698
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition poppler-form.h:669
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition poppler-form.h:672
@ SignatureGenericError
The signature could not be verified.
Definition poppler-form.h:674
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition poppler-form.h:673
@ SignatureValid
The signature is cryptographically valid.
Definition poppler-form.h:670
@ SignatureNotFound
The requested signature is not present in the document.
Definition poppler-form.h:675
@ SignatureInvalid
The signature is cryptographically invalid.
Definition poppler-form.h:671
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:894
CryptoSignBackendFeature
Definition poppler-form.h:925
@ 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.