如何显示和下载用PHP制作的PDF文件? [英] How to display and download PDF file made with PHP?

查看:57
本文介绍了如何显示和下载用PHP制作的PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一个使用tFPDF类制作的PDF文件。我想知道如何管理它以在新的浏览器窗口中显示并使其可以下载到客户端的PC。正如标题中所述,PDF文件是用PHP制作的。为了解决这个问题,我是否需要将PDF文件或其服务器位置传递给javascript,然后在新窗口中显示或者是否可以显示它并使其可以在PHP中下载。



我尝试了什么:



到目前为止,我尝试使用json_encode()才能通过从PHP到javascript的pdf位置,然后在新窗口中显示。在这种情况下,javascript代码将无法运行。



JAVASCRIPT:

Hi. I have a PDF file made by using tFPDF class. I would like to know how can I manage it to show in a new browser window and make it downloadable to client's PC. As said in the title, PDF file is made in PHP. In order to deal with the problem, do I need to pass the PDF file or its server location to javascript and then show it in a new window OR is it possible to show it and make it downloadable in PHP.

What I have tried:

So far I tried using json_encode() in order to pass the pdf location from PHP to javascript and then showing it in new window. In this case javascript code won't run.

JAVASCRIPT:

var pdfFileLocation = <?php echo json_encode($pdfLocation); ?>;
window.open(pdfFileLocation);





PHP:



PHP:

$pdfLocation = $_SERVER['DOCUMENT_ROOT']."/File.pdf";

推荐答案

pdfLocation); ?取代;
window .open(pdfFileLocation);
pdfLocation); ?>; window.open(pdfFileLocation);





PHP:



PHP:


pdfLocation =
pdfLocation =


_SERVER [' DOCUMENT_ROOT']。 / File.pdf;
_SERVER['DOCUMENT_ROOT']."/File.pdf";


这篇关于如何显示和下载用PHP制作的PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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