Jump to content

Archived

This topic is now archived and is closed to further replies.

DeX

DomPDF not referencing external stylesheet

Recommended Posts

Any ideas why this would be? The question seems to be all over the internet but nothing seems to work. I installed the latest version (0.6.0 beta) and I have had this working fine for months.....with the exception of the CSS. For some reason when it creates the PDF, it leaves out the external stylesheet and doesn't style anything. Inline styling works fine but it's supposed to access the external CSS.

 

I created a simplified PHP snippet for you that shows my issue:

<html>

<?php

$quote = 
" <div class = 'row0'>div 1</div>
<div class = 'row1'>div 2</div>";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="test1.css" media="screen" />
</head>
<body>

<?php
echo $quote;

	// save file to server
	require_once("d/dompdf_config.inc.php");
	$dompdf = new DOMPDF();
//		$dompdf->set_base_path("admin3/");
	echo "base path: " . $dompdf->get_base_path();
	$dompdf->load_html($quote);
	$dompdf->render();

	file_put_contents('customers/a.pdf', $dompdf->output()); 

?>
</body>
</html>

 

And the external test1.css file:

.row1
{
background: #000;
}

.row0
{
background: #bbb;
}

 

Any ideas how to get this to reference the CSS file? I've tried every combination of absolute/relative paths in the set_base_path() function but nothing seems to work there. The test1.css file is in the same directory as the PHP file and is displaying properly on the screen.

Share this post


Link to post
Share on other sites

F ya, got it thanks to a Google newsgroup.

 

I need to pass in the entire HTML page including the CSS includes to DomPDF so this needs to be my PHP file:

<?php 
ob_start(); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// 
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<title></title> 
<link rel="stylesheet" type="text/css" href="test1.css" media="screen" /> 
</head> 
<body> 
<div class = 'row0'>div 1</div> 
<div class = 'row1'>div 2</div></body> 
</html> 
<?php 
require_once("d/dompdf_config.inc.php"); 
$dompdf = new DOMPDF(); 
$dompdf->load_html(ob_get_clean()); 
$dompdf->render(); 
file_put_contents('customers/a.pdf', $dompdf->output()); 
?> 

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.