Q:

Unable to find "startxref" keyword opening PDF in PHP

I am downloading a file, saving it locally and then opening it to get the number of pages in the file. I am getting an error: Unable to find "startxref" keyword. I have done searches and not found anything that could be connected to my problem.
public function getPageCountPDF($jobid) {
    $this->load->library('Awss3', null, 'S3');
    require_once 'application/libraries/fpdi/fpdf.php';
    require_once 'application/libraries/fpdi/fpdi.php';
    $PdfTranscriptInfo = $this->MJob->getDOCCSPdfTranscript($jobid);
    $filename = $PdfTranscriptInfo['origfilename'];
    $PdfFilename = 'uploads/' . $jobid . '/' . $filename;
    $pdfdata = $this->S3->readfile($PdfFilename, false, 'bucket');
    $localfilename = FCPATH . 'tmp/local.pdf'; 
    fopen($localfilename, 'a');
    $pdf = new FPDI();
    $pageCount = $pdf->setSourceFile($localfilename);  
    unlink($localfilename);
    return $pageCount;
}

When I echo out the $pdfdata, I see the startxref keyword, so why is it not finding it?
Anyone? Any ideas?
EDIT: I checked if the file is compressed and it is not.
SECOND EDIT: I see that my PDF is version 1.3, could that have anything to do with it?

A:

Thank you to @SamTolton. His answer helped me solve the problem.  Here is my code now that works:
public function getPageCountPDF($jobid) {
    $this->load->library('Awss3', null, 'S3');
    require_once 'application/libraries/fpdi/fpdf.php';
    require_once 'application/libraries/fpdi/fpdi.php';
    $PdfTranscriptInfo = $this->MJob->getDOCCSPdfTranscript($jobid);
    $filename = $PdfTranscriptInfo['origfilename'];
    $PdfFilename = 'uploads/' . $jobid . '/' . $filename;
    $pdfdata = $this->S3->readfile($PdfFilename, false, 'bucket');
    $localfilename = FCPATH . 'tmp/local.pdf';
    file_put_contents($localfilename, $pdfdata);
    $pdf = new FPDI();
    $pageCount = $pdf->setSourceFile($localfilename);
    $pdf->cleanUp();
    unlink($localfilename);
    return $pageCount;
}

