Skip to content

Commit

Permalink
GeoPDF export also requires GDAL builds with poppler/pdfium support b…
Browse files Browse the repository at this point in the history
…uilt in
  • Loading branch information
nyalldawson committed Aug 17, 2019
1 parent a0b6350 commit 65b4496
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/core/qgsabstractgeopdfexporter.cpp
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 65b4496

Please sign in to comment.