<?php
require_once(dirname(__FILE__)."/DBConnection.php");
require_once(dirname(__FILE__)."/TCPDF/tcpdf.php");
class GeneratePDFFile
{
protected $db;
private $_id;
private $_html;
private $_fileName;
private $_password;
public function setID($id) {
$this->_id = $id;
}
public function seHTML($html) {
$this->_html = $html;
}
public function setFileName($fileName) {
$this->_fileName = $fileName;
}
public function setPassword($password) {
$this->_password = $password;
}
public function __construct() {
$this->db = new DBConnection();
$this->db = $this->db->returnConnection();
}
// get Blog Info function
public function getBlogInfo() {
$query = "SELECT name, description FROM blog WHERE id = ".$this->_id;
$result = $this->db->query($query) or die($this->db->error);
$data = $result->fetch_array(MYSQLI_ASSOC);
return $data;
}
//generate PDF File
public function generatePDFFile() {
ob_start();
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetProtection(array('print', 'copy'), $this->_password, null, 0, null);
// Example with public-key
// To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
//$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' => '/Applications/XAMPP/htdocs/password-protected-pdf-generation-in-php/include/tcpdf.crt', 'p' => array('print'))));
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('TechArise');
$pdf->SetTitle('TechArise');
$pdf->SetSubject('TechArise');
$pdf->SetKeywords('TechArise');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 016', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array('helvetica', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array('helvetica', '', PDF_FONT_SIZE_DATA));
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// 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('times', '', 16);
// add a page
$pdf->AddPage();
// print a block of html using Write()
//$pdf->Write(0, $this->_html, '', 0, 'L', true, 0, false, false, 0);
$pdf->writeHTML($this->_html, true, false, true, false, '');
//Close and output PDF document
$pdf->Output(ROOT_UPLOAD_PATH.$this->_fileName, 'F');
return $this->_fileName;
}
}
?>