Zye
Posts: 56
|
Posted: 10/10/2008, 11:04 AM |
|
Here's how I got DOMPDF to work within CCS - PHP, MySQL
Download the files from http://www.digitaljunkies.ca/dompdf/
I installed them in a folder on my server called 'dompdf' - minus the www folder with the example files.
In the 'dompdf' folder I created a folder called tmp and made it writable (chmod) - dompdf/tmp
Make the folder with the fonts writable also - dompdf/lib/fonts
In the code view of my page (not events) I put the require_once line in the white space under - //End Include Common Files
//End Include Common Files
require_once("./dompdf/dompdf_config.inc.php");
In my HTML view of CCS I deleted all HTML, leaving nothing. Like an example I saw for FPDF on the CCS forums.
In beforeshow event of my page I have my code. The second code snippet below is not my actual code, but you should be able to get the idea.
I have my code in this way because I needed to have a few SQL WHILE loop queries happening.
You can get a simple result by just using a few lines like the example from digitaljunkies website:
--------------------------------------------------------------------------------------------------
$html =
'<html><body>'.
'<p>Some text</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
--------------------------------------------------------------------------------------------------
This is the method I used to create my while loops.
$db = new clsDBconnection;
$data = CCGetParam("data_id","");
$SQL = "SELECT data_title, data_desc, data_img FROM data WHERE data_id =". $data;
$db->query($SQL);
while($db->next_record())
{
$datatitle = $db->f("data_title");
$datadesc = $db->f("data_desc");
$dataimg = $db->f("data_img");
$strHtml = '<p><table cellspacing="0" cellpadding="5" width="90%" align="center" border="0">';
$strHtml .= '<tr>';
$strHtml .= '<td valign="top">';
$strHtml .= '<strong>Data Title: '. $datatitle .'</strong><br>';
$strHtml .= 'Description: '. $datadesc .'<br>';
$strHtml .= '<td align="right" valign="top"><img src="' . $_SERVER['DOCUMENT_ROOT'] . '/images/'. $dataimg .'"> </p></td>';
$strHtml .= '</tr>';
$strHtml .= '</table>';
$strHtml .= '<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0">';
$strHtml .= '<tr>';
}
$strHtml .= '</td>';
$strHtml .= '<td valign="top"> </td>';
$strHtml .= '</tr>';
$strHtml .= '</table>';
$strHtml .= '</body></html>';
$dompdf = new DOMPDF();
//$dompdf->set_paper('A4');
$dompdf->load_html($strHtml);
$dompdf->render();
$dompdf->stream("brochure.pdf", array("Attachment" => 0)); // switch Attachment to 1 to view PDF in Acrobat.
Thats it. I will post if there is something I may have left out. Need to apply more fonts next.
Zye ...
|