@@ -384,6 +384,21 @@ void QgsLayoutItemPicture::loadRemotePicture( const QString &url )
384
384
if ( reply )
385
385
{
386
386
QImageReader imageReader ( reply );
387
+
388
+ if ( imageReader.format () == " pdf" )
389
+ {
390
+ // special handling for this format -- we need to pass the desired target size onto the image reader
391
+ // so that it can correctly render the (vector) pdf content at the desired dpi. Otherwise it returns
392
+ // a very low resolution image (the driver assumes points == pixels!)
393
+ // For other image formats, we read the original image size only and defer resampling to later in this
394
+ // function. That gives us more control over the resampling method used.
395
+
396
+ // driver assumes points == pixels, so driver image size is reported assuming 72 dpi.
397
+ const QSize sizeAt72Dpi = imageReader.size ();
398
+ const QSize sizeAtTargetDpi = sizeAt72Dpi * mLayout ->renderContext ().dpi () / 72 ;
399
+ imageReader.setScaledSize ( sizeAtTargetDpi );
400
+ }
401
+
387
402
mImage = imageReader.read ();
388
403
mMode = FormatRaster;
389
404
}
@@ -434,6 +449,21 @@ void QgsLayoutItemPicture::loadLocalPicture( const QString &path )
434
449
{
435
450
// try to open raster with QImageReader
436
451
QImageReader imageReader ( pic.fileName () );
452
+
453
+ if ( imageReader.format () == " pdf" )
454
+ {
455
+ // special handling for this format -- we need to pass the desired target size onto the image reader
456
+ // so that it can correctly render the (vector) pdf content at the desired dpi. Otherwise it returns
457
+ // a very low resolution image (the driver assumes points == pixels!)
458
+ // For other image formats, we read the original image size only and defer resampling to later in this
459
+ // function. That gives us more control over the resampling method used.
460
+
461
+ // driver assumes points == pixels, so driver image size is reported assuming 72 dpi.
462
+ const QSize sizeAt72Dpi = imageReader.size ();
463
+ const QSize sizeAtTargetDpi = sizeAt72Dpi * mLayout ->renderContext ().dpi () / 72 ;
464
+ imageReader.setScaledSize ( sizeAtTargetDpi );
465
+ }
466
+
437
467
if ( imageReader.read ( &mImage ) )
438
468
{
439
469
mMode = FormatRaster;
0 commit comments