Files
HotLunches/pdf-test.php
T
2026-10-19 15:22:52 -07:00

131 lines
3.7 KiB
PHP

<?php
include "db.php";
//
// Setup PDF document
//
require("tcpdf/config/lang/eng.php");
require("tcpdf/tcpdf.php");
// Set parameters for this document
$left_col = 15;
$title_width = 250;
$max_rows = 190;
$name_col = 15;
$contact_col = 65;
$home_phone_col = 115;
$work_phone_col = 145;
$cell_phone_col = 175;
$email_col = 205;
$name_width = $contact_col - $name_col - 1;
$contact_width = $home_phone_col - $contact_col - 1;
$phone_width = $work_phone_col - $home_phone_col - 1;
$email_width = 60;
$document_font = "Helvetica";
$document_font_weight = "";
$document_text_color = "#000000";
$document_font_size = 9;
$start_row = 10;
$curr_row = $start_row;
$incr = 4.5;
$report_title = "Test PDF";
$report_subtitle = "";
$class_parent_name = "";
class PDF extends TCPDF {
function Header() {
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $class_parent_name;
// Print the header
$this->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$this->SetFont($document_font,"B",$document_font_size + 2);
$this->SetXY($left_col,$start_row);
$this->Cell($title_width,$incr + 1," $report_title",'0',1,'L',true);
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
$offset = 150;
$this->SetXY($left_col + $offset,$start_row);
$this->Cell($title_width - $offset,$incr + 1,"$report_subtitle ",'0',1,'R',true);
}
if (isset($class_parent_name) && strlen($class_parent_name) > 0) {
$this->SetFont($document_font,"B",$document_font_size + 0);
$this->SetXY($left_col,$start_row + $incr + 2);
$this->Cell($title_width,$incr," ",'0',1,'L',true);
$offset = 150;
$this->SetXY($left_col + $offset,$start_row + $incr + 2);
$this->Cell($title_width - $offset,$incr,getLanguageText('TEXT-CLASS-PARENT').": $class_parent_name ",'0',1,'R',true);
}
}
function Footer() {
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row;
// Print the date
$this->SetFont($document_font,"",$document_font_size - 1);
$this->SetXY($left_col,$logo_row);
$date = date("Y-m-d",time());
$this->Cell($title_width,$incr - 1,"$document_name: $date",'0',1,'R');
$this->Image($logo_image,10,$logo_row, 50);
$this->SetXY(20,$logo_row + 9);
$this->SetFont($document_font,"B",$document_font_size);
$this->Cell($title_width,$incr,$logo_url,'0',1,'L');
}
}
$pdf = new PDF('L', 'mm', 'Letter', true, 'UTF-8', false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$font_red = hexdec("00");
$font_green = hexdec("00");
$font_blue = hexdec("00");
$pdf->SetTextColor($font_red,$font_green,$font_blue);
$pdf->SetFont($document_font,"",$document_font_size);
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$pdf->addPage();
$curr_row += $incr * 2;
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($name_width,$incr,"Mark Fester",'0',1,'L',true);
// Output the completed PDF
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-type: application/pdf');
header("Content-Disposition: attachment; filename=test.pdf");
header('Content-Transfer-Encoding: binary');
$pdf->Output("test.pdf","D");
?>