summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/pdfread.hxx13
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx13
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx34
3 files changed, 40 insertions, 20 deletions
diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index 8fd840685248..5d79c6d38146 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -21,11 +21,16 @@ VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap &rBitmap,
size_t nPageIndex,
css::uno::Sequence<sal_Int8> &rPdfFata,
sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN,
- sal_uInt64 nSize = STREAM_SEEK_TO_END);
-VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
+ sal_uInt64 nSize = STREAM_SEEK_TO_END,
+ const double fResolutionDPI = 96.);
-VCL_DLLPUBLIC size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
- css::uno::Sequence<sal_Int8>& rPdfData);
+VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic,
+ const double fResolutionDPI = 96.);
+
+VCL_DLLPUBLIC size_t ImportPDF(const OUString& rURL,
+ std::vector<Bitmap>& rBitmaps,
+ css::uno::Sequence<sal_Int8>& rPdfData,
+ const double fResolutionDPI = 96.);
}
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 4f7bd4ed0a6c..01e6ee5623de 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -99,9 +99,12 @@ bool SdPdfFilter::Import()
const OUString aFileName(
mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE));
+ // Rendering resolution.
+ const double dResolutionDPI = 96.;
+
uno::Sequence<sal_Int8> aPdfData;
std::vector<Bitmap> 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);
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 52d8e7277719..f61c4062fb37 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -58,15 +58,16 @@ int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void*
}
/// Convert to inch, then assume 96 DPI.
-double pointToPixel(double fPoint)
+inline double pointToPixel(const double fPoint, const double fResolutionDPI)
{
- return fPoint / 72 * 96;
+ return fPoint * fResolutionDPI / 72.;
}
/// Does PDF to bitmap conversion using pdfium.
size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps,
sal_uInt64 nPos, sal_uInt64 nSize,
- const size_t nFirstPage = 0, int nPages = 1)
+ const size_t nFirstPage = 0, int nPages = 1,
+ const double fResolutionDPI = 96.)
{
FPDF_LIBRARY_CONFIG aConfig;
aConfig.version = 2;
@@ -97,8 +98,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps,
break;
// Returned unit is points, convert that to pixel.
- const size_t nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage));
- const size_t nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage));
+ const size_t nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage), fResolutionDPI);
+ const size_t nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage), fResolutionDPI);
FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1);
if (!pPdfBitmap)
break;
@@ -201,13 +202,17 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream,
}
#else
size_t generatePreview(SvStream&, std::vector<Bitmap>&,
- sal_uInt64 nPos, sal_uInt64 nSize,
- size_t nFirstPage = 0, int nLastPage = 0)
+ sal_uInt64 nPos, sal_uInt64 nSize,
+ size_t nFirstPage = 0, int nLastPage = 0,
+ const double fResolutionDPI = 96.)
{
(void)rStream;
(void)rBitmap;
(void)nPos;
(void)nSize;
+ (void)nFirstPage;
+ (void)nLastPage;
+ (void)fResolutionDPI;
return false;
}
@@ -229,11 +234,12 @@ namespace vcl
bool ImportPDF(SvStream& rStream, Bitmap &rBitmap,
size_t nPageIndex,
css::uno::Sequence<sal_Int8> &rPdfData,
- sal_uInt64 nPos, sal_uInt64 nSize)
+ sal_uInt64 nPos, sal_uInt64 nSize,
+ const double fResolutionDPI)
{
// Get the preview of the first page.
std::vector<Bitmap> aBitmaps;
- if (generatePreview(rStream, aBitmaps, nPos, nSize, nPageIndex, 1) != 1 ||
+ if (generatePreview(rStream, aBitmaps, nPos, nSize, nPageIndex, 1, fResolutionDPI) != 1 ||
aBitmaps.empty())
return false;
@@ -253,11 +259,12 @@ bool ImportPDF(SvStream& rStream, Bitmap &rBitmap,
}
-bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
+bool ImportPDF(SvStream& rStream, Graphic& rGraphic,
+ const double fResolutionDPI)
{
uno::Sequence<sal_Int8> aPdfData;
Bitmap aBitmap;
- bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData);
+ bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData, fResolutionDPI);
rGraphic = aBitmap;
rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
rGraphic.setPageNumber(0); // We currently import only the first page.
@@ -265,12 +272,13 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
}
size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
- css::uno::Sequence<sal_Int8>& rPdfData)
+ css::uno::Sequence<sal_Int8>& rPdfData,
+ const double fResolutionDPI)
{
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)
+ if (generatePreview(*xStream, rBitmaps, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END, 0, -1, fResolutionDPI) == 0)
return 0;
// Save the original PDF stream for later use.