Skip to content
Advertisement

Create pdf with DOM PDF outside DOMpdf directory

Hi I have mybb installed on my website. I have also installed dompdf and its working in its own directory i.e. I have installed in "DOM" directory. Now I can easily general pdfs with this simple code , keeping in the "DOM" directory.

<?php
require_once "dompdf_config.inc.php";
//$file = "www/test/css_at_font_face.html"; 
$file="msf.html";
$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");

?>

If I try to access other file that is out the director DOM i.e.

load_html_file($file); $dompdf->render(); $dompdf->stream(“sample.pdf”);

?> I receive error Remote file requested, but DOMPDF_ENABLE_REMOTE is false

Advertisement

Answer

To load html without enabling remote file access:

<?php
require_once "dompdf_config.inc.php";
$file = "www/test/css_at_font_face.html"; 
$html=file_get_contents($file);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

?>

To enable remote file access:

Taken from dompdf_config.inc.php

/**
 * Enable remote file access
 *
 * If this setting is set to true, DOMPDF will access remote sites for
 * images and CSS files as required.
 * This is required for part of test case www/test/image_variants.html through www/examples.php
 *
 * Attention!
 * **This can be a security risk**, in particular in combination with DOMPDF_ENABLE_PHP and
 * allowing remote access to dompdf.php or on allowing remote html code to be passed to
 * $dompdf = new DOMPDF(); $dompdf->load_html(...);
 * This allows anonymous users to download legally doubtful internet content which on
 * tracing back appears to being downloaded by your server, or allows malicious php code
 * in remote html pages to be executed by your server with your account privileges.
 *
 * @var bool
 */
def("DOMPDF_ENABLE_REMOTE", true);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement