I am trying to create a PDF file using TCPDF. But When I tried to insert inline CSS into the HTML, it's displaying a blank page! Here are a few lines of my HTML:
pdf->AddPage();
// set font
$pdf->SetFont('helvetica', 'B', 20);
$pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0);
// create some HTML content
$html = '
<div id="wrapper" style="width:900px;height:auto;margin:0 auto;">
<div id="header" style="width:900px;height:180px;border-bottom:2px solid #5a5a5a;">
<div id="img" style="width:174px;height:87px;position:relative;top:10px;left:350px;"><img src="Untitled Document_files/logoticket.png" /></div>
<div id="text" style="width:250px;position:relative;left:315px;top:20px;font-family:Arial, Helvetica, sans-serif;font-weight:bold;font-size:14px;">E-TICKET/RESERVATION VOUCHER</div>
<div id="text2" style="width:200px;position:relative;left:345px;top:40px;font-family:Arial, Helvetica, sans-serif;
font-weight:bold;font-size:12px;">Visit - www.bookings.7sisters.in</div>
</div>
<div id="mainContent">
<div id="icon" style="width:600px;
height:37px;
position:relative;
left:190px;
top:20px;">
<img src="Untitled D.....
etc.
I am inserting the code in TCPDF example 39. But the output is only the TCPDF logo and the line "Example of HTML Justification". What's the reason? Or it does not support inline CSS?
TCPDF has a very limited CSS support. It doesn't support all attributes.
Currently, only the following CSS attributes are supported:
So try removing the other attributes, and tell if it works.
Also, this is an active forum for TCPDF related discussion.
Alternatives to TCPDF that are definitely worth trying:
Key Features
Helpful tutorial: http://kyokasuigetsu25.wordpress.com/2011/07/14/how-to-use-dompdf-with-css/
Examples (both PHP and generated PDF) can be found here and here.
Hope it helps :)
I used the code you provided, and changed the color to red for 'Visit - www.bookings.7sisters.in' using inline CSS.
See my sample output at https://www.box.com/s/520e9e1f4976802696ec
in my case server added slashes to double quotes - tcpdf ignored attributes like style without warning. so I removed slashes by stripslashes function
well there is a work around that I found :
<h1>Heading<small>Text(is smaller than heading.)</small></h1>
hope this helps someone.