DeX Posted March 9, 2011 Share Posted March 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/230146-dompdf-not-referencing-external-stylesheet/ Share on other sites More sharing options...
DeX Posted March 11, 2011 Author Share Posted March 11, 2011 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/230146-dompdf-not-referencing-external-stylesheet/#findComment-1185906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.