From 2daf1a6d53832d3b5937d7d813332a1c3bb53ecc Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 16 Jul 2023 18:56:50 +0200 Subject: [PATCH] Issue #59: Set physical dimensions of images in the rasterizer --- Pdf4QtLib/sources/pdfrenderer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Pdf4QtLib/sources/pdfrenderer.cpp b/Pdf4QtLib/sources/pdfrenderer.cpp index f22bc02..ecef9ad 100644 --- a/Pdf4QtLib/sources/pdfrenderer.cpp +++ b/Pdf4QtLib/sources/pdfrenderer.cpp @@ -317,6 +317,14 @@ QImage PDFRasterizer::render(PDFInteger pageIndex, image.convertTo(QImage::Format_ARGB32_Premultiplied); } + // Calculate image DPI + QSizeF rotatedSizeInMeters = page->getRotatedMediaBoxMM().size() / 1000.0; + QSizeF rotatedSizeInPixels = image.size(); + qreal dpiX = rotatedSizeInPixels.width() / rotatedSizeInMeters.width(); + qreal dpiY = rotatedSizeInPixels.height() / rotatedSizeInMeters.height(); + image.setDotsPerMeterX(qCeil(dpiX)); + image.setDotsPerMeterY(qCeil(dpiY)); + return image; }