dev/null                                           |binary
 sdext/Package_pdfimport_xpdfimport.mk              |    2 --
 sdext/source/pdfimport/wrapper/wrapper.cxx         |   17 +++--------------
 sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx |   21 ++++++---------------
 4 files changed, 9 insertions(+), 31 deletions(-)

New commits:
commit cc895651302dc42dfb91ef06c41872d9dae8dd44
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Apr 4 09:41:50 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Apr 4 08:29:35 2024 +0200

    Related: tdf#160260 Drop xpdfimport.err.pdf, let PDF import return false
    
    The problem was, that upon any error in opening a PDF, out Poppler
    wrapper used another bundled document, with a single page with a static
    text "This PDF file is encrypted and can't be opened.". That happened
    regardless of the nature of the problem (it could be an IO problem, as
    in tdf#160260, or other things from Poppler's poppler/ErrorCodes.h).
    For automated import (command line or API), it meant that it was not
    possible to detect the failure.
    
    This replaces this strange mechanism with a normal error reporting. For
    now, a simple "general input/output error" will be reported; but it is
    possible to use interaction handler to show details (see comment in
    xpdf_ImportFromFile).
    
    Change-Id: I30493118fc5dd0b1c62cae7718acfe95bb4b13b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165771
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sdext/Package_pdfimport_xpdfimport.mk 
b/sdext/Package_pdfimport_xpdfimport.mk
index 9f08e05f4773..c1c82814aa77 100644
--- a/sdext/Package_pdfimport_xpdfimport.mk
+++ b/sdext/Package_pdfimport_xpdfimport.mk
@@ -9,6 +9,4 @@
 
 $(eval $(call gb_Package_Package,sdext_pdfimport_pdf,$(SRCDIR)/sdext))
 
-$(eval $(call 
gb_Package_add_file,sdext_pdfimport_pdf,$(LIBO_SHARE_FOLDER)/xpdfimport/xpdfimport_err.pdf,source/pdfimport/dialogs/xpdfimport_err.pdf))
-
 # vim: set noet sw=4 ts=4:
diff --git a/sdext/source/pdfimport/dialogs/xpdfimport_err.pdf 
b/sdext/source/pdfimport/dialogs/xpdfimport_err.pdf
deleted file mode 100644
index dc0f9292c680..000000000000
Binary files a/sdext/source/pdfimport/dialogs/xpdfimport_err.pdf and /dev/null 
differ
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx 
b/sdext/source/pdfimport/wrapper/wrapper.cxx
index d99103b9867a..6a17d295eae1 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -1079,24 +1079,12 @@ bool xpdf_ImportFromFile(const OUString& rURL,
     OUString converterURL("$BRAND_BASE_DIR/" LIBO_BIN_FOLDER "/xpdfimport");
     rtl::Bootstrap::expandMacros(converterURL); //TODO: detect failure
 
-    // Determine pathname of xpdfimport_err.pdf:
-    OUString errPathname("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER 
"/xpdfimport/xpdfimport_err.pdf");
-    rtl::Bootstrap::expandMacros(errPathname); //TODO: detect failure
-    if (osl::FileBase::getSystemPathFromFileURL(errPathname, errPathname)
-        != osl::FileBase::E_None)
-    {
-        SAL_WARN(
-            "sdext.pdfimport",
-            "getSystemPathFromFileURL(" << errPathname << ") failed");
-        return false;
-    }
-
     // spawn separate process to keep LGPL/GPL code apart.
 
     OUString aOptFlag("-o");
-    rtl_uString*  args[] = { aSysUPath.pData, errPathname.pData,
+    rtl_uString*  args[] = { aSysUPath.pData,
                              aOptFlag.pData, rFilterOptions.pData };
-    sal_Int32 nArgs = rFilterOptions.isEmpty() ? 2 : 4;
+    sal_Int32 nArgs = rFilterOptions.isEmpty() ? std::size(args) - 2 : 
std::size(args);
 
     oslProcess    aProcess;
     oslFileHandle pIn  = nullptr;
@@ -1206,6 +1194,7 @@ bool xpdf_ImportFromFile(const OUString& rURL,
                     "sdext.pdfimport",
                     "getProcessInfo of " << converterURL
                         << " failed with exit code " << info.Code);
+                // TODO: use xIHdl and/or exceptions to inform the user; see 
poppler/ErrorCodes.h
                 bRet = false;
             }
         }
diff --git a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx 
b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
index 383f6810b2a2..ebed120708cc 100644
--- a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
@@ -152,7 +152,6 @@ int main(int argc, char **argv)
 
     // PDFDoc takes over ownership for all strings below
     GooString* pFileName = new GooString(myStringToStdString(argv[1]));
-    GooString* pErrFileName = new GooString(myStringToStdString(argv[2]));
 
     // check for password string(s)
     GooString* pOwnerPasswordStr( aPwBuf[0] != 0
@@ -182,30 +181,22 @@ int main(int argc, char **argv)
     PDFDoc aDoc( std::make_unique<GooString>(pFileName),
                  std::optional<GooString>(pOwnerPasswordStr),
                  std::optional<GooString>(pUserPasswordStr) );
-
-    PDFDoc aErrDoc( std::make_unique<GooString>(pErrFileName),
-                 std::optional<GooString>(pOwnerPasswordStr),
-                 std::optional<GooString>(pUserPasswordStr) );
 #else
     PDFDoc aDoc( pFileName,
                  pOwnerPasswordStr,
                  pUserPasswordStr );
-
-    PDFDoc aErrDoc( pErrFileName,
-                 pOwnerPasswordStr,
-                 pUserPasswordStr );
 #endif
 
-    // Check various permissions for aDoc.
-    PDFDoc &rDoc = aDoc.isOk()? aDoc: aErrDoc;
+    if (!aDoc.isOk())
+        return aDoc.getErrorCode();
 
-    pdfi::PDFOutDev aOutDev(&rDoc);
+    pdfi::PDFOutDev aOutDev(&aDoc);
     if (options == TO_STRING_VIEW("SkipImages")) {
             aOutDev.setSkipImages(true);
     }
 
     // tell the receiver early - needed for proper progress calculation
-    const int nPages = rDoc.isOk()? rDoc.getNumPages(): 0;
+    const int nPages = aDoc.getNumPages();
     pdfi::PDFOutDev::setPageNum(nPages);
 
     // virtual resolution of the PDF OutputDev in dpi
@@ -214,12 +205,12 @@ int main(int argc, char **argv)
     // do the conversion
     for (int i = 1; i <= nPages; ++i)
     {
-        rDoc.displayPage(&aOutDev,
+        aDoc.displayPage(&aOutDev,
                 i,
                 PDFI_OUTDEV_RESOLUTION,
                 PDFI_OUTDEV_RESOLUTION,
                 0, true, true, true);
-        rDoc.processLinks(&aOutDev, i);
+        aDoc.processLinks(&aOutDev, i);
     }
 
     return 0;

Reply via email to