Re: Using iamges from a virtual directory in a PDF

106 views
Skip to first unread message

Dixon MD

unread,
Oct 1, 2012, 7:22:56 AM10/1/12
to dom...@googlegroups.com
use absolute path for image.

On Friday, September 28, 2012 5:52:53 PM UTC+5:30, Paul wrote:
I have a setup like so:

IIS7, PHP the website has a virtual directory in IIS that points to an image share on a remote server ie \\server\images mapped as images.

if I use http://site.com/images/pic.jpg I can see my image in the browser.

If I use this full url as the img src I can load the image in the PDF.

If I have code such as:

  <?php

    require_once("pdf/dompdf_config.inc.php");
  $dompdf = new DOMPDF();
  $theHtm = "<html><body>daata<img src='/images/069.jpg'/></body></html>" ;
  $dompdf->load_html($theHtm);
  $dompdf->render();
    $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

  exit(0);
 ?>

I can never load the image into the PDF.  Anyone seen issues like this? Is this possible with this library?

BrianS

unread,
Oct 1, 2012, 10:27:44 AM10/1/12
to dom...@googlegroups.com
As Dixon says, you should be more explicit in your code. When using $dompdf->load_html() dompdf does not have any sense about your web site. Code loaded in this manner is assumed to not have a defined web presence and so links are relative to the operating system file system.

$theHtm = "<html><body>daata<img src='http://site.com/images/069.jpg'/></body></html>";

Alternately, you could provide a hint to dompdf that this is web-based content using the BASE tag. Though in order for this to work properly you will need to be using the latest code (available from the SVN repository or as a nightly download).

$theHtm = "<html><head><base href="http://site.com"></head><body>daata<img src='/images/069.jpg'/></body></html>";

There might also be a way to specify the base path using the dompdf object, though I'd have to investigate this further as I've had trouble with this functionality in the past.
Reply all
Reply to author
Forward
0 new messages