<?php
// Connection to database
include "./includes/config.php";
// Gets data from database
$result =
mysql_query("SELECT department, name, address, city, phone FROM stores ORDER BY department ASC LIMIT 1");
// Create PDF document
$pdf = pdf_new();
// Open the PDF document
pdf_open_file($pdf,"C:\PDF_Doc.pdf");
// Set info
pdf_set_info($pdf, "Author", "My name");
pdf_set_info($pdf, "Title", "Database");
pdf_set_info($pdf, "Creator", "My name");
pdf_set_info($pdf, "Subject", "Database");
// Create page (A4)
pdf_begin_page($pdf, 595, 842);
// Set fonts
$font1 = PDF_load_font($pdf, "Courier-Bold","iso8859-1", "");
$font2 = PDF_load_font($pdf, "Courier","iso8859-1", "");
// Set position of Y
$y = 735;
// Line top
pdf_setlinewidth($pdf, 1);
pdf_moveto($pdf, 20, 780);
pdf_lineto($pdf, 575, 780);
pdf_stroke($pdf);
// Line bottom
pdf_setlinewidth($pdf, 1);
pdf_moveto($pdf, 20, 50);
pdf_lineto($pdf, 575, 50);
pdf_stroke($pdf);
// Line horizontal (1)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 48, 760);
pdf_lineto($pdf, 557, 760);
pdf_stroke($pdf);
// Line horizontal (2)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 48, 745);
pdf_lineto($pdf, 557, 745);
pdf_stroke($pdf);
// Line horizontal (3)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 48, 70);
pdf_lineto($pdf, 557, 70);
pdf_stroke($pdf);
// Line vertical (1)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 48, 70);
pdf_lineto($pdf, 48, 760);
pdf_stroke($pdf);
// Line vertical (2)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 107, 70);
pdf_lineto($pdf, 107, 760);
pdf_stroke($pdf);
// Line vertical (3)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 233, 70);
pdf_lineto($pdf, 233, 760);
pdf_stroke($pdf);
// Line vertical (4)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 373, 70);
pdf_lineto($pdf, 373, 760);
pdf_stroke($pdf);
// Line vertical (5)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 473, 70);
pdf_lineto($pdf, 473, 760);
pdf_stroke($pdf);
// Line vertical (6)
pdf_setlinewidth($pdf, 0.1);
pdf_moveto($pdf, 557, 70);
pdf_lineto($pdf, 557, 760);
pdf_stroke($pdf);
// Header
pdf_setfont($pdf, $font1, 18);
pdf_show_xy($pdf, "Company name", 50, 795);
// Static text
pdf_setfont($pdf, $font1, 9);
pdf_show_xy($pdf, "Department", 50, 750);
pdf_show_xy($pdf, "Store name", 109, 750);
pdf_show_xy($pdf, "Addresse", 235, 750);
pdf_show_xy($pdf, "City", 375, 750);
pdf_show_xy($pdf, "Phone", 475, 750);
// Dynamic text
pdf_setfont($pdf, $font2, 8);
pdf_show_xy($pdf, $row['department'], 70, $y);
pdf_show_xy($pdf, $row['department'], 70, $y - 15);
pdf_show_xy($pdf, $row['department'], 70, $y - 30);
pdf_show_xy($pdf, $row['department'], 70, $y - 45);
pdf_show_xy($pdf, $row['name'], 109, $y);
pdf_show_xy($pdf, $row['name'], 109, $y - 15);
pdf_show_xy($pdf, $row['name'], 109, $y - 30);
pdf_show_xy($pdf, $row['name'], 109, $y - 45);
pdf_show_xy($pdf, $row['address'], 235, $y);
pdf_show_xy($pdf, $row['address'], 235, $y - 15);
pdf_show_xy($pdf, $row['address'], 235, $y - 30);
pdf_show_xy($pdf, $row['address'], 235, $y - 45);
pdf_show_xy($pdf, $row['city'], 375, $y);
pdf_show_xy($pdf, $row['city'], 375, $y - 15);
pdf_show_xy($pdf, $row['city'], 375, $y - 30);
pdf_show_xy($pdf, $row['city'], 375, $y - 45);
pdf_show_xy($pdf, $row['phone'], 475, $y);
pdf_show_xy($pdf, $row['phone'], 475, $y - 15);
pdf_show_xy($pdf, $row['phone'], 475, $y - 30);
pdf_show_xy($pdf, $row['phone'], 475, $y - 45);
}
// Save page
pdf_end_page($pdf);
// Save & exit
pdf_close($pdf);
pdf_delete($pdf);
?>
// Get open/save dialog
<?php
header ('Content-Description: File Transfer');
header ('Content-Type: application/octet-stream');
header ('Content-Transfer-Encoding: binary');
header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header ('Content-Disposition: attachment; filename="' .
$filename .
'";');
header ('Content-type: application/pdf');
header ('Content-Disposition: attachment; filename="PDF_Doc.pdf"');
?>