Poppler Qt6 22.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 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
30 */
31
32#ifndef _POPPLER_QT6_FORM_H_
33#define _POPPLER_QT6_FORM_H_
34
35#include <functional>
36#include <memory>
37#include <ctime>
38#include <QtCore/QDateTime>
39#include <QtCore/QVector>
40#include <QtCore/QList>
41#include <QtCore/QRectF>
42#include <QtCore/QStringList>
43#include <QtCore/QSharedPointer>
44#include "poppler-export.h"
45#include "poppler-annotation.h"
46#include "poppler-qt6.h"
47
48class Object;
49class Page;
50class FormWidget;
51class FormWidgetButton;
52class FormWidgetText;
53class FormWidgetChoice;
54class FormWidgetSignature;
55
56namespace Poppler {
57
58class DocumentData;
59class Link;
60
61class FormFieldData;
62class FormFieldIconData;
63
68class POPPLER_QT6_EXPORT FormFieldIcon
69{
70
71 friend class FormFieldIconData;
72
73public:
74 explicit FormFieldIcon(FormFieldIconData *data);
75 FormFieldIcon(const FormFieldIcon &ffIcon);
77
78 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
79
80private:
81 FormFieldIconData *d_ptr;
82};
86class POPPLER_QT6_EXPORT FormField
87{
88
89 friend class FormFieldData;
90
91public:
96 {
100 FormSignature
101 };
102
103 virtual ~FormField();
104
108 virtual FormType type() const = 0;
109
114 QRectF rect() const;
115
119 int id() const;
120
124 QString name() const;
125
129 void setName(const QString &name) const;
130
134 QString fullyQualifiedName() const;
135
140 QString uiName() const;
141
145 bool isReadOnly() const;
146
150 void setReadOnly(bool value);
151
155 bool isVisible() const;
156
160 void setVisible(bool value);
161
165 bool isPrintable() const;
166
170 void setPrintable(bool value);
171
177 std::unique_ptr<Link> activationAction() const;
178
183 {
188 };
192 std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
193
197 std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
198
199protected:
201 explicit FormField(std::unique_ptr<FormFieldData> dd);
202
203 std::unique_ptr<FormFieldData> m_formData;
205
206private:
207 Q_DISABLE_COPY(FormField)
208};
209
213class POPPLER_QT6_EXPORT FormFieldButton : public FormField
214{
215public:
220 {
223 Radio
224 };
225
227 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
230
231 FormType type() const override;
232
237
241 QString caption() const;
242
247
252 void setIcon(const FormFieldIcon &icon);
253
257 bool state() const;
258
262 void setState(bool state);
263
270 QList<int> siblings() const;
271
272private:
273 Q_DISABLE_COPY(FormFieldButton)
274};
275
279class POPPLER_QT6_EXPORT FormFieldText : public FormField
280{
281public:
286 {
289 FileSelect
290 };
291
293 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
295 ~FormFieldText() override;
296
297 FormType type() const override;
298
303
307 QString text() const;
308
313 void setText(const QString &text);
314
319 void setAppearanceText(const QString &text);
320
327 bool isPassword() const;
328
332 bool isRichText() const;
333
337 int maximumLength() const;
338
342 Qt::Alignment textAlignment() const;
343
348 bool canBeSpellChecked() const;
349
353 double getFontSize() const;
354
358 void setFontSize(int fontSize);
359
360private:
361 Q_DISABLE_COPY(FormFieldText)
362};
363
367class POPPLER_QT6_EXPORT FormFieldChoice : public FormField
368{
369public:
374 {
376 ListBox
377 };
378
380 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
383
384 FormType type() const override;
385
390
394 QStringList choices() const;
395
401 QVector<QPair<QString, QString>> choicesWithExportValues() const;
402
409 bool isEditable() const;
410
417 bool multiSelect() const;
418
422 QList<int> currentChoices() const;
423
427 void setCurrentChoices(const QList<int> &choice);
428
432 QString editChoice() const;
433
437 void setEditChoice(const QString &text);
438
442 Qt::Alignment textAlignment() const;
443
450 bool canBeSpellChecked() const;
451
452private:
453 Q_DISABLE_COPY(FormFieldChoice)
454};
455
459class CertificateInfoPrivate;
460class POPPLER_QT6_EXPORT CertificateInfo
461{
462public:
467 {
468 RsaKey,
469 DsaKey,
470 EcKey,
471 OtherKey
472 };
473
478 {
479 KuDigitalSignature = 0x80,
480 KuNonRepudiation = 0x40,
481 KuKeyEncipherment = 0x20,
482 KuDataEncipherment = 0x10,
483 KuKeyAgreement = 0x08,
484 KuKeyCertSign = 0x04,
485 KuClrSign = 0x02,
486 KuEncipherOnly = 0x01,
487 KuNone = 0x00
488 };
490
491
494 enum EntityInfoKey
495 {
496 CommonName,
497 DistinguishedName,
498 EmailAddress,
499 Organization,
500 };
501
503 explicit CertificateInfo(CertificateInfoPrivate *priv);
505
509 bool isNull() const;
510
514 int version() const;
515
519 QByteArray serialNumber() const;
520
524 QString issuerInfo(EntityInfoKey key) const;
525
529 QString subjectInfo(EntityInfoKey key) const;
530
536 QString nickName() const;
537
541 QDateTime validityStart() const;
542
546 QDateTime validityEnd() const;
547
551 KeyUsageExtensions keyUsageExtensions() const;
552
556 QByteArray publicKey() const;
557
562
566 int publicKeyStrength() const;
567
571 bool isSelfSigned() const;
572
576 QByteArray certificateData() const;
577
583 bool checkPassword(const QString &password) const;
584
585 CertificateInfo(const CertificateInfo &other);
586 CertificateInfo &operator=(const CertificateInfo &other);
587
588private:
589 Q_DECLARE_PRIVATE(CertificateInfo)
590
591 QSharedPointer<CertificateInfoPrivate> d_ptr;
592};
593Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
594
595
598class SignatureValidationInfoPrivate;
599class POPPLER_QT6_EXPORT SignatureValidationInfo
600{
601public:
606 {
613 SignatureNotVerified
614 };
615
620 {
627 CertificateNotVerified
628 };
629
634 {
635 HashAlgorithmUnknown,
636 HashAlgorithmMd2,
637 HashAlgorithmMd5,
638 HashAlgorithmSha1,
639 HashAlgorithmSha256,
640 HashAlgorithmSha384,
641 HashAlgorithmSha512,
642 HashAlgorithmSha224
643 };
644
646 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
649
654
659
663 QString signerName() const;
664
668 QString signerSubjectDN() const;
669
673 QString location() const;
674
678 QString reason() const;
679
684
688 time_t signingTime() const;
689
693 QByteArray signature() const;
694
698 QList<qint64> signedRangeBounds() const;
699
704 bool signsTotalDocument() const;
705
710
712 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
713
714private:
715 Q_DECLARE_PRIVATE(SignatureValidationInfo)
716
717 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
718};
719
723class POPPLER_QT6_EXPORT FormFieldSignature : public FormField
724{
725public:
730 {
731 UnknownSignatureType,
732 AdbePkcs7sha1,
733 AdbePkcs7detached,
734 EtsiCAdESdetached,
735 UnsignedSignature
736 };
737
742 {
743 ValidateVerifyCertificate = 1,
744 ValidateForceRevalidation = 2,
745 ValidateWithoutOCSPRevocationCheck = 4,
746 ValidateUseAIACertFetch = 8
747 };
748
750 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
753
754 FormType type() const override;
755
760
767
773 SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
774
779 {
781 GenericSigningError,
782 SigningSuccess
783 };
784
792 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
793
794private:
795 Q_DISABLE_COPY(FormFieldSignature)
796};
797
803bool POPPLER_QT6_EXPORT hasNSSSupport();
804
810QVector<CertificateInfo> POPPLER_QT6_EXPORT getAvailableSigningCertificates();
811
817QString POPPLER_QT6_EXPORT getNSSDir();
818
824void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL);
825
831void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
832}
833
834#endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition: poppler-annotation.h:435
Definition: poppler-form.h:461
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.
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:489
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:478
PublicKeyType
The algorithm of public key.
Definition: poppler-form.h:467
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.
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition: poppler-form.h:214
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:220
@ CheckBox
A check box.
Definition: poppler-form.h:222
@ Push
A simple push button.
Definition: poppler-form.h:221
bool state() const
The state of the button.
A form field that represents a choice field.
Definition: poppler-form.h:368
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:374
@ ComboBox
A simple singleline text field.
Definition: poppler-form.h:375
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:69
A form field that represents a signature.
Definition: poppler-form.h:724
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:730
SigningResult
Definition: poppler-form.h:779
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition: poppler-form.h:780
ValidateOptions
The validation options of this signature.
Definition: poppler-form.h:742
~FormFieldSignature() override
*‍/
A form field that represents a text input.
Definition: poppler-form.h:280
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:286
@ Multiline
A multiline text field.
Definition: poppler-form.h:288
@ Normal
A simple singleline text field.
Definition: poppler-form.h:287
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:87
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:183
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition: poppler-form.h:187
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition: poppler-form.h:185
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition: poppler-form.h:186
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition: poppler-form.h:184
FormType
The different types of form field.
Definition: poppler-form.h:96
@ FormButton
A button field. See ButtonType.
Definition: poppler-form.h:97
@ FormText
A text field. See TextType.
Definition: poppler-form.h:98
@ FormChoice
A single choice field. See ChoiceType.
Definition: poppler-form.h:99
Holds data for a new signature.
Definition: poppler-qt6.h:1971
Definition: poppler-form.h:600
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:620
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition: poppler-form.h:622
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition: poppler-form.h:623
@ CertificateGenericError
The certificate could not be verified.
Definition: poppler-form.h:626
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition: poppler-form.h:624
@ CertificateTrusted
The certificate is considered trusted.
Definition: poppler-form.h:621
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition: poppler-form.h:625
HashAlgorithm
The hash algorithm of the signature.
Definition: poppler-form.h:634
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition: poppler-form.h:606
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition: poppler-form.h:609
@ SignatureGenericError
The signature could not be verified.
Definition: poppler-form.h:611
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition: poppler-form.h:610
@ SignatureValid
The signature is cryptographically valid.
Definition: poppler-form.h:607
@ SignatureNotFound
The requested signature is not present in the document.
Definition: poppler-form.h:612
@ SignatureInvalid
The signature is cryptographically invalid.
Definition: poppler-form.h:608
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
QVector< CertificateInfo > POPPLER_QT6_EXPORT getAvailableSigningCertificates()
Return vector of suitable signing certificates.
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.
void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL)
Set a custom NSS CertDB directory.
bool POPPLER_QT6_EXPORT hasNSSSupport()
Returns is poppler was compiled with NSS support.
void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function< char *(const char *)> &f)
Sets the callback for NSS password requests.