$filePath = '路径.pdf';
$this->preview_pdf($filePath);
public function preview_pdf($filePath) {
// PDF文件是否存在
if (!file_exists($filePath)) {
throw new Exception('文件不存在');
}
// 设置header来指示浏览器打开PDF文件进行预览
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . basename($filePath) . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
// 读取并发送PDF文件内容
readfile($filePath);
exit;
}
如何预览 pdf文件
于 2024-04-11 16:14:10 首次发布