summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-03-13 23:55:26 -0400
committerJan Holesovsky <kendy@collabora.com>2018-06-07 10:45:18 +0200
commit7939efc7136987fad348baca2cd686a00aee73cd (patch)
treec142fd2770bb97d83fa91b971e370cf3b4acc73c
parent9b11fdd36ec80f9d1ae0a05455745361e0ce9ced (diff)
sd: import PDFs as images using Pdfium new SdPdfFilter
LOK now opens PDFs as images using Pdfium, which has a superior accuracy and support to poppler, the default pdf reader. Change-Id: Ifbbecf7f048f001836fb98886705cba47e6bed4e
-rw-r--r--include/vcl/graph.hxx6
-rw-r--r--include/vcl/pdfread.hxx (renamed from vcl/inc/pdfread.hxx)3
-rw-r--r--sd/Library_sd.mk1
-rw-r--r--sd/inc/sdpdffilter.hxx40
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx171
-rw-r--r--sd/source/ui/docshell/docshel4.cxx9
-rw-r--r--sdext/CppunitTest_sdext_pdfimport.mk1
-rw-r--r--sdext/Executable_pdf2xml.mk1
-rw-r--r--sdext/Executable_pdfunzip.mk1
-rw-r--r--sdext/Library_pdfimport.mk1
-rw-r--r--sdext/source/pdfimport/wrapper/wrapper.cxx40
-rw-r--r--sfx2/source/doc/objstor.cxx7
-rw-r--r--svx/source/xml/xmlgrhlp.cxx1
-rw-r--r--vcl/inc/impgraph.hxx9
-rw-r--r--vcl/source/filter/graphicfilter.cxx2
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx27
-rw-r--r--vcl/source/gdi/graph.cxx10
-rw-r--r--vcl/source/gdi/impgraph.cxx2
18 files changed, 298 insertions, 34 deletions
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 847e20e202ab..cd2e48c273f7 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -231,10 +231,14 @@ public:
const VectorGraphicDataPtr& getVectorGraphicData() const;
void setPdfData(const std::shared_ptr<css::uno::Sequence<sal_Int8>>& rPdfData);
- void setPdfData(const css::uno::Sequence<sal_Int8>& rPdfData) { setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(rPdfData)); }
std::shared_ptr<css::uno::Sequence<sal_Int8>> getPdfData() const;
bool hasPdfData() const;
+ /// Set the page number of the multi-page source this Graphic is rendered from.
+ void setPageNumber(sal_Int32 nPageNumber);
+ /// Get the page number of the multi-page source this Graphic is rendered from.
+ sal_Int32 getPageNumber() const;
+
static css::uno::Sequence<sal_Int8> getUnoTunnelId();
};
diff --git a/vcl/inc/pdfread.hxx b/include/vcl/pdfread.hxx
index 2e16e4474c17..9f2797768646 100644
--- a/vcl/inc/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -36,6 +36,9 @@ VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN,
sal_uInt64 nSize = STREAM_SEEK_TO_END);
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
+
+VCL_DLLPUBLIC size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
+ css::uno::Sequence<sal_Int8>& rPdfData);
}
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index ae4592e340f3..7e165c3ec7a6 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/filter/html/buttonset \
sd/source/filter/html/htmlex \
sd/source/filter/html/sdhtmlfilter \
+ sd/source/filter/pdf/sdpdffilter \
sd/source/filter/sdfilter \
sd/source/filter/sdpptwrp \
sd/source/filter/xml/sdtransform \
diff --git a/sd/inc/sdpdffilter.hxx b/sd/inc/sdpdffilter.hxx
new file mode 100644
index 000000000000..8971eb745179
--- /dev/null
+++ b/sd/inc/sdpdffilter.hxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SD_INC_SDPDFIUMFILTER_HXX
+#define INCLUDED_SD_INC_SDPDFIUMFILTER_HXX
+
+#include <com/sun/star/drawing/XShape.hpp>
+
+#include "sdfilter.hxx"
+
+class SdPdfFilter : public SdFilter
+{
+public:
+ SdPdfFilter(SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell);
+
+ virtual ~SdPdfFilter() override;
+
+ bool Import();
+ bool Export() override;
+};
+
+#endif // INCLUDED_SD_INC_SDGRFFILTER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
new file mode 100644
index 000000000000..ede9f1aaf836
--- /dev/null
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <com/sun/star/drawing/GraphicExportFilter.hpp>
+#include <com/sun/star/graphic/GraphicProvider.hpp>
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
+#include <com/sun/star/graphic/GraphicType.hpp>
+#include <com/sun/star/ucb/SimpleFileAccess.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
+
+#include <unotools/localfilehelper.hxx>
+#include <vcl/errinf.hxx>
+#include <vcl/weld.hxx>
+#include <vcl/metaact.hxx>
+#include <vcl/virdev.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/frame.hxx>
+#include <svx/svdograf.hxx>
+#include <svx/svdpagv.hxx>
+
+#include <strings.hrc>
+#include <DrawViewShell.hxx>
+#include <DrawDocShell.hxx>
+#include <ClientView.hxx>
+#include <FrameView.hxx>
+
+#include <comphelper/anytostring.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <unotools/pathoptions.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <svx/xoutbmp.hxx>
+
+#include <sdpage.hxx>
+#include <drawdoc.hxx>
+#include <sdresid.hxx>
+#include <sdpdffilter.hxx>
+#include <ViewShellBase.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/PropertyValues.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/drawing/XDrawView.hpp>
+#include <DrawController.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/drawing/XShape.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/XInteractionRequest.hpp>
+#include <com/sun/star/drawing/GraphicFilterRequest.hpp>
+
+#include <vcl/bitmap.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/pdfread.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::graphic;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::ucb;
+using namespace com::sun::star::ui::dialogs;
+using namespace ::sfx2;
+
+SdPdfFilter::SdPdfFilter(SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell)
+ : SdFilter(rMedium, rDocShell)
+{
+}
+
+SdPdfFilter::~SdPdfFilter() {}
+
+bool SdPdfFilter::Import()
+{
+ //FIXME: Replace with parsing the PDF elements to allow editing.
+ //FIXME: For now we import as images for simplicity.
+
+ const OUString aFileName(
+ mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE));
+
+ uno::Sequence<sal_Int8> aPdfData;
+ std::vector<Bitmap> aBitmaps;
+ if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData) == 0)
+ return false;
+
+ // Prepare the link with the PDF stream.
+ const size_t nGraphicContentSize = aPdfData.getLength();
+ std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
+ memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize);
+ GfxLink aGfxLink(std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf);
+
+ mrDocument.CreateFirstPages();
+ for (int i = 0; i < aBitmaps.size() - 1; ++i)
+ {
+ mrDocument.DuplicatePage(0);
+ }
+
+ size_t nPageNumber = 0;
+ for (Bitmap& aBitmap : aBitmaps)
+ {
+ // Create the Graphic and link the original PDF stream.
+ Graphic aGraphic(aBitmap);
+ aGraphic.setPdfData(std::make_shared<uno::Sequence<sal_Int8>>(aPdfData));
+ aGraphic.SetLink(aGfxLink);
+
+ // Create the page and insert the Graphic.
+ SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
+ Point aPos;
+ Size aPagSize(pPage->GetSize());
+ Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(),
+ MapMode(MapUnit::Map100thMM)));
+
+ aPagSize.AdjustWidth(-(pPage->GetLeftBorder() + pPage->GetRightBorder()));
+ aPagSize.AdjustHeight(-(pPage->GetUpperBorder() + pPage->GetLowerBorder()));
+
+ // scale to fit page
+ if (((aGrfSize.Height() > aPagSize.Height()) || (aGrfSize.Width() > aPagSize.Width()))
+ && aGrfSize.Height() && aPagSize.Height())
+ {
+ double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height();
+ double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height();
+
+ // adjust graphic to page size (scales)
+ if (fGrfWH < fWinWH)
+ {
+ aGrfSize.setWidth(static_cast<long>(aPagSize.Height() * fGrfWH));
+ aGrfSize.setHeight(aPagSize.Height());
+ }
+ else if (fGrfWH > 0.F)
+ {
+ aGrfSize.setWidth(aPagSize.Width());
+ aGrfSize.setHeight(static_cast<long>(aPagSize.Width() / fGrfWH));
+ }
+ }
+
+ // set output rectangle for graphic
+ aPos.setX(((aPagSize.Width() - aGrfSize.Width()) >> 1) + pPage->GetLeftBorder());
+ aPos.setY(((aPagSize.Height() - aGrfSize.Height()) >> 1) + pPage->GetUpperBorder());
+
+ pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic,
+ ::tools::Rectangle(aPos, aGrfSize)));
+ }
+
+ return true;
+}
+
+bool SdPdfFilter::Export() { return false; }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx
index fb979fbfafa9..975b9af9dd56 100644
--- a/sd/source/ui/docshell/docshel4.cxx
+++ b/sd/source/ui/docshell/docshel4.cxx
@@ -79,6 +79,7 @@
#include <sdcgmfilter.hxx>
#include <sdgrffilter.hxx>
#include <sdhtmlfilter.hxx>
+#include <sdpdffilter.hxx>
#include <framework/FrameworkHelper.hxx>
#include <SdUnoDrawView.hxx>
@@ -489,12 +490,18 @@ bool DrawDocShell::ConvertFrom( SfxMedium& rMedium )
ErrCode nError = ERRCODE_NONE;
bRet = SdXMLFilter( rMedium, *this, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
}
- else if( aFilterName == "CGM - Computer Graphics Metafile" )
+ else if (aFilterName == "CGM - Computer Graphics Metafile")
{
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
bRet = SdCGMFilter( rMedium, *this ).Import();
}
+ else if (aFilterName == "draw_pdf_import")
+ {
+ mpDoc->CreateFirstPages();
+ mpDoc->StopWorkStartupDelay();
+ bRet = SdPdfFilter(rMedium, *this).Import();
+ }
else
{
mpDoc->CreateFirstPages();
diff --git a/sdext/CppunitTest_sdext_pdfimport.mk b/sdext/CppunitTest_sdext_pdfimport.mk
index f5fc54696329..87a917f8d81d 100644
--- a/sdext/CppunitTest_sdext_pdfimport.mk
+++ b/sdext/CppunitTest_sdext_pdfimport.mk
@@ -30,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sdext_pdfimport,\
sal \
test \
unotest \
+ tl \
xo \
))
diff --git a/sdext/Executable_pdf2xml.mk b/sdext/Executable_pdf2xml.mk
index c0f7fe6f5727..b2439164a1ed 100644
--- a/sdext/Executable_pdf2xml.mk
+++ b/sdext/Executable_pdf2xml.mk
@@ -30,6 +30,7 @@ $(eval $(call gb_Executable_use_libraries,pdf2xml,\
unotest \
cppuhelper \
sal \
+ tl \
xo \
))
diff --git a/sdext/Executable_pdfunzip.mk b/sdext/Executable_pdfunzip.mk
index 006f8e5c9430..1fcca8a863d7 100644
--- a/sdext/Executable_pdfunzip.mk
+++ b/sdext/Executable_pdfunzip.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_Executable_use_libraries,pdfunzip,\
cppuhelper \
sal \
vcl \
+ tl \
xo \
))
diff --git a/sdext/Library_pdfimport.mk b/sdext/Library_pdfimport.mk
index 465a406b66b8..f0d38e624d1d 100644
--- a/sdext/Library_pdfimport.mk
+++ b/sdext/Library_pdfimport.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,pdfimport,\
cppu \
cppuhelper \
sal \
+ tl \
xo \
))
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 7d3d68901e37..affd350a6a8c 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -35,6 +35,7 @@
#include <rtl/strbuf.hxx>
#include <rtl/byteseq.hxx>
+#include <comphelper/lok.hxx>
#include <comphelper/propertysequence.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/io/XInputStream.hpp>
@@ -71,6 +72,12 @@
#include <rtl/character.hxx>
+#include <vcl/bitmapaccess.hxx>
+#include <vcl/bitmap.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/pdfread.hxx>
+#include <vcl/pngwrite.hxx>
+
using namespace com::sun::star;
namespace pdfi
@@ -1001,20 +1008,12 @@ public:
}
};
-bool xpdf_ImportFromFile_Poppler(const OUString& aSysUPath,
- const ContentSinkSharedPtr& rSink,
- const uno::Reference<task::XInteractionHandler>& xIHdl,
- const bool bIsEncrypted,
- const OUString& aPwd,
- const uno::Reference<uno::XComponentContext>& xContext,
- const OUString& rFilterOptions);
-
-bool xpdf_ImportFromFile( const OUString& rURL,
- const ContentSinkSharedPtr& rSink,
- const uno::Reference< task::XInteractionHandler >& xIHdl,
- const OUString& rPwd,
- const uno::Reference< uno::XComponentContext >& xContext,
- const OUString& rFilterOptions )
+bool xpdf_ImportFromFile(const OUString& rURL,
+ const ContentSinkSharedPtr& rSink,
+ const uno::Reference<task::XInteractionHandler>& xIHdl,
+ const OUString& rPwd,
+ const uno::Reference<uno::XComponentContext>& xContext,
+ const OUString& rFilterOptions)
{
OSL_ASSERT(rSink);
@@ -1039,19 +1038,6 @@ bool xpdf_ImportFromFile( const OUString& rURL,
return false;
}
- return xpdf_ImportFromFile_Poppler(aSysUPath, rSink, xIHdl, bIsEncrypted, aPwd, xContext, rFilterOptions);
-}
-
-/// Parse PDf file using libpoppler, which is quite limited
-/// to be phased out in favor of pdfium.
-bool xpdf_ImportFromFile_Poppler(const OUString& aSysUPath,
- const ContentSinkSharedPtr& rSink,
- const uno::Reference<task::XInteractionHandler>& /*xIHdl*/,
- const bool bIsEncrypted,
- const OUString& aPwd,
- const uno::Reference<uno::XComponentContext>& xContext,
- const OUString& rFilterOptions)
-{
// Determine xpdfimport executable URL:
OUString converterURL("$BRAND_BASE_DIR/" LIBO_BIN_FOLDER "/xpdfimport");
rtl::Bootstrap::expandMacros(converterURL); //TODO: detect failure
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 61ab2371eb24..7eb2824636c7 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -101,6 +101,7 @@
#include <officecfg/Office/Common.hxx>
#include <osl/file.hxx>
#include <comphelper/scopeguard.hxx>
+#include <comphelper/lok.hxx>
#include <sfx2/signaturestate.hxx>
#include <sfx2/app.hxx>
@@ -746,9 +747,13 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
if ( GetError() == ERRCODE_NONE )
{
+ // Experimental PDF importing using PDFium. This is currently enabled for LOK only and
+ // we handle it not via XmlFilterAdaptor but a new SdPdfFiler.
+ const bool bPdfiumImport = comphelper::LibreOfficeKit::isActive() && pMedium->GetFilter() &&
+ (pMedium->GetFilter()->GetFilterName() == "draw_pdf_import");
pImpl->nLoadedFlags = SfxLoadedFlags::NONE;
pImpl->bModelInitialized = false;
- if ( pMedium->GetFilter() && ( pMedium->GetFilter()->GetFilterFlags() & SfxFilterFlags::STARONEFILTER ) )
+ if ( pMedium->GetFilter() && ( pMedium->GetFilter()->GetFilterFlags() & SfxFilterFlags::STARONEFILTER ) && !bPdfiumImport )
{
uno::Reference < beans::XPropertySet > xSet( GetModel(), uno::UNO_QUERY );
const OUString sLockUpdates("LockUpdates");
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index c261e8450858..718703487559 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -777,6 +777,7 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X
{
pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
}
+
rOutSavedMimeType = aMimeType;
bSuccess = (pStream->GetError() == ERRCODE_NONE);
}
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 052bed0924a5..36a888c01efc 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -88,10 +88,19 @@ private:
bool mbSwapOut;
bool mbDummyContext;
VectorGraphicDataPtr maVectorGraphicData;
+
+ /// The PDF stream from which this Graphic is rendered,
+ /// as converted (version downgraded) from the original,
+ /// which should be in GfxLink.
std::shared_ptr<css::uno::Sequence<sal_Int8>> mpPdfData;
std::unique_ptr<GraphicID> mpGraphicID;
GraphicExternalLink maGraphicExternalLink;
+ /// Used with GfxLink and/or PdfData when they store original media
+ /// which might be multi-page (PDF, f.e.) and we need to re-render
+ /// this Graphic (a page) from the source in GfxLink or PdfData.
+ sal_Int32 mnPageNumber;
+
std::chrono::high_resolution_clock::time_point maLastUsed;
bool mbPrepared;
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 1ba3d1d776ec..f713264cacfb 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -44,7 +44,7 @@
#include <vcl/wmf.hxx>
#include <vcl/settings.hxx>
#include "igif/gifread.hxx"
-#include <pdfread.hxx>
+#include <vcl/pdfread.hxx>
#include "jpeg/jpeg.hxx"
#include "ixbm/xbmread.hxx"
#include "ixpm/xpmread.hxx"
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index e3fe26332e2f..092be448b608 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -7,7 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <pdfread.hxx>
+#include <vcl/pdfread.hxx>
#include <config_features.h>
@@ -19,6 +19,7 @@
#include <vcl/graph.hxx>
#include <bitmapwriteaccess.hxx>
+#include <unotools/ucbstreamhelper.hxx>
using namespace com::sun::star;
@@ -237,9 +238,31 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
Bitmap aBitmap;
const bool bRet = ImportPDF(rStream, aBitmap, aPdfData);
rGraphic = aBitmap;
- rGraphic.setPdfData(aPdfData);
+ rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
return bRet;
}
+
+size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
+ css::uno::Sequence<sal_Int8>& rPdfData)
+{
+ std::unique_ptr<SvStream> xStream(
+ ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE));
+
+ if (generatePreview(*xStream, rBitmaps, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END, 0, -1) == 0)
+ return 0;
+
+ // Save the original PDF stream for later use.
+ SvMemoryStream aMemoryStream;
+ if (!getCompatibleStream(*xStream, aMemoryStream, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END))
+ return 0;
+
+ aMemoryStream.Seek(STREAM_SEEK_TO_END);
+ rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.Tell());
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength());
+
+ return rBitmaps.size();
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index 21b8a5713651..adc7d771c94d 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -574,6 +574,16 @@ bool Graphic::hasPdfData() const
return pPdfData && pPdfData->hasElements();
}
+void Graphic::setPageNumber(sal_Int32 nPageNumber)
+{
+ mxImpGraphic->mnPageNumber = nPageNumber;
+}
+
+sal_Int32 Graphic::getPageNumber() const
+{
+ return mxImpGraphic->mnPageNumber;
+}
+
OUString Graphic::getOriginURL() const
{
if (mxImpGraphic)
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 6e1691470ae1..5a063dc7c93f 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -43,7 +43,7 @@
#include <o3tl/make_unique.hxx>
#include <vcl/gdimetafiletools.hxx>
-#include <pdfread.hxx>
+#include <vcl/pdfread.hxx>
#define GRAPHIC_MTFTOBMP_MAXEXT 2048
#define GRAPHIC_STREAMBUFSIZE 8192UL