2013-03-20 118 views
0

我正在使用cakephp。我生成FDF文件使用的功能從http://koivi.com/fill-pdf-form-fields這個URL在safari中下載PDF文件5.1.7

它工作正常。然後我使用PDFTK生成PDF文件,並且有一些頭文件可以在Firefox,Chorome和IE中正常工作,但它在Safari瀏覽器中效果不佳。在Safari瀏覽器中顯示PDF文件代碼。當我在命令末尾使用exit();時,safari會下載文件,但並不完整。

文件的正常大小是60Kb但是exit()它生成48Kb文件。所以它的意思是由於exit()命令錯過了一些PDF文件內容。

如果有人能在Safari瀏覽器中給出一些提示來解決這個問題。 在此先感謝。

header('Content-Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename="pdf_file_name.pdf"'); 
header("Content-Type: application/download"); 
header("Content-Length: " . filesize($pdf_doc)); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
// $pdf_doc is the PDF Form physical path 
// $fdf_doc is the FDF file physical path 
echo passthru("/usr/local/bin/pdftk $pdf_doc fill_form $fdf_doc output - "); 
+0

我注意到,當顯示在Safari瀏覽器的PDF代碼,我點擊刷新按鈕,然後它給人的文件下載選項。 – nbhatti2001 2013-03-20 07:32:42

回答

2

嘗試將其保存在磁盤上生成的文件使用PDFTK

以下命令
passthru("pdftk $pdf_doc fill_form $fdf_doc output test.pdf"); 

,然後使用相同的代碼已經生成PDF你有。 嘗試保存PDF文件

header('Content-Disposition: attachment; filename="pdf_file_name.pdf"'); 
header("Content-Type: application/download"); 
header('Content-Type:application/pdf'); 
header("Content-Length: " . filesize("test.pdf")); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
readfile("test.pdf"); 

希望以後下面的代碼,這將在Safari工作,以及

0

header('Content-Type:application/pdf');

+0

沒有工作。 – nbhatti2001 2013-03-20 07:29:34

+0

我認爲是一個Safari錯誤,https://discussions.apple.com/thread/3906040?start=0&tstart=0 – Christian 2013-03-20 07:36:24