Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect File Name Encoding on Safari When Downloading PDF with Non-ASCII Characters #517

Open
saiko-daidv opened this issue Oct 1, 2023 · 0 comments

Comments

@saiko-daidv
Copy link

I am currently using laravel-snappy to generate PDF files in a Laravel application. The library works as expected on browsers like Chrome, but I encountered an issue when downloading files using Safari. Specifically, when the filename contains non-ASCII characters (e.g., Japanese characters), the name gets incorrectly encoded.

For example, a correct filename should appear as follows:
#335テスト_社内見積_20231001.pdf

However, in Safari, it is incorrectly displayed as:
#335ãã¹ã_社åè¦ç©_20231001.pdf

Here's a snippet of the code I'm using:

public function projectDetailPdf($id, Request $request) {
    $project = $this->projectRepository->find($id);
    $pdf = \PDF::loadView('pdf.project_details', [
        'project' => $project,
    ])
    ->setOption('encoding', 'utf-8')
        ->setPaper('a4', 'landscape');
    
    $filename = $project['name'] . '_プロジェクト詳細_' . date("Ymd") . '.pdf';
    
    $headers = [
        'Content-Type'        => 'application/pdf',
        'Content-Disposition' => 'attachment; filename*=UTF-8\'\''.rawurlencode($filename)
    ];
    
    return $pdf->stream($filename, 200, $headers);
}

I tried using both rawurlencode and urlencode for the filename in the Content-Disposition header, but neither resolved the issue.

Laravel version: ^6.20.26
laravel-snappy version: ^0.4.8
PHP version: 7.4

Please help me!
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant