2012-01-04 5 views
37

Dompdfを使用してPDFファイルを作成していますが、作成したPDFをサーバーに保存しない理由はわかりません。DOMPDF生成コンテンツをファイルに保存する方法はありますか?

アイデア?

require_once("./pdf/dompdf_config.inc.php"); 
    $html = 
     '<html><body>'. 
     '<p>Put your html here, or generate it with your favourite '. 
     'templating system.</p>'. 
     '</body></html>'; 

    $dompdf = new DOMPDF(); 
    $dompdf->load_html($html); 
    $dompdf->render(); 
    file_put_contents('Brochure.pdf', $dompdf->output()); 
+0

dompdfのバージョン?すべてのPHPエラー? – BrianS

+0

dompdf 0.5.2、php 5.2.13 – user1079810

+0

保存できないようなものは表示されないので、サーバーの設定エラーを推測しています。 PHPがそのディレクトリに書き込めないのでしょうか?その場合、PHPはエラーを報告します。 PHPエラーログを確認するか、エラー表示を有効にしてください。 – BrianS

答えて

58

私はdompdfを使用していますが、コードは少し異なりますが、機能しました。ここで

それは次のとおりです。

require_once("./pdf/dompdf_config.inc.php"); 
$files = glob("./pdf/include/*.php"); 
foreach($files as $file) include_once($file); 

$html = 
     '<html><body>'. 
     '<p>Put your html here, or generate it with your favourite '. 
     'templating system.</p>'. 
     '</body></html>'; 

    $dompdf = new DOMPDF(); 
    $dompdf->load_html($html); 
    $dompdf->render(); 
    $output = $dompdf->output(); 
    file_put_contents('Brochure.pdf', $output); 

だけ違い、ここでは、ディレクトリ内のすべてのファイルが含まれていることです。

私の唯一の提案は、ファイル名だけでなく、ファイルを書き込むための完全なディレクトリパスを指定することです。

1

私はあなたのコードをテストしましたが、私が見ることができる唯一の問題は、あなたがファイルを書き込むディレクトリに与えられた許可がないことでした。

ファイルを置く必要があるディレクトリに「書き込み」権限を与えます。あなたの場合は、現在のディレクトリです。

linuxで "chmod"を使用してください。

Windowsの場合は、ディレクトリのセキュリティタブに「書き込み」を有効にして「Everyone」を追加します。

-2
<?php 
$content='<table width="100%" border="1">'; 
$content.='<tr><th>name</th><th>email</th><th>contact</th><th>address</th><th>city</th><th>country</th><th>postcode</th></tr>'; 
for ($index = 0; $index < 10; $index++) { 
$content.='<tr><td>nadim</td><td>[email protected]</td><td>7737033665</td><td>247 dehligate</td><td>udaipur</td><td>india</td><td>313001</td></tr>'; 
} 
$content.='</table>'; 
//$html = file_get_contents('pdf.php'); 
if(isset($_POST['pdf'])){ 
    require_once('./dompdf/dompdf_config.inc.php'); 
    $dompdf = new DOMPDF;       
    $dompdf->load_html($content); 
    $dompdf->render(); 
    $dompdf->stream("hello.pdf"); 
} 
?> 
<html> 
    <body> 
     <form action="#" method="post">   
      <button name="pdf" type="submit">export</button> 
     <table width="100%" border="1"> 
      <tr><th>name</th><th>email</th><th>contact</th><th>address</th><th>city</th><th>country</th><th>postcode</th></tr>   
      <?php for ($index = 0; $index < 10; $index++) { ?> 
      <tr><td>nadim</td><td>[email protected]</td><td>7737033665</td><td>247 dehligate</td><td>udaipur</td><td>india</td><td>313001</td></tr> 
      <?php } ?>    
     </table>   
     </form>   
    </body> 
</html> 
関連する問題