include/vcl/filter/PDFiumLibrary.hxx |    3 ++-
 vcl/source/filter/ipdf/pdfcompat.cxx |    3 ++-
 vcl/source/pdf/PDFiumLibrary.cxx     |    8 +++++---
 3 files changed, 9 insertions(+), 5 deletions(-)

New commits:
commit aa5629a48b0c181e02c26f6f0f25d99c5797bffa
Author:     Dr. David Alan Gilbert <d...@treblig.org>
AuthorDate: Wed May 21 01:03:25 2025 +0100
Commit:     David Gilbert <d...@treblig.org>
CommitDate: Fri Jun 13 22:04:30 2025 +0200

    tdf#162826: vcl: pdfium wrapper: add 'remove security' option
    
    When PDFium loads a file, and then resaves it, by default
    it keeps the password used to load it.
    Add a flag to lose the password, and use it in pdfcompat.
    
    Change-Id: Id73732944cb981a308f5dff9b2f4cd193c9e011c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185581
    Tested-by: Jenkins
    Reviewed-by: David Gilbert <freedesk...@treblig.org>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx 
b/include/vcl/filter/PDFiumLibrary.hxx
index 1f20beab475f..efa4cd516674 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -274,7 +274,8 @@ public:
     virtual int getSignatureCount() = 0;
     virtual int getFileVersion() = 0;
     virtual int getAttachmentCount() = 0;
-    virtual bool saveWithVersion(SvMemoryStream& rStream, int nFileVersion) = 
0;
+    virtual bool saveWithVersion(SvMemoryStream& rStream, int nFileVersion, 
bool bRemoveSecurity)
+        = 0;
 
     virtual std::unique_ptr<PDFiumPage> openPage(int nIndex) = 0;
     virtual std::unique_ptr<PDFiumSignature> getSignature(int nIndex) = 0;
diff --git a/vcl/source/filter/ipdf/pdfcompat.cxx 
b/vcl/source/filter/ipdf/pdfcompat.cxx
index 850504c9b68d..124aa4e9acee 100644
--- a/vcl/source/filter/ipdf/pdfcompat.cxx
+++ b/vcl/source/filter/ipdf/pdfcompat.cxx
@@ -99,7 +99,8 @@ bool convertToHighestSupported(
 
         SAL_INFO("vcl.filter", "convertToHighestSupported do save");
         // 16 means PDF-1.6.
-        if (!pPdfDocument->saveWithVersion(aSaved, 16))
+        // true means 'remove security' - i.e. not passworded
+        if (!pPdfDocument->saveWithVersion(aSaved, 16, true))
             return false;
     } while (bAgain);
 
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 908206395fb7..4ca6fb3c1bd6 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -573,7 +573,7 @@ public:
     int getSignatureCount() override;
     int getAttachmentCount() override;
     int getFileVersion() override;
-    bool saveWithVersion(SvMemoryStream& rStream, int nFileVersion) override;
+    bool saveWithVersion(SvMemoryStream& rStream, int nFileVersion, bool 
bRemoveSecurity) override;
 
     std::unique_ptr<PDFiumPage> openPage(int nIndex) override;
     std::unique_ptr<PDFiumSignature> getSignature(int nIndex) override;
@@ -962,12 +962,14 @@ int PDFiumDocumentImpl::getFileVersion()
     return nFileVersion;
 }
 
-bool PDFiumDocumentImpl::saveWithVersion(SvMemoryStream& rStream, int 
nFileVersion)
+bool PDFiumDocumentImpl::saveWithVersion(SvMemoryStream& rStream, int 
nFileVersion,
+                                         bool bRemoveSecurity)
 {
     CompatibleWriter aWriter(rStream);
     aWriter.version = 1;
     aWriter.WriteBlock = &CompatibleWriterCallback;
-    if (!FPDF_SaveWithVersion(mpPdfDocument, &aWriter, 0, nFileVersion))
+    if (!FPDF_SaveWithVersion(mpPdfDocument, &aWriter, bRemoveSecurity ? 
FPDF_REMOVE_SECURITY : 0,
+                              nFileVersion))
     {
         return false;
     }

Reply via email to