1. <?php
  2. session_start();
  3.  
  4. // Connection to database
  5. include "./includes/config.php";
  6.  
  7. // Gets data from database
  8. $result = mysql_query("SELECT department, name, address, city, phone FROM stores ORDER BY department ASC LIMIT 1");
  9.  
  10. // Create PDF document
  11. $pdf = pdf_new();
  12.  
  13. // Open the PDF document
  14. pdf_open_file($pdf,"C:\PDF_Doc.pdf");
  15.  
  16. // Set info
  17. pdf_set_info($pdf, "Author", "My name");
  18. pdf_set_info($pdf, "Title", "Database");
  19. pdf_set_info($pdf, "Creator", "My name");
  20. pdf_set_info($pdf, "Subject", "Database");
  21.  
  22. // Create page (A4)
  23. pdf_begin_page($pdf, 595, 842);
  24.  
  25. // Set fonts
  26. $font1 = PDF_load_font($pdf, "Courier-Bold","iso8859-1", "");
  27. $font2 = PDF_load_font($pdf, "Courier","iso8859-1", "");
  28.  
  29. // Set position of Y
  30. $y = 735;
  31.  
  32. // Line top
  33. pdf_setlinewidth($pdf, 1);
  34. pdf_moveto($pdf, 20, 780);
  35. pdf_lineto($pdf, 575, 780);
  36. pdf_stroke($pdf);
  37.  
  38. // Line bottom
  39. pdf_setlinewidth($pdf, 1);
  40. pdf_moveto($pdf, 20, 50);
  41. pdf_lineto($pdf, 575, 50);
  42. pdf_stroke($pdf);
  43.  
  44. // Line horizontal (1)
  45. pdf_setlinewidth($pdf, 0.1);
  46. pdf_moveto($pdf, 48, 760);
  47. pdf_lineto($pdf, 557, 760);
  48. pdf_stroke($pdf);
  49.  
  50. // Line horizontal (2)
  51. pdf_setlinewidth($pdf, 0.1);
  52. pdf_moveto($pdf, 48, 745);
  53. pdf_lineto($pdf, 557, 745);
  54. pdf_stroke($pdf);
  55.  
  56. // Line horizontal (3)
  57. pdf_setlinewidth($pdf, 0.1);
  58. pdf_moveto($pdf, 48, 70);
  59. pdf_lineto($pdf, 557, 70);
  60. pdf_stroke($pdf);
  61.  
  62. // Line vertical (1)
  63. pdf_setlinewidth($pdf, 0.1);
  64. pdf_moveto($pdf, 48, 70);
  65. pdf_lineto($pdf, 48, 760);
  66. pdf_stroke($pdf);
  67.  
  68. // Line vertical (2)
  69. pdf_setlinewidth($pdf, 0.1);
  70. pdf_moveto($pdf, 107, 70);
  71. pdf_lineto($pdf, 107, 760);
  72. pdf_stroke($pdf);
  73.  
  74. // Line vertical (3)
  75. pdf_setlinewidth($pdf, 0.1);
  76. pdf_moveto($pdf, 233, 70);
  77. pdf_lineto($pdf, 233, 760);
  78. pdf_stroke($pdf);
  79.  
  80. // Line vertical (4)
  81. pdf_setlinewidth($pdf, 0.1);
  82. pdf_moveto($pdf, 373, 70);
  83. pdf_lineto($pdf, 373, 760);
  84. pdf_stroke($pdf);
  85.  
  86. // Line vertical (5)
  87. pdf_setlinewidth($pdf, 0.1);
  88. pdf_moveto($pdf, 473, 70);
  89. pdf_lineto($pdf, 473, 760);
  90. pdf_stroke($pdf);
  91.  
  92. // Line vertical (6)
  93. pdf_setlinewidth($pdf, 0.1);
  94. pdf_moveto($pdf, 557, 70);
  95. pdf_lineto($pdf, 557, 760);
  96. pdf_stroke($pdf);
  97.  
  98. // Header
  99. pdf_setfont($pdf, $font1, 18);
  100. pdf_show_xy($pdf, "Company name", 50, 795);
  101.  
  102. // Static text
  103. pdf_setfont($pdf, $font1, 9);
  104. pdf_show_xy($pdf, "Department", 50, 750);
  105. pdf_show_xy($pdf, "Store name", 109, 750);
  106. pdf_show_xy($pdf, "Addresse", 235, 750);
  107. pdf_show_xy($pdf, "City", 375, 750);
  108. pdf_show_xy($pdf, "Phone", 475, 750);
  109.  
  110. // Dynamic text
  111. pdf_setfont($pdf, $font2, 8);
  112. while ($row = mysql_fetch_array($result )) {
  113. pdf_show_xy($pdf, $row['department'], 70, $y);
  114. pdf_show_xy($pdf, $row['department'], 70, $y - 15);
  115. pdf_show_xy($pdf, $row['department'], 70, $y - 30);
  116. pdf_show_xy($pdf, $row['department'], 70, $y - 45);
  117. pdf_show_xy($pdf, $row['name'], 109, $y);
  118. pdf_show_xy($pdf, $row['name'], 109, $y - 15);
  119. pdf_show_xy($pdf, $row['name'], 109, $y - 30);
  120. pdf_show_xy($pdf, $row['name'], 109, $y - 45);
  121. pdf_show_xy($pdf, $row['address'], 235, $y);
  122. pdf_show_xy($pdf, $row['address'], 235, $y - 15);
  123. pdf_show_xy($pdf, $row['address'], 235, $y - 30);
  124. pdf_show_xy($pdf, $row['address'], 235, $y - 45);
  125. pdf_show_xy($pdf, $row['city'], 375, $y);
  126. pdf_show_xy($pdf, $row['city'], 375, $y - 15);
  127. pdf_show_xy($pdf, $row['city'], 375, $y - 30);
  128. pdf_show_xy($pdf, $row['city'], 375, $y - 45);
  129. pdf_show_xy($pdf, $row['phone'], 475, $y);
  130. pdf_show_xy($pdf, $row['phone'], 475, $y - 15);
  131. pdf_show_xy($pdf, $row['phone'], 475, $y - 30);
  132. pdf_show_xy($pdf, $row['phone'], 475, $y - 45);
  133. }
  134.  
  135. // Save page
  136. pdf_end_page($pdf);
  137.  
  138. // Save & exit
  139. pdf_close($pdf);
  140. pdf_delete($pdf);
  141. ?>
  142.  
  143. // Get open/save dialog
  144. <?php
  145. header ('Content-Description: File Transfer');
  146. header ('Content-Type: application/octet-stream');
  147. header ('Content-Transfer-Encoding: binary');
  148. header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  149. header ('Content-Disposition: attachment; filename="' . $filename . '";');
  150. header ('Content-Length: ' . filesize ($filepath));
  151. header ('Content-type: application/pdf');
  152. header ('Content-Disposition: attachment; filename="PDF_Doc.pdf"');
  153. readfile ('c:\PDF_Doc.pdf');
  154. ?>