Skip to content

Commit

Permalink
PDF: fix build against Poppler > 22.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 19, 2022
1 parent 75dd520 commit 2d5f96f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gdal/frmts/pdf/pdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4241,8 +4241,6 @@ PDFDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
#ifdef HAVE_POPPLER
if(bUseLib.test(PDFLIB_POPPLER))
{
GooString* poUserPwd = nullptr;

static bool globalParamsCreatedByGDAL = false;
{
CPLMutexHolderD(&hGlobalParamsMutex);
Expand Down Expand Up @@ -4310,9 +4308,6 @@ PDFDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
while( true )
{
VSIFSeekL(fp, 0, SEEK_SET);
if (pszUserPwd)
poUserPwd = new GooString(pszUserPwd);

g_nPopplerErrors = 0;
if( globalParamsCreatedByGDAL )
registerErrorCallback();
Expand All @@ -4322,10 +4317,20 @@ PDFDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
oObj.getObj()->initNull();
auto poStream = new VSIPDFFileStream(fp, pszFilename, oObj.getObj());
#endif
#if POPPLER_MAJOR_VERSION > 22 || (POPPLER_MAJOR_VERSION == 22 && POPPLER_MINOR_VERSION > 2)
std::optional<GooString> osUserPwd;
if (pszUserPwd)
osUserPwd = std::optional<GooString>(pszUserPwd);
poDocPoppler = new PDFDoc(poStream, std::optional<GooString>(), osUserPwd);
#else
GooString* poUserPwd = nullptr;
if (pszUserPwd)
poUserPwd = new GooString(pszUserPwd);
poDocPoppler = new PDFDoc(poStream, nullptr, poUserPwd);
delete poUserPwd;
#endif
if( globalParamsCreatedByGDAL )
registerErrorCallback();
delete poUserPwd;
if( g_nPopplerErrors >= MAX_POPPLER_ERRORS )
{
PDFFreeDoc(poDocPoppler);
Expand Down

0 comments on commit 2d5f96f

Please sign in to comment.