[poppler] qt5/src qt6/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 5 14:01:36 UTC 2022


 qt5/src/poppler-pdf-converter.cc |   27 ++++++++++++++++++++++++++-
 qt5/src/poppler-qt5.h            |   20 ++++++++++++++++++++
 qt6/src/poppler-pdf-converter.cc |   27 ++++++++++++++++++++++++++-
 qt6/src/poppler-qt6.h            |   20 ++++++++++++++++++++
 4 files changed, 92 insertions(+), 2 deletions(-)

New commits:
commit 902ef7b20b7b7b6d434e45b3f06d2ac8b3e8ba54
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Dec 29 19:26:15 2021 +0100

    qt: Allow passing the document password when signing
    
    We need it since in the middle of the signing process we need to reopen
    the document we just created to do some final modifications

diff --git a/qt5/src/poppler-pdf-converter.cc b/qt5/src/poppler-pdf-converter.cc
index 5b2e7c03..28256dc7 100644
--- a/qt5/src/poppler-pdf-converter.cc
+++ b/qt5/src/poppler-pdf-converter.cc
@@ -134,9 +134,11 @@ bool PDFConverter::sign(const NewSignatureData &data)
     std::unique_ptr<GooString> gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
     const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
     const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
+    const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
+    const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
     return doc->sign(d->outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), data.password().toUtf8().constData(), QStringToGooString(data.fieldPartialName()), data.page() + 1,
                      boundaryToPdfRectangle(destPage, data.boundingRectangle(), Annotation::FixedRotation), *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(),
-                     convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get());
+                     convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), "" /*imagepath*/, ownerPwd.get(), userPwd.get());
 }
 
 struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
@@ -159,6 +161,9 @@ struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
     QColor backgroundColor = QColor(240, 240, 240);
 
     QString partialName = QUuid::createUuid().toString();
+
+    QByteArray documentOwnerPassword;
+    QByteArray documentUserPassword;
 };
 
 PDFConverter::NewSignatureData::NewSignatureData() : d(new NewSignatureDataPrivate()) { }
@@ -317,4 +322,24 @@ void PDFConverter::NewSignatureData::setFieldPartialName(const QString &name)
 {
     d->partialName = name;
 }
+
+QByteArray PDFConverter::NewSignatureData::documentOwnerPassword() const
+{
+    return d->documentOwnerPassword;
+}
+
+void PDFConverter::NewSignatureData::setDocumentOwnerPassword(const QByteArray &password)
+{
+    d->documentOwnerPassword = password;
+}
+
+QByteArray PDFConverter::NewSignatureData::documentUserPassword() const
+{
+    return d->documentUserPassword;
+}
+
+void PDFConverter::NewSignatureData::setDocumentUserPassword(const QByteArray &password)
+{
+    d->documentUserPassword = password;
+}
 }
diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
index f307a26e..19d30cac 100644
--- a/qt5/src/poppler-qt5.h
+++ b/qt5/src/poppler-qt5.h
@@ -2291,6 +2291,26 @@ public:
         QString fieldPartialName() const;
         void setFieldPartialName(const QString &name);
 
+        /**
+         * Document owner password (needed if the document that is being signed is password protected)
+         *
+         * Default: no password
+         *
+         * \since 22.02
+         */
+        QByteArray documentOwnerPassword() const;
+        void setDocumentOwnerPassword(const QByteArray &password);
+
+        /**
+         * Document user password (needed if the document that is being signed is password protected)
+         *
+         * Default: no password
+         *
+         * \since 22.02
+         */
+        QByteArray documentUserPassword() const;
+        void setDocumentUserPassword(const QByteArray &password);
+
     private:
         struct NewSignatureDataPrivate;
         NewSignatureDataPrivate *const d;
diff --git a/qt6/src/poppler-pdf-converter.cc b/qt6/src/poppler-pdf-converter.cc
index 1c77146d..2d6c90a1 100644
--- a/qt6/src/poppler-pdf-converter.cc
+++ b/qt6/src/poppler-pdf-converter.cc
@@ -134,9 +134,11 @@ bool PDFConverter::sign(const NewSignatureData &data)
     std::unique_ptr<GooString> gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
     const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
     const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
+    const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
+    const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
     return doc->sign(d->outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), data.password().toUtf8().constData(), QStringToGooString(data.fieldPartialName()), data.page() + 1,
                      boundaryToPdfRectangle(destPage, data.boundingRectangle(), Annotation::FixedRotation), *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(),
-                     convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get());
+                     convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), "" /*imagepath*/, ownerPwd.get(), userPwd.get());
 }
 
 struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
@@ -159,6 +161,9 @@ struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
     QColor backgroundColor = QColor(240, 240, 240);
 
     QString partialName = QUuid::createUuid().toString();
+
+    QByteArray documentOwnerPassword;
+    QByteArray documentUserPassword;
 };
 
 PDFConverter::NewSignatureData::NewSignatureData() : d(new NewSignatureDataPrivate()) { }
@@ -317,4 +322,24 @@ void PDFConverter::NewSignatureData::setFieldPartialName(const QString &name)
 {
     d->partialName = name;
 }
+
+QByteArray PDFConverter::NewSignatureData::documentOwnerPassword() const
+{
+    return d->documentOwnerPassword;
+}
+
+void PDFConverter::NewSignatureData::setDocumentOwnerPassword(const QByteArray &password)
+{
+    d->documentOwnerPassword = password;
+}
+
+QByteArray PDFConverter::NewSignatureData::documentUserPassword() const
+{
+    return d->documentUserPassword;
+}
+
+void PDFConverter::NewSignatureData::setDocumentUserPassword(const QByteArray &password)
+{
+    d->documentUserPassword = password;
+}
 }
diff --git a/qt6/src/poppler-qt6.h b/qt6/src/poppler-qt6.h
index c59ffe4d..2ae36ab8 100644
--- a/qt6/src/poppler-qt6.h
+++ b/qt6/src/poppler-qt6.h
@@ -2067,6 +2067,26 @@ public:
         QString fieldPartialName() const;
         void setFieldPartialName(const QString &name);
 
+        /**
+         * Document owner password (needed if the document that is being signed is password protected)
+         *
+         * Default: no password
+         *
+         * \since 22.02
+         */
+        QByteArray documentOwnerPassword() const;
+        void setDocumentOwnerPassword(const QByteArray &password);
+
+        /**
+         * Document user password (needed if the document that is being signed is password protected)
+         *
+         * Default: no password
+         *
+         * \since 22.02
+         */
+        QByteArray documentUserPassword() const;
+        void setDocumentUserPassword(const QByteArray &password);
+
     private:
         struct NewSignatureDataPrivate;
         NewSignatureDataPrivate *const d;


More information about the poppler mailing list