如何使用php渲染pdf文件

use*_*296 2 php pdf render

我们有一些 PDF 文件,我们希望它通过 php 呈现,而不是直接提供文件链接,以便只有经过身份验证的用户才能下载 pdf 文件。因此我们不需要向用户提供文件路径。

是否可以?

曼格什

And*_*ita 5

您可以,这是一个示例:

<?php
$file = './path/to/the.pdf';
$filename = 'You dont know where I am.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
?>
Run Code Online (Sandbox Code Playgroud)