Jump to content

DomPDF not referencing external stylesheet


DeX

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.

Link to comment
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()); 
?> 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.