-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcpdf.php
50 lines (38 loc) · 1.51 KB
/
tcpdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once "config.php";
require_once "inline-html.php";
session_start();
//if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
// header("location: login.php");
// exit;
//}
$template = $_POST['template'];
if(!empty($template))
{
require_once('tcpdf/tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Export HTML Table data to PDF using TCPDF in PHP");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('dejavusans', '', 12, false);
$obj_pdf->AddPage();
$content = '';
$content .= $template;
$file_name = time() . '.pdf';
$html = injectHtml(Array(
'header_1' => "Some text here 1",
'header_2' => "Some text here 2",
'image_1' => realpath('image-examples') . DIRECTORY_SEPARATOR . 'example.jpg'
));
$obj_pdf->writeHTML($html);
$obj_pdf->Output(realpath('uploads') . DIRECTORY_SEPARATOR . $file_name, 'F');
$obj_pdf->Output($file_name, 'I');
}