0
我有服務器上託管的PDF文件,並希望當用戶點擊鏈接來打印PDF文件,然後打開對話框應該打開,並從那裏用戶可以打印該PDF文件。它應該可以在Chrome,Firefox和Safari瀏覽器中使用。如何發送PDF文件打印對話框使用PHP?
請讓我知道這可以在PHP/jQuery或HTML/jQuery中完成嗎?
我有服務器上託管的PDF文件,並希望當用戶點擊鏈接來打印PDF文件,然後打開對話框應該打開,並從那裏用戶可以打印該PDF文件。它應該可以在Chrome,Firefox和Safari瀏覽器中使用。如何發送PDF文件打印對話框使用PHP?
請讓我知道這可以在PHP/jQuery或HTML/jQuery中完成嗎?
嘗試下面的代碼一旦
$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協議;無論如何,一些瀏覽器可能會忽略它。
這將下載PDF文件到用戶PC上。當打印鏈接被點擊時,我需要打開對話框。這樣用戶可以打印PDF文件。 –