1
votes
<?php

include('../helper/app2.php');

$admin = new admin;

$preview = $admin->pdfPreview();

$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title> New Document </title><meta name="Generator" content="EditPlus"><meta name="Author" content=""><meta name="Keywords" content="">  <meta name="Description" content="">  <link href="../../css/style.css" rel="stylesheet" type="text/css" /></head><body><div class="biegeBox"><div class="cardContainer"><div class="cardImg" style="background-image:url(http://'.$_SERVER['SERVER_NAME'].'/demo/'. $preview[0]['image'].'); background-repeat:no-repeat;"><div class="cardQuote">'.$preview[0]['desc'].'</div></div></div></div></body></html>';

if ( isset( $html ) ) {

    require_once("dompdf_config.inc.php");

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
    $dompdf->render();

    $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

    exit(0);
}
?>

The above code I am using to create pdf from dom, but its not rendering image in the pdf. Can any one help me to fix it. After reading this DOMPDF Page background (or alternatives?) question and answer I changed the background property.

1
Make sure your setting for accessing remote resources are correct, specifically DOMPDF_ENABLE_REMOTE and allow_url_fopen are both true. Using dompdf 0.5.x or 0.6.x? In 0.6.x you can access dompdf/www/setup.php (via your web server) to look for any red flags. - BrianS
yes both DOMPDF_ENABLE_REMOTE and allow_url_fopen is true and enabled. - Nathan Sri
Can you post the resulting HTML+CSS rather than the PHP that generates it? Is your containing div styled with a width/height? Which version of dompdf are you using? - BrianS
In my case, allow_url_fopen needed to be turned on from PHP.ini. - Nick Pickering

1 Answers

0
votes

This may not apply to you fully, but in my shared hosting environment the only way i was able to include images was to have the image in the same directory as the HTML file and refer to it via its relative path