我正在使用Codeigniter 4,并試圖將一個動態的HTML(發票)轉換為pdf,以便當用戶點擊一個按鈕時可以下載它。它在我的本地機器chrome和edge瀏覽器上運行良好,但當我試圖在我的手機chrome上測驗它時,它將在檔案擴展名的末尾添加.html,當我打開它時,我看到一堆代碼,但當我在手機上用opera mini測驗時,它運行良好。
這是我試過的代碼和我遇到的隨機錯誤的圖片。
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'/span>, 'potrait'/span>)。
$dompdf->loadHtml(view('backend/templates/invoice', compact('getTransaction')); //Loading my view here
$dompdf-> render();
ob_clean()。
$dompdf->stream('sebedata-invoice'.$getTransaction-> trans_ref . '.pdf')。)
}
這是我在手機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 (t?dompdf 1. 0.2 CPDF) /CreationDate (D:20210901212045 01'00'/span>) /ModDate (D:20210901212045 01'00'/span>) /Title (t?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<?aL?4???? '?? <?a#???o&oW'?v(v§? ?G(?I? ^(E??dìá[üTì?áíüJR;?¨üahN4q ??¥ "e~9ò?)&@?rM?ü?è3N?¢?o.êü6PUwtSo "5? u?m "?a~aT~¥?G:_a?í?v1Zòù$?à?rC?-`Zù}?9S6jh! ?# ;! "?0' S°′$c("?d "H432J¥^€ _X5?'M" ?w#D(DdZGR?í4n??YOa ‰?éY?ü?ó??ó"?}? "vH(?Hùm?'?@‰W=R6 "?*?uX?]Nê2üV?*??z?K '?2ü???èó|n?U[??t?5! t'?>o'|8?I0í???1? "u}z~_tD?m@? "0 ?<Yv?? ?ò?[òB?L ? ! "?U6 "ò$?M?Nz t?Y? "oêòU÷k;°?Vu?àê??>}?? ???i?q2f r?K>H6tM??q?q "1q£en?êy?t "YIé¤ìém¢|à??...Qù¢f¥? voù?U? (2'D "j?÷2 (];üˉ ?-$Q¤*ò Y??V yi÷XM/<?ìo%?ìEm Y|ù± è üu&v'L$s?"???t^èYm{?ó:ü?w?‰ mW "D?7?í,g?aBe???d?3ú?>zêh'U %T??ù ?′ei6 ?l?1?c&H}W4]Q?9D?÷ D?'9Dè8*è J′2n~T5ü?v'?K! 33'h ò|?$sá?¥'¨???bèr[^?ffH?FWú?...?7á( Oμ°??Y?ú?02?KúG?5E-tR??d *?? ;Q???Aí??£yD4$-a""SiH?3ü*9k<'Y??0?ky?÷yu?à?,qHqèoC'"?7"?oo1μ5?T6? wM]a?c? "??[¥3 "?>?v'd6ò;V??¨?~ma?ù`!@oà e'òè¢z???"-′ja'‰3¢???]h(?Z′??o?5=Y]?í¨"?-° ′! ??~"á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。
uj5u.com熱心網友回復:
我通過在$dompdf->stream('sebedata-invoice'.$getTransaction->trans_ref . '.pdf');
exit();解決了這個問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/311018.html
標籤:
下一篇:同名的多個MySQL鍵的影響
