Laravel 5 fpdi unicode字符
Laravel 5 Fpdi unicode character
我的 laravel 项目需要帮助。我正在使用 Fpdi 导入 PDF,但是当我在本地主机上显示它时,我只有这样的 unicode 字符:
%PDF-1.4 3 0 obj <> endobj 4 0 obj <> stream
x�E�K�0D�9�,a�:i�d��H�|�4�ⓠr|�!y�aƗ!C*�r�y���{�98
L>|a�)w 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');
});
为什么会发生这种情况以及如何解决这个问题?
试着return这样
除非您发送响应,否则浏览器不知道响应的类型,因此它不知道应该显示 pdf
...
return response($pdf->Output('S'))->withHeaders(['Content-Type' => 'application/pdf']);
源文档 https://laravel.com/docs/5.6/responses#attaching-headers-to-responses
我的 laravel 项目需要帮助。我正在使用 Fpdi 导入 PDF,但是当我在本地主机上显示它时,我只有这样的 unicode 字符:
%PDF-1.4 3 0 obj <> endobj 4 0 obj <> stream x�E�K�0D�9�,a�:i�d��H�|�4�ⓠr|�!y�aƗ!C*�r�y���{�98
L>|a�)w 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');
});
为什么会发生这种情况以及如何解决这个问题?
试着return这样 除非您发送响应,否则浏览器不知道响应的类型,因此它不知道应该显示 pdf
...
return response($pdf->Output('S'))->withHeaders(['Content-Type' => 'application/pdf']);
源文档 https://laravel.com/docs/5.6/responses#attaching-headers-to-responses