簡體   English   中英

讓用戶下載pdf而不是保存到某個位置

[英]Make user download pdf instead of saving to a location

我正在嘗試以下代碼,該代碼實際上將pdf文件保存到C:/ xampp /,我想創建一個鏈接,以便當用戶單擊它時。 它提示它保存pdf文件。

<?php  
// create handle for new PDF document  
$pdf = pdf_new();  

// open a file  
pdf_open_file($pdf, "try1.pdf");  

// start a new page (A4)  
pdf_begin_page($pdf, 595, 842);  
pdf_set_parameter($pdf, 'FontOutline',

'Arial=c:\windows\fonts\arial.ttf');
// get and use a font object  
$font = pdf_findfont($pdf, "Arial", "host", 1); 

pdf_setfont($pdf, $font, 10);  

// print text  
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,", 50, 750); 
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50, 730);  

// add an image under the text  
//$image = pdf_open_image_file($pdf, "jpeg", "shakespeare.jpg"); pdf_place_image($pdf, $image, 50, 650, 0.25);  

// end page  
pdf_end_page($pdf);  

// close and save file  
pdf_close($pdf);  
?>

代替pdf_close()使用pdf_get_buffer()pdf_delete()

問題和標題似乎不太匹配,但是您可能正在尋找Content-Disposition標頭。 當您將標頭與PDF之類的資源一起發送時,建議瀏覽器處理該資源-將其保存到文件或內聯呈現(例如,在窗口中)。

例如,建議瀏覽器提供將文件保存在本地的方法:

Content-Disposition: attachment; filename=foo.pdf

而建議它應該嘗試內聯呈現內容:

Content-Disposition: inline; filename=foo.pdf

瀏覽器仍然可以執行所需的任何操作,但主要瀏覽器會提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM