简体   繁体   English

Laravel 5 Fpdi Unicode字符

[英]Laravel 5 Fpdi unicode character

I need help for my laravel project. 我的laravel项目需要帮助。 I am using Fpdi to import PDF but when I display it on localhost, I have only unicode characters like this : 我正在使用Fpdi导入PDF,但是当我在localhost上显示它时,我只有这样的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 %PDF-1.4 3 0 obj <> endobj 4 0 obj <>流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 L> |a )w endstream endobj 1 0 obj <> endobj 5 0 obj <>流x ]R n 0。

Here is my code: 这是我的代码:

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();

My route: 我的路线:

Route::get('/testpdf', function() {
    return view('layouts/essai'); 
});

Why is this happening and how to fix this? 为什么会发生这种情况以及如何解决?

Try to return it like this The browser doesn't know the type of the response unless you send it so it doesn't know it should show a pdf 尝试像这样返回它浏览器不知道响应的类型,除非您发送了它,所以它不知道它应该显示pdf

...
return response($pdf->Output('S'))->withHeaders(['Content-Type' => 'application/pdf']);

Source docs https://laravel.com/docs/5.6/responses#attaching-headers-to-responses 源文档 https://laravel.com/docs/5.6/responses#attaching-headers-to-responses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM