我需要帮助我的拉拉项目。我使用Fpdi导入PDF,但是当我在本地主机上显示它时,我只有如下所示的unicode字符:
%PDF-1.4 3 0 obj <> endobj 4 0 obj <>流x�E�K�0 D�9�,a�:i�d��H�|�4�qr�!y�aƗ!C*�r�yƗ98 (L>|a�) endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0�
这里是我的代码:
use setasign\ Fpdi;
// initiate FPDI
$pdf = new Fpdi\ Fpdi();
// add a page
$pdf - > AddPage();
// set the source file
$pdf - > setSourceFile(storage_path("justificatif.pdf"));
// import page 1
$tplIdx = $pdf - > importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf - > useImportedPage($tplIdx, 10, 10, 100);
// now write some text above the imported page
$pdf - > SetFont('Helvetica');
$pdf - > SetTextColor(255, 0, 0);
$pdf - > SetXY(30, 30);
$pdf - > Write(0, 'This is just a simple text');
$pdf - > Output();我的路线:
Route::get('/testpdf', function() {
return view('layouts/essai');
});为什么会发生这种情况,以及如何解决这个问题?
发布于 2018-03-15 19:05:13
尝试像这样返回它,浏览器不知道响应的类型,除非你发送它,所以它不知道它应该显示一个pdf
...
return response($pdf->Output('S'))->withHeaders(['Content-Type' => 'application/pdf']);源文档 https://laravel.com/docs/5.6/responses#attaching-headers-to-responses
https://stackoverflow.com/questions/49307280
复制相似问题