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

Community
  • 1
  • 1
Nathan Sri
  • 103
  • 1
  • 4
  • 14
  • 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 Dec 27 '11 at 18:48
  • 1
    yes both DOMPDF_ENABLE_REMOTE and allow_url_fopen is true and enabled. – Nathan Sri Dec 27 '11 at 19:27
  • 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 Jan 03 '12 at 19:43
  • In my case, `allow_url_fopen` needed to be turned on from PHP.ini. – Nick Pickering Mar 11 '13 at 09:21
  • Possible duplicate of [How to give Background to pdf by dompdf?](http://stackoverflow.com/questions/6994460/how-to-give-background-to-pdf-by-dompdf) – Tristan McGowan Feb 22 '16 at 22:21

1 Answers1

0

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

Raymond Holguin
  • 1,050
  • 2
  • 12
  • 35