From 65b4496538c8492b2f8898806480548a940aae99 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 16 Aug 2019 10:20:11 +1000 Subject: [PATCH] GeoPDF export also requires GDAL builds with poppler/pdfium support built in --- src/core/qgsabstractgeopdfexporter.cpp | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/qgsabstractgeopdfexporter.cpp b/src/core/qgsabstractgeopdfexporter.cpp index 83907cb36ed7..d85becd27d42 100644 --- a/src/core/qgsabstractgeopdfexporter.cpp +++ b/src/core/qgsabstractgeopdfexporter.cpp @@ -37,7 +37,23 @@ bool QgsAbstractGeoPdfExporter::geoPDFCreationAvailable() #if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,0,0) return false; #else - return true; + + // test if GDAL has read support in PDF driver + GDALDriverH hDriverMem = GDALGetDriverByName( "PDF" ); + if ( !hDriverMem ) + { + return false; + } + + const char *pHavePoppler = GDALGetMetadataItem( hDriverMem, "HAVE_POPPLER", nullptr ); + if ( pHavePoppler && strstr( pHavePoppler, "YES" ) ) + return true; + + const char *pHavePdfium = GDALGetMetadataItem( hDriverMem, "HAVE_PDFIUM", nullptr ); + if ( pHavePdfium && strstr( pHavePdfium, "YES" ) ) + return true; + + return false; #endif } @@ -46,7 +62,22 @@ QString QgsAbstractGeoPdfExporter::geoPDFAvailabilityExplanation() #if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,0,0) return QObject::tr( "GeoPDF creation requires GDAL version 3.0 or later." ); #else - return QString(); + // test if GDAL has read support in PDF driver + GDALDriverH hDriverMem = GDALGetDriverByName( "PDF" ); + if ( !hDriverMem ) + { + return QObject::tr( "No GDAL PDF driver available." ); + } + + const char *pHavePoppler = GDALGetMetadataItem( hDriverMem, "HAVE_POPPLER", nullptr ); + if ( pHavePoppler && strstr( pHavePoppler, "YES" ) ) + return QString(); + + const char *pHavePdfium = GDALGetMetadataItem( hDriverMem, "HAVE_PDFIUM", nullptr ); + if ( pHavePdfium && strstr( pHavePdfium, "YES" ) ) + return QString(); + + return QObject::tr( "GDAL PDF driver was not built with PDF read support. A build with PDF read support is required for GeoPDF creation." ); #endif }