如何使用php渲染pdf文件 [英] How to render pdf file by using php

查看:203
本文介绍了如何使用php渲染pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have some PDF files and instead of giving direct link to to file, we want it to render through php so that only authenticated users are able to download the pdf file. Thus we dont need to give filepath to user.

有可能吗?

Mangesh

推荐答案

可以,下面是一个示例:

You can, here is a sample:

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

这篇关于如何使用php渲染pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆