include/vcl/pdfread.hxx | 1 sd/source/filter/pdf/sdpdffilter.cxx | 41 +++++++++++++++++++++-------------- vcl/source/filter/ipdf/pdfread.cxx | 13 +++++++---- 3 files changed, 35 insertions(+), 20 deletions(-)
New commits: commit 0affb7652ac29134e4d41b58621aa7870f958107 Author: Caolán McNamara <[email protected]> AuthorDate: Thu Oct 9 13:15:10 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 10 09:29:21 2025 +0200 tweak pdf import to allow import from SvStream Change-Id: I3c602b01195b1a89072c22716ad9f241529b2a82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192117 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index b02b882d5474..4a426f1206f8 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -36,6 +36,7 @@ #include <com/sun/star/text/XText.hpp> #include <basegfx/polygon/b2dpolygontools.hxx> +#include <unotools/ucbstreamhelper.hxx> using namespace css; @@ -46,30 +47,27 @@ SdPdfFilter::SdPdfFilter(SfxMedium& rMedium, sd::DrawDocShell& rDocShell) SdPdfFilter::~SdPdfFilter() {} -bool SdPdfFilter::Import() +static bool ImportPDF(SvStream& rStream, SdDrawDocument& rDocument) { - const OUString aFileName( - mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE)); - std::vector<vcl::PDFGraphicResult> aGraphics; - if (vcl::ImportPDFUnloaded(aFileName, aGraphics) == 0) + if (vcl::ImportPDFUnloaded(rStream, aGraphics) == 0) return false; - bool bWasLocked = mrDocument.isLocked(); - mrDocument.setLock(true); - const bool bSavedUndoEnabled = mrDocument.IsUndoEnabled(); - mrDocument.EnableUndo(false); - mrDocument.setPDFDocument(true); + bool bWasLocked = rDocument.isLocked(); + rDocument.setLock(true); + const bool bSavedUndoEnabled = rDocument.IsUndoEnabled(); + rDocument.EnableUndo(false); + rDocument.setPDFDocument(true); - SdrModel& rModel = mrDocument; + SdrModel& rModel = rDocument; // Add as many pages as we need up-front. - mrDocument.CreateFirstPages(); + rDocument.CreateFirstPages(); sal_uInt16 nPageToDuplicate = 0; for (size_t i = 0; i < aGraphics.size() - 1; ++i) { // duplicating the last page is cheaper than repeatedly duplicating the first one - nPageToDuplicate = mrDocument.DuplicatePage(nPageToDuplicate); + nPageToDuplicate = rDocument.DuplicatePage(nPageToDuplicate); } for (vcl::PDFGraphicResult const& rPDFGraphicResult : aGraphics) @@ -81,7 +79,7 @@ bool SdPdfFilter::Import() assert(nPageNumber >= 0 && o3tl::make_unsigned(nPageNumber) < aGraphics.size()); // Create the page and insert the Graphic. - SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard); + SdPage* pPage = rDocument.GetSdPage(nPageNumber, PageKind::Standard); if (!pPage) // failed to duplicate page, out of memory? return false; @@ -229,11 +227,22 @@ bool SdPdfFilter::Import() } pPage->setLinkAnnotations(rPDFGraphicResult.GetLinksInfo()); } - mrDocument.setLock(bWasLocked); - mrDocument.EnableUndo(bSavedUndoEnabled); + rDocument.setLock(bWasLocked); + rDocument.EnableUndo(bSavedUndoEnabled); return true; } +bool SdPdfFilter::Import() +{ + const OUString aFileName( + mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE)); + + std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( + aFileName, StreamMode::READ | StreamMode::SHARE_DENYNONE)); + + return ImportPDF(*xStream, mrDocument); +} + bool SdPdfFilter::Export() { return false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 61fa90966601a765224e364b026f0cd2bae02aea Author: Caolán McNamara <[email protected]> AuthorDate: Thu Oct 9 13:07:08 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 10 09:29:13 2025 +0200 add a ImportPDFUnloaded variant for a SvStream Change-Id: I4bcf0fe17046bb4ac2e105d7310c3af64da521e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192116 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index 743fd68eebc0..9cfe64c3635f 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -106,6 +106,7 @@ public: /// Returns the number of pages read. VCL_DLLPUBLIC size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rGraphics); +VCL_DLLPUBLIC size_t ImportPDFUnloaded(SvStream& rStream, std::vector<PDFGraphicResult>& rGraphics); } #endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 1a9e9db42559..cc609f7cf40e 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -364,14 +364,12 @@ findLinks(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, } // end anonymous namespace -size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rGraphics) +size_t ImportPDFUnloaded(SvStream& rStream, std::vector<PDFGraphicResult>& rGraphics) { - std::unique_ptr<SvStream> xStream( - ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE)); bool bEncrypted; // Save the original PDF stream for later use. - BinaryDataContainer aDataContainer = vcl::pdf::createBinaryDataContainer(*xStream, bEncrypted); + BinaryDataContainer aDataContainer = vcl::pdf::createBinaryDataContainer(rStream, bEncrypted); if (aDataContainer.isEmpty()) return 0; @@ -425,6 +423,13 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG return rGraphics.size(); } + +size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rGraphics) +{ + std::unique_ptr<SvStream> xStream( + ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE)); + return ImportPDFUnloaded(*xStream, rGraphics); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
