sw/source/uibase/uiview/view2.cxx    |    3 +-
 vcl/source/filter/ipdf/pdfcompat.cxx |   43 ++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 6 deletions(-)

New commits:
commit 87ba2a139af771e459f08ceccc8b52f7f69b926d
Author:     Dr. David Alan Gilbert <d...@treblig.org>
AuthorDate: Tue May 20 01:20:42 2025 +0100
Commit:     David Gilbert <d...@treblig.org>
CommitDate: Fri Jun 13 22:04:10 2025 +0200

    tdf#162826: sw: Get InteractionHandler
    
    Writer takes a different path, so also fetch the InteractionHandler
    here.
    
    Change-Id: Icac72f523d8043dc3e7c62f5403a3d5363786984
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185546
    Tested-by: Jenkins
    Reviewed-by: David Gilbert <freedesk...@treblig.org>

diff --git a/sw/source/uibase/uiview/view2.cxx 
b/sw/source/uibase/uiview/view2.cxx
index f3130d93fb3e..b3332fd34fc9 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -327,7 +327,8 @@ ErrCode SwView::InsertGraphic( const OUString &rPath, const 
OUString &rFilter,
             SfxLokHelper::sendNetworkAccessError("insert");
     }
 
-    aResult = GraphicFilter::LoadGraphic( rPath, rFilter, aGraphic, pFilter );
+    auto xHandler(GetDocShell()->GetMedium()->GetInteractionHandler());
+    aResult = GraphicFilter::LoadGraphic(rPath, rFilter, aGraphic, pFilter, 
nullptr, xHandler);
 
     if( ERRCODE_NONE == aResult )
     {
commit 8521a05c3aa2266106e2eb1c3084518fe272630e
Author:     Dr. David Alan Gilbert <d...@treblig.org>
AuthorDate: Mon May 19 02:13:09 2025 +0100
Commit:     David Gilbert <d...@treblig.org>
CommitDate: Fri Jun 13 22:04:00 2025 +0200

    tdf#162826: Ask for pass in convertToHighestSupported
    
    If PDFIum can't open the PDF because it's password protected,
    ask the user for the password.
    
    Change-Id: I86c3d5df09b30c42a6cd6fd785df5a41e7760be7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185490
    Tested-by: Jenkins
    Reviewed-by: David Gilbert <freedesk...@treblig.org>

diff --git a/vcl/source/filter/ipdf/pdfcompat.cxx 
b/vcl/source/filter/ipdf/pdfcompat.cxx
index 727c4d7e1fbc..850504c9b68d 100644
--- a/vcl/source/filter/ipdf/pdfcompat.cxx
+++ b/vcl/source/filter/ipdf/pdfcompat.cxx
@@ -12,6 +12,7 @@
 #include <o3tl/string_view.hxx>
 #include <tools/solar.h>
 #include <vcl/filter/PDFiumLibrary.hxx>
+#include <vcl/pdf/pwdinteract.hxx>
 #include <sal/log.hxx>
 
 namespace vcl::pdf
@@ -44,7 +45,7 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, 
sal_uInt64 nSize)
 
 bool convertToHighestSupported(
     SvStream& rInStream, SvStream& rOutStream,
-    const css::uno::Reference<css::task::XInteractionHandler>& 
/*xInteractionHandler*/)
+    const css::uno::Reference<css::task::XInteractionHandler>& 
xInteractionHandler)
 {
     sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN;
     sal_uInt64 nSize = STREAM_SEEK_TO_END;
@@ -59,19 +60,51 @@ bool convertToHighestSupported(
     aInBuffer.WriteStream(rInStream, nSize);
 
     SvMemoryStream aSaved;
+    bool bAgain = false;
+    OUString aPassword;
+    do
     {
         // Load the buffer using pdfium.
+        OString aIsoPwd = OUStringToOString(aPassword, 
RTL_TEXTENCODING_ISO_8859_1);
+
         std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
-            = pPdfium->openDocument(aInBuffer.GetData(), aInBuffer.GetSize(), 
OString());
-        if (!pPdfDocument)
+            = pPdfium->openDocument(aInBuffer.GetData(), aInBuffer.GetSize(), 
aIsoPwd);
+        auto nPdfiumErr = pPdfium->getLastErrorCode();
+        if (!pPdfDocument && nPdfiumErr != vcl::pdf::PDFErrorType::Password)
+        {
+            SAL_WARN("vcl.filter",
+                     "convertToHighestSupported pdfium err: " << 
pPdfium->getLastError());
             return false;
-
+        }
+
+        if (!pPdfDocument && nPdfiumErr == vcl::pdf::PDFErrorType::Password)
+        {
+            if (!xInteractionHandler || !xInteractionHandler.is())
+            {
+                SAL_WARN("vcl.filter", "convertToHighestSupported no Int 
handler for pass");
+                return false;
+            }
+
+            // We don't have a filename for the GUI here
+            bAgain = vcl::pdf::getPassword(xInteractionHandler, aPassword, 
!bAgain, u"PDF"_ustr);
+            SAL_INFO("vcl.filter", "convertToHighestSupported pass result: " 
<< bAgain);
+            if (!bAgain)
+            {
+                SAL_WARN("vcl.filter", "convertToHighestSupported Failed to 
get pass");
+                return false;
+            }
+            continue;
+        }
+        bAgain = false;
+
+        SAL_INFO("vcl.filter", "convertToHighestSupported do save");
         // 16 means PDF-1.6.
         if (!pPdfDocument->saveWithVersion(aSaved, 16))
             return false;
-    }
+    } while (bAgain);
 
     aSaved.Seek(STREAM_SEEK_TO_BEGIN);
+    SAL_INFO("vcl.filter", "convertToHighestSupported do write");
     rOutStream.WriteStream(aSaved);
 
     return rOutStream.good();

Reply via email to