gebeer Posted November 4, 2021 Share Posted November 4, 2021 Facing a strange issue with $files->send() method creating this error only on Iphone Safari: "Cannot parse response". On all other clients it is working fine. I am creating a pdf with @bernhard's RockPdf module (which basically is a wrapper around Mpdf library) and sending it for download to browser $pdf = $modules->get('RockPdf'); // ... $mpdf = $pdf->mpdf; // ... $mpdf->WriteHTML($header . $job->render(array('noLinks' => true))); // send $options['noLinks'] for pdf output to not render as links $filename = $input->urlSegment1 . '.pdf'; $saved = $pdf->save($input->urlSegment1 . '.pdf'); if (isset($saved) && $saved->path && file_exists($saved->path)) { try { $files->send($saved->path, array('exit' => true)); unlink($saved->path); } catch (\Throwable $th) { $log->save('pdfdownloads', $th->getMessage()); } } When using Mpdf's native Output method, the rror does not occur $pdf = $modules->get('RockPdf'); // ... $mpdf = $pdf->mpdf; // ... $mpdf->WriteHTML($header . $job->render(array('noLinks' => true))); $filename = $input->urlSegment1 . '.pdf'; try { $output = $mpdf->Output($filename, \Mpdf\Output\Destination::DOWNLOAD); // send to browser } catch (\Throwable $th) { $log->save('pdfdownloads', $th->getMessage()); } exit(); Since PDF generation and Mpdf's native Output method are working fine it seems that $files->send() is the culprit here. Honestly, I have no idea what could cause such a behavior only on Iphone's Safari. Any insights by someone who has more background knowledge on this would be much appreciated. Link to comment Share on other sites More sharing options...
Zeka Posted November 4, 2021 Share Posted November 4, 2021 Hi @gebeer Not sure that this issue is PW relative. Take a look at this thead on apple discussions: https://discussions.apple.com/thread/252479616 1 Link to comment Share on other sites More sharing options...
gebeer Posted November 5, 2021 Author Share Posted November 5, 2021 7 hours ago, Zeka said: Hi @gebeer Not sure that this issue is PW relative. Take a look at this thead on apple discussions: https://discussions.apple.com/thread/252479616 Thank you. I had googled but din't find that link which is quite enlightening. Seems like Mpdf's Output method sets different headers than $files->send() does. I will check what headers are set exactly and can then amend the $files->send() method using the headers option to pass the headers that Safari likes. Cheers! Link to comment Share on other sites More sharing options...
bernhard Posted November 5, 2021 Share Posted November 5, 2021 What happens if you use the show() method? https://github.com/BernhardBaumrock/RockPdf#different-output-types Link to comment Share on other sites More sharing options...
gebeer Posted November 6, 2021 Author Share Posted November 6, 2021 12 hours ago, bernhard said: What happens if you use the show() method? https://github.com/BernhardBaumrock/RockPdf#different-output-types Not sure. Since the Output method is working fine, I haven't tried other methods :-) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now