Poppler Qt5  22.05.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  *
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_QT5_FORM_H_
33 #define _POPPLER_QT5_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-qt5.h"
47 
48 class Object;
49 class Page;
50 class FormWidget;
51 class FormWidgetButton;
52 class FormWidgetText;
53 class FormWidgetChoice;
54 class FormWidgetSignature;
55 
56 namespace Poppler {
57 
58 class DocumentData;
59 class Link;
60 
61 class FormFieldData;
62 class FormFieldIconData;
63 
70 class POPPLER_QT5_EXPORT FormFieldIcon
71 {
72 
73  friend class FormFieldIconData;
74 
75 public:
76  explicit FormFieldIcon(FormFieldIconData *data);
77  FormFieldIcon(const FormFieldIcon &ffIcon);
78  ~FormFieldIcon();
79 
80  FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
81 
82 private:
83  FormFieldIconData *d_ptr;
84 };
90 class POPPLER_QT5_EXPORT FormField
91 {
92 
93  friend class FormFieldData;
94 
95 public:
99  enum FormType
100  {
104  FormSignature
105  };
106 
107  virtual ~FormField();
108 
112  virtual FormType type() const = 0;
113 
118  QRectF rect() const;
119 
123  int id() const;
124 
128  QString name() const;
129 
134  void setName(const QString &name) const;
135 
140  QString fullyQualifiedName() const;
141 
146  QString uiName() const;
147 
151  bool isReadOnly() const;
152 
157  void setReadOnly(bool value);
158 
162  bool isVisible() const;
163 
168  void setVisible(bool value);
169 
174  bool isPrintable() const;
175 
180  void setPrintable(bool value);
181 
188 
195  {
200  };
207 
214 
215 protected:
217  explicit FormField(std::unique_ptr<FormFieldData> dd);
218 
219  std::unique_ptr<FormFieldData> m_formData;
221 
222 private:
223  Q_DISABLE_COPY(FormField)
224 };
225 
231 class POPPLER_QT5_EXPORT FormFieldButton : public FormField
232 {
233 public:
238  {
241  Radio
242  };
243 
245  FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
247  ~FormFieldButton() override;
248 
249  FormType type() const override;
250 
255 
259  QString caption() const;
260 
267 
274  void setIcon(const FormFieldIcon &icon);
275 
279  bool state() const;
280 
284  void setState(bool state);
285 
292  QList<int> siblings() const;
293 
294 private:
295  Q_DISABLE_COPY(FormFieldButton)
296 };
297 
303 class POPPLER_QT5_EXPORT FormFieldText : public FormField
304 {
305 public:
309  enum TextType
310  {
313  FileSelect
314  };
315 
317  FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
319  ~FormFieldText() override;
320 
321  FormType type() const override;
322 
327 
331  QString text() const;
332 
337  void setText(const QString &text);
338 
344  void setAppearanceText(const QString &text);
345 
352  bool isPassword() const;
353 
357  bool isRichText() const;
358 
362  int maximumLength() const;
363 
367  Qt::Alignment textAlignment() const;
368 
373  bool canBeSpellChecked() const;
374 
378  double getFontSize() const;
379 
383  void setFontSize(int fontSize);
384 
385 private:
386  Q_DISABLE_COPY(FormFieldText)
387 };
388 
394 class POPPLER_QT5_EXPORT FormFieldChoice : public FormField
395 {
396 public:
401  {
403  ListBox
404  };
405 
407  FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
409  ~FormFieldChoice() override;
410 
411  FormType type() const override;
412 
417 
421  QStringList choices() const;
422 
429  QVector<QPair<QString, QString>> choicesWithExportValues() const;
430 
437  bool isEditable() const;
438 
445  bool multiSelect() const;
446 
450  QList<int> currentChoices() const;
451 
455  void setCurrentChoices(const QList<int> &choice);
456 
462  QString editChoice() const;
463 
469  void setEditChoice(const QString &text);
470 
474  Qt::Alignment textAlignment() const;
475 
482  bool canBeSpellChecked() const;
483 
484 private:
485  Q_DISABLE_COPY(FormFieldChoice)
486 };
487 
493 class CertificateInfoPrivate;
494 class POPPLER_QT5_EXPORT CertificateInfo
495 {
496 public:
501  {
502  RsaKey,
503  DsaKey,
504  EcKey,
505  OtherKey
506  };
507 
512  {
513  KuDigitalSignature = 0x80,
514  KuNonRepudiation = 0x40,
515  KuKeyEncipherment = 0x20,
516  KuDataEncipherment = 0x10,
517  KuKeyAgreement = 0x08,
518  KuKeyCertSign = 0x04,
519  KuClrSign = 0x02,
520  KuEncipherOnly = 0x01,
521  KuNone = 0x00
522  };
523  Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
524 
525 
529  {
530  CommonName,
531  DistinguishedName,
532  EmailAddress,
533  Organization,
534  };
535 
536  CertificateInfo();
537  explicit CertificateInfo(CertificateInfoPrivate *priv);
538  ~CertificateInfo();
539 
543  bool isNull() const;
544 
548  int version() const;
549 
553  QByteArray serialNumber() const;
554 
558  QString issuerInfo(EntityInfoKey key) const;
559 
563  QString subjectInfo(EntityInfoKey key) const;
564 
570  QString nickName() const;
571 
575  QDateTime validityStart() const;
576 
580  QDateTime validityEnd() const;
581 
585  KeyUsageExtensions keyUsageExtensions() const;
586 
590  QByteArray publicKey() const;
591 
596 
600  int publicKeyStrength() const;
601 
605  bool isSelfSigned() const;
606 
610  QByteArray certificateData() const;
611 
617  bool checkPassword(const QString &password) const;
618 
619  CertificateInfo(const CertificateInfo &other);
620  CertificateInfo &operator=(const CertificateInfo &other);
621 
622 private:
623  Q_DECLARE_PRIVATE(CertificateInfo)
624 
625  QSharedPointer<CertificateInfoPrivate> d_ptr;
626 };
627 Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
628 
629 
634 class SignatureValidationInfoPrivate;
635 class POPPLER_QT5_EXPORT SignatureValidationInfo
636 {
637 public:
642  {
649  SignatureNotVerified
650  };
651 
656  {
663  CertificateNotVerified
664  };
665 
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 
706  QString signerSubjectDN() const;
707 
712  QString location() const;
713 
718  QString reason() const;
719 
725 
729  time_t signingTime() const;
730 
735  QByteArray signature() const;
736 
741  QList<qint64> signedRangeBounds() const;
742 
748  bool signsTotalDocument() const;
749 
755 
757  SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
758 
759 private:
760  Q_DECLARE_PRIVATE(SignatureValidationInfo)
761 
762  QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
763 };
764 
770 class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
771 {
772 public:
778  {
779  AdbePkcs7sha1,
780  AdbePkcs7detached,
781  EtsiCAdESdetached,
783  UnsignedSignature
784  };
785 
790  {
791  ValidateVerifyCertificate = 1,
792  ValidateForceRevalidation = 2,
793  ValidateWithoutOCSPRevocationCheck = 4,
794  ValidateUseAIACertFetch = 8
795  };
796 
798  FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
800  ~FormFieldSignature() override;
801 
802  FormType type() const override;
803 
809 
816 
824  SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
825 
830  {
832  GenericSigningError,
833  SigningSuccess
834  };
835 
843  SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
844 
845 private:
846  Q_DISABLE_COPY(FormFieldSignature)
847 };
848 
854 bool POPPLER_QT5_EXPORT hasNSSSupport();
855 
861 QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
862 
868 QString POPPLER_QT5_EXPORT getNSSDir();
869 
875 void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
876 
882 void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
883 }
884 
885 #endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition: poppler-annotation.h:481
Definition: poppler-form.h:495
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.
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:512
PublicKeyType
The algorithm of public key.
Definition: poppler-form.h:501
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:529
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition: poppler-form.h:232
ButtonType buttonType() const
The particular type of the button field.
QString caption() const
The caption to be used for the button.
QList< int > siblings() const
The list with the IDs of siblings (ie, buttons belonging to the same group as the current one.
void setIcon(const FormFieldIcon &icon)
Sets a new icon for the button, it has to be a icon returned by FormFieldButton::icon.
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:238
@ CheckBox
A check box.
Definition: poppler-form.h:240
@ Push
A simple push button.
Definition: poppler-form.h:239
bool state() const
The state of the button.
A form field that represents a choice field.
Definition: poppler-form.h:395
QList< int > currentChoices() const
The currently selected choices.
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:401
@ ComboBox
A simple singleline text field.
Definition: poppler-form.h:402
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.
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.
QVector< QPair< QString, QString > > choicesWithExportValues() const
The possible choices of the choice 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:771
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:778
@ UnknownSignatureType
Definition: poppler-form.h:782
SigningResult
Definition: poppler-form.h:830
@ FieldAlreadySigned
Trying to sign a field that is already signed.
Definition: poppler-form.h:831
ValidateOptions
The validation options of this signature.
Definition: poppler-form.h:790
A form field that represents a text input.
Definition: poppler-form.h:304
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:310
@ Multiline
A multiline text field.
Definition: poppler-form.h:312
@ Normal
A simple singleline text field.
Definition: poppler-form.h:311
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:91
bool isPrintable() const
Whether this field is printable.
int id() const
The ID of the field.
Link * additionalAction(AdditionalActionType type) const
Returns a given form additional action.
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.
Link * additionalAction(Annotation::AdditionalActionType type) const
Returns a given widget annotation additional action.
void setPrintable(bool value)
Set whether this field is printable.
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.
Link * activationAction() const
The activation action of this form field.
virtual FormType type() const =0
The type of the field.
AdditionalActionType
Describes the flags from the form 'AA' dictionary.
Definition: poppler-form.h:195
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition: poppler-form.h:199
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition: poppler-form.h:197
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition: poppler-form.h:198
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition: poppler-form.h:196
FormType
The different types of form field.
Definition: poppler-form.h:100
@ FormButton
A button field. See ButtonType.
Definition: poppler-form.h:101
@ FormText
A text field. See TextType.
Definition: poppler-form.h:102
@ FormChoice
A single choice field. See ChoiceType.
Definition: poppler-form.h:103
Holds data for a new signature.
Definition: poppler-qt5.h:2195
A page in a document.
Definition: poppler-qt5.h:434
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
@ 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 Qt5 binding.
Definition: poppler-annotation.h:50
QString getNSSDir()
Gets the current NSS CertDB directory.
void setNSSPasswordCallback(const std::function< char *(const char *)> &f)
Sets the callback for NSS password requests.
void setNSSDir(const QString &pathURL)
Set a custom NSS CertDB directory.
bool hasNSSSupport()
Returns is poppler was compiled with NSS support.
QVector< CertificateInfo > getAvailableSigningCertificates()
Return vector of suitable signing certificates.