I am using the standard DOMPDF code to render existing web pages (e.g.1):
$dompdf = new DOMPDF();
$dompdf->set_base_path($artpath);
$dompdf->load_html_file($artpath);
$dompdf->render();
$dompdf->stream($pdfpath);
where $artpath
' is the path to the HTML code and $pdfpath
is the name of the PDF.
However, the web page contains both relative links (which are correctly followed) and absolute links (e.g. /gifs/bullet.gif
) which are not found. This is probably because the DOMPDF code is being executed at http://www.epress.ac.uk/src/xtra/makeapdf.php, www.epress.ac.uk
being a virtual domain on my server, which also hosts the virtual domain jasss.soc.surrey.ac.uk
(that is, both domains are on the same server). It would seem that DOMPDF is using the document root of www.epress.ac.uk
, when it should be using the document root of jasss.surrey.ac.uk
.
Is there some way around this? I have tried resetting $_SERVER['DOCUMENT_ROOT']
to the document root of jasss.soc.surrey.ac.uk
before calling new DOMPDF()
, but this doesn't seem to solve the problem. I get errors such as:
file_get_contents(/styles/jasssarticle.css) [function.file-get-contents]: failed to open stream: No such file or directory
Unable to load css file /styles/jasssarticle.css
The web page is valid HTML according to the www validator.w3.org
Thanks for your advice!