Har laddat ner tcpdf http://www.tcpdf.org men har problem med att den inte skriver ut informationen ifrån databasen. Sätter jag fast kod funkar det.
Har testat mysqlkoden och den funkar. Testat jag printa ut så visas det så inget fel med den.
Min kod:
//============================================================+
// File name : example_006.php
// Begin : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 006 for TCPDF class
// WriteHTML and RTL support
//
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com LTD
// www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* Creates an example PDF TEST document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: WriteHTML and RTL support
* @author Nicola Asuni
* @since 2008-03-04
*/
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
$this->Cell(0, 15, 'Användarvillkor', 0, false, 'L', 0, '', 0, false, 'T', 'M');
// Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Sida '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Min hemsida');
$pdf->SetTitle('Användarvillkor');
$pdf->SetSubject('Användarvillkor');
$pdf->SetKeywords('Användarvillkor');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
$host = "mysql.sida.se";
$user = "username";
$password = "losenord";
$db = "databas";
$conn = mysql_connect("$host", "$user", "$password") or die(mysql_error());
mysql_select_db($db,$conn) or die(mysql_error());
$sql = mysql_query("Select rubrik,info From tbl_pages Where sidID=8") or die(mysql_error());
$RS = mysql_fetch_array($sql);
$strRubrik = $RS['rubrik'];
$strInfo = $RS['info'];
//$html = '<p>Användarvillkor står här bla bla</p>';
$html = $strInfo;
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('anvandarvillkor.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+