2016-10-01 77 views
0

我有服务器上托管的PDF文件,并希望当用户点击链接来打印PDF文件,然后打开对话框应该打开,并从那里用户可以打印该PDF文件。它应该可以在Chrome,Firefox和Safari浏览器中使用。如何发送PDF文件打印对话框使用PHP?

请让我知道这可以在PHP/jQuery或HTML/jQuery中完成吗?

回答

0

尝试下面的代码一旦

$filepath = "path/to/file.pdf"; 
$filename = "file.pdf"; 
header('Content-Transfer-Encoding: binary'); 
header('Content-Length: ' . filesize($filepath)); // File size 
header('Content-Encoding: none'); 
header('Content-Type: application/pdf'); 
header('Content-Disposition: attachment; filename=' . $filename); // Make the browser display the Save As dialog 
readfile($filepath); // This is necessary in order to get it to actually download the file, otherwise it will be 0Kb 

注:,这只是一个扩展HTTP协议;无论如何,一些浏览器可能会忽略它。

+0

这将下载PDF文件到用户PC上。当打印链接被点击时,我需要打开对话框。这样用户可以打印PDF文件。 –

相关问题