3

I am using mPDF to allow users to download a result from a website in PDF. The PDF files open fine in adobe acrobat, but when closing acrobat it will always ask "Do you want to save changes to /filename.pdf/ before closing?". Nothing can be done or changed in the PDF file so I assume adobe must have found something in the file that it needed to change or fix. The code I use to generate the PDF:

public function pdf($page_to_export, $filename){
    $url = urldecode($page_to_export);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1 );
    $formvars = array('val1' => $_SESSION['val1'] , 
            'val2' => $_SESSION['val2']);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formvars));
    $html = curl_exec($ch);
    curl_close($ch);
    ob_clean();
    header('Content-type: application/pdf');
    header('Content-Transfer-Encoding: binary');
    header('Accept-Ranges: bytes');
    $mpdf = new \Mpdf\Mpdf();
    $mpdf->CSSselectMedia='print'; 
    $mpdf->setBasePath($url);
    $mpdf->WriteHTML($html);    
    $mpdf->Output($filename.'.pdf','D'); 
    ob_end_flush();
}

The formvars do not seem to be the problem, removing them does not make the problem go away. According to what I could find this could be due to a file corruption that is automatically fixed by acrobat. I have no idea how to start debugging this though. Could anyone point me in the right direction?

bolvo
  • 361
  • 3
  • 13

0 Answers0