Check to see if the PDF file is damaged.
int pdfFileIsDamaged(PDFHandle pdf)
This function returns true if the PDF file is damaged, meaning that the object structure couldn't be parsed, and required repair.

Xpdf attempts to repair all damaged files. If the repair is unsuccessful, pdfLoadFile will return an error. If pdfLoadFile succeeds, pdfFileIsDamaged can be used to check whether the file was repaired.

if (pdfFileIsDamaged(pdf)) { .... }