2009-12-07 91 views
1

我試圖從FDF文件創建pdf。我已經成功創建了FDF文件。 但是,當我嘗試將其轉換爲PDF我得到一些錯誤。以下是我的代碼的一部分。中的test.pdf文件下載對話框打開,當我嘗試打開它給錯誤「無法打開,因爲檢驗.pdf它要麼不支持的文件類型或已損壞」使用PHP將FDF轉換爲PDF

if($fp=fopen($fdf_file,'w')){ 
      fwrite($fp,$fdf_data,strlen($fdf_data)); 
      echo $fdf_file,' written successfully.'; 
      header('Content-type: application/pdf'); 
      header('Content-Disposition: attachment; filename="test.pdf"'); 
      passssthru("pdftk test.pdf fill_form test.fdf output - "); 
      exit; 

     }else{ 
      die('U 
+0

Andromeda,你可以請分享完整的代碼,如果你的問題解決了FDF爲PDF。 代碼中的$ fp和$ fdf_data是什麼?請將我的FDF示例代碼通過電子郵件發送給PDF,我可以根據自己的要求輕鬆運行並進行修改。 [email protected] 謝謝, – 2014-12-06 22:10:17

回答

0

刪除echo $fdf_file,' written successfully.';

+0

我已將其刪除。仍顯示相同的錯誤 – Andromeda 2009-12-07 08:54:16

+0

您是否嘗試過passssthru(「pdftk test.pdf fill_form test.fdf output test-out.pdf」);並驗證它的工作原理?您是否嘗試過在十六進制編輯器中編輯PDF以查看數據的外觀? – 2009-12-07 09:43:49

+0

不,我沒有.... 我如何測試「passssthru(」pdftk test.pdf fill_form test.fdf output test-out.pdf「。 – Andromeda 2009-12-07 09:45:35

0

爲了進一步調試,請檢查下載文件的大小,並在編輯器中查看它的大小。我猜你已經輸出這個代碼之前或之後。

0

你可能必須確保直接引用安裝PDFTK地方,因爲這樣的:

passthru('/usr/local/bin/pdftk /forms/test.pdf fill_form /forms/test.fdf output - '); 

此外,您還可以在命令的末尾添加>> output.pdf創建一個新的PDF文件。

1
if($fp=fopen($fdf_file,'w')){ 
     fwrite($fp,$fdf_data,strlen($fdf_data)); 
     //echo $fdf_file,' written successfully.'; 
     header('Content-type: application/pdf'); 
     header('Content-Disposition: attachment; filename="test.pdf"'); 
     passssthru("pdftk test.pdf fill_form test.fdf output - "); 
     exit; 
}