Am using Codeigniter 4 and trying to convert a dynamic HTML (invoice) to pdf so it can be download when a user click on a button. It was working perfectly on my local machine chrome and edge browser, but when I tried to test it on my phone chrome it will add .html at the end of the file extension and when I opened it I see a bunch of codes, but when I tried with opera mini on phone is working well.
Here is the code I have tried and the image of random error am having.
public function getInvoice($id){
$options = new Options();
$options->set('isRemoteEnabled', true);
$options->set('enable_css_float', false);
$dompdf = new Dompdf($options);
$getTransaction = $this->BasicModel->getTransaction($id);
$dompdf->setPaper('A4', 'potrait');
$dompdf->loadHtml(view('backend/templates/invoice', compact('getTransaction'))); //Loading my view here
$dompdf->render();
ob_clean();
$dompdf->stream('sebededata-invoice-'.$getTransaction->trans_ref . '.pdf');
}
Here is the error am having when I opened the file downloaded on Mobile chrome
%PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R /F3 11 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (þÿdompdf 1.0.2 CPDF) /CreationDate (D:20210901212045 01'00') /ModDate (D:20210901212045 01'00') /Title (þÿExample 1) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Annots [ 13 0 R ] /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 1046 >> stream xœ VMoÜ6½ï¯˜cØ,¿IùÔ$u¨ƒÖ‹^’ä]ÚV½’\Ik#ÿ> » ‰öʉPØ&çqæÍg‚qÎ)]›Û…VŒKJï6#8“Ê’sŠy“Qèfñß"7†øN‰÷ H«™òšœ’Ì;M«rq€NÏž¦"hÄ '=§ øûw<ÿâLï4Æõï?‚™ä <Øa#Ë™Øo&ºW‹¿v(v§?®G(šIà ^(EåÂdÌá[üÞ̇ÁÍÜJR;õ¨ÜªhN4q öæ¥ "ð~9Ò˜)&@ãrM¿ü®È3NË¢Ïo.Êü6PUwtSo«5Õ ußm«ûª~ªÞ~¥åG:_âžíˆv1ZÒù$Äà™rCŒ•`Zù}ˆ9S6jh!ã# ;!„Û0' S°´$c(”ƒd“H4³2J¥^€ _X5õ’M" žw#Ð(ÐdZGR¡í4nåˆYOª ‰ŒéY½üçÓŇó”½}š"vH(ãHÙm¸'ë@‰W=R6„ç*\‡uXç]Nê²ÜVÅ*ïŠzŒK ‚ä²Üƒ\ÖäèÓ¦n¶U[ßÖtÕ5!t'ô>o‹¦8¡I0í™ÏÄ1Ø»u}z~_tÐÛm@Ë»0 ¡<Yvñå åòË[òBëL ø !»œU6“Ò$¬MäNz tØÝñ«ºêòU÷k;°ÇVu™àê¾Â>}Å?ëňi˜q2f rŠK>H6tM‡Øqæq«1q£ðnÿêyËt“YIɤÌÉm¢¦àŸÅ…QÙ¢f¥?voÙäUÿ (²›Ð„jÎ÷2 (];ܯ ¬—$Q¤\*Ò Y¸¾V yi÷XM/<™Ìo%ñìEm Y¦ù± È üu&v'L$s˜„ŠÆÃt\^ÈÝm{öÓ:üˆwë‰ \mW«Ð¶7ÛÍ,g¸aBðÔ™ƒd†3Ú¼>zêh‹U %Þï™Ù Ñ´ði6 ûlø1Ñc&H}W4]Q†9Dô÷ Dô’9Dè8*È J´²n~T5Üöv‚ÑK!³³‘h Ò¦Ž$sáñ¥›¨Ž?ëëbèr[^‡ffHÑFWúÿ…†7Á( Oµ°Â˜YÅÚÛ0²ÑKúGô5E-þRŃd *ö?;Qœ¿¡AÍφ£ýD4$—â”»SiHˆ3ü*9k<’YûÄ0¡kyÅ÷yuÄÀØ,qHqèºC‹“ß7 »¼ºo1µ5ôÞ6ô wM]a˜cÏ"ô¼[¥3“Ö>Žv‚d6ò;VÇѨÿ~mªƒÙ`!@oÀ e'òè¢z¬ãõ”·´j₉³¢œÐž¶]h(ÇZ´ô˜oŠ5=Ý]½í¨»Ô·k° ´!ߎ~»Á3 endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Times-Bold /Encoding /WinAnsiEncoding >> endobj 10 0 obj [6 0 R /Fit] endobj 11 0 obj << /Type /Font /Subtype /Type1 /Name /F3 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj 12 0 obj [6 0 R /Fit] endobj 13 0 obj << /Type /Annot /Subtype /Link /A 14 0 R /Border [0 0 0] /H /I /Rect [ 432.5080 626.6971 524.0200 635.6071 ] >> endobj 14 0 obj << /Type /Action /S /URI /URI (mailto:[email protected]) >> endobj 15 0 obj [6 0 R /Fit] endobj xref 0 16 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000295 00000 n 0000000324 00000 n 0000000503 00000 n 0000000625 00000 n 0000001744 00000 n 0000001853 00000 n 0000001961 00000 n 0000001990 00000 n 0000002100 00000 n 0000002129 00000 n 0000002257 00000 n 0000002338 00000 n trailer << /Size 16 /Root 1 0 R /Info 5 0 R /ID[<7abfe18a36062956fc713cf29e74e28c><7abfe18a36062956fc713cf29e74e28c>] >> startxref 2367 %%EOF
CodePudding user response:
I was able to solve this by adding exit();
after $dompdf->stream('sebededata-invoice-'.$getTransaction->trans_ref . '.pdf');