From 6d8ce5b1d608d2e8e4dc36dec43328e9380a8bc9 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Thu, 24 May 2018 23:01:15 -0400 Subject: pdf: preserve the original page dimensions on import Also allow for rendering PDFs to images at custom resolution, instead of hard-coded (old hard-coded value of 96 dpi is now default arguments). Change-Id: Ia5b52f72d6ce7130a2debc7c6f86504aa041bdc8 Reviewed-on: https://gerrit.libreoffice.org/54786 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky --- sd/source/filter/pdf/sdpdffilter.cxx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sd') diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index a52a6aea3353..ad00ae0ba0ba 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -100,9 +100,12 @@ bool SdPdfFilter::Import() const OUString aFileName( mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE)); + // Rendering resolution. + const double dResolutionDPI = 96.; + uno::Sequence aPdfData; std::vector aBitmaps; - if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData) == 0) + if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData, dResolutionDPI) == 0) return false; // Prepare the link with the PDF stream. @@ -129,8 +132,12 @@ bool SdPdfFilter::Import() // Create the page and insert the Graphic. SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard); - const Size aGrfSize(OutputDevice::LogicToLogic( - aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM))); + Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), + MapMode(MapUnit::Map100thMM))); + + // Resize to original size based on 72 dpi to preserve page size. + aGrfSize = Size(aGrfSize.Width() * 72. / dResolutionDPI, + aGrfSize.Height() * 72. / dResolutionDPI); // Make the page size match the rendered image. pPage->SetSize(aGrfSize); -- cgit