如何显示和下载用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";