Подтвердить что ты не робот

Как сохранить созданный контент DOMPDF в файл?

Я использую Dompdf для создания PDF файла, но я не знаю, почему он не сохраняет созданный PDF файл на сервере.

Любые идеи?

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());
4b9b3361

Ответ 1

Я только что использовал 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);

Единственное отличие здесь в том, что все файлы в каталоге include включены.

Кроме того, мое единственное предложение - указать полный путь к каталогу для записи файла, а не только имя файла.

Ответ 2

Я проверил ваш код, и единственной проблемой, которую я мог видеть, было отсутствие разрешения, предоставленного каталогу, в котором вы пытаетесь записать файл.

Дайте разрешение "написать" в каталог, в который вы должны поместить файл. В вашем случае это текущий каталог.

Используйте "chmod" в Linux.

Добавить "Все" с "записью", включенной на вкладку безопасности каталога, если вы находитесь в Windows.

Ответ 3

<?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>