function generate_tickets_pdf($dbh, $person_id, $order_id, $row) { $ticket_graphics = array(); # Generate code for each space for ($i = 1; $i <= $row['Spaces']; $i++) { $ticket_number = ''; do { $ticket_number = generate_reg_code(); } while (get_ticket_by_code($dbh, $ticket_number)); # Insert the ticket row into database insert_ticket($dbh, $person_id, $ticket_number); # Generate ticket graphic for each space $ticket_graphics[] = generate_ticket_image($row['Name'], $ticket_number, $current = $i, $seats = $row['Spaces']); } # Generate PDF and cache it to be emailed out require_once 'pdf_lib.php'; $pdf = new PDF_Generator(); #FIXME: REUSE this instance to speed things up $pdf->AddPage(); $pdf->SetFont('helvetica', '', 12); $pdf->SetY(25); #$pdf->SetX(25); #$pdf->Cell(15); $pdf->SetLeftMargin(25); $pdf->Image('images/alamo-30.png', 30, 60, 70, 0); $pdf->Write(5, "Present this ticket at the registration table to receive your \$15 Alamo food gift card.\n"); $pdf->Ln(); #$pdf->SetX(25); $pdf->SetFont('', 'B'); $pdf->Write(5, 'Where: '); PutLink($pdf, 'One Loudoun, 20575 Easthampton Plaza, Ashburn, VA 20147', 'https://www.google.com/maps/place/Alamo+Drafthouse+Cinema/@39.0477854,-77.4656295,14z/data=!4m2!3m1!1s0x0:0x3fda98f8c48cb5aa'); $pdf->Ln(); $pdf->SetFont('', 'B'); $pdf->Write(5, 'When: '); $pdf->SetFont('', ''); $pdf->Write(5, "Saturday, March 5th @ 11:00\n\n"); $pdf->SetFont('', '', 10); $pdf->Write(5, "Please arrive 15 minutes before the showtime to\nselect a seat and take a look at the menu. You\nmight not be seated if you arrive after the showtime.\nAlamo has a strict no talking/texting policy. Noisy\ntables get one warning before being ejected from\nthe theatre.\n\nFursuits have been approved inside the Alamo,\nhowever was not approved by the property owners.\nAs such we ask that fursuits be worn indoors only,\nbut note that there is no dedicated changing\nareas.\n"); $pdf->Image('images/map.png', 110, 50, 80, 0, '', 'https://www.google.com/maps/place/Alamo+Drafthouse+Cinema/@39.0477854,-77.4656295,14z/data=!4m2!3m1!1s0x0:0x3fda98f8c48cb5aa'); # First page: $y_offset = 120; for ($i = 0; $i < count($ticket_graphics); $i++) { # We can fit two tickets on page 1 if ($i <= 1) { $pdf->GDImage($ticket_graphics[$i], 35, $y_offset, 140); $pdf->Line(25, $y_offset, 190, $y_offset); } else { # Pages 2 and onwards fit 3 if (($i + 1) % 3 === 0) { $pdf->AddPage(); $pdf->GDImage($ticket_graphics[$i], 35, 30, 140); $y_offset = 30; } else { $pdf->GDImage($ticket_graphics[$i], 35, $y_offset, 140); $pdf->Line(30, $y_offset, 180, $y_offset); } } $y_offset += 70; } # Save the PDF for now $pdf->Output("pdf/{$person_id}.pdf", 'F'); # Prevent memory leaks foreach ($ticket_graphics as $ticket) { imagedestroy($ticket); } }
<?php require 'pdf_lib.php'; require 'barcode.php'; function PutLink($pdf, $text, $URL) { $pdf->SetFont('', 'U'); $pdf->SetTextColor(0, 0, 255); $pdf->Write(5, $text, $URL); $pdf->SetFont('', ''); $pdf->SetTextColor(0); } $pdf = new PDF_Generator(); $pdf->AddPage(); $pdf->SetFont('helvetica', '', 12); $pdf->SetY(25); #$pdf->SetX(25); #$pdf->Cell(15); $pdf->SetLeftMargin(25); $pdf->Image('images/alamo-30.png', 30, 60, 70, 0); $pdf->Write(5, "Present this ticket at the registration table to receive your \$15 Alamo food gift card.\n"); $pdf->Ln(); #$pdf->SetX(25); $pdf->SetFont('', 'B'); $pdf->Write(5, 'Where: '); PutLink($pdf, 'One Loudoun, 20575 Easthampton Plaza, Ashburn, VA 20147', 'https://www.google.com/maps/place/Alamo+Drafthouse+Cinema/@39.0477854,-77.4656295,14z/data=!4m2!3m1!1s0x0:0x3fda98f8c48cb5aa'); $pdf->Ln(); $pdf->SetFont('', 'B'); $pdf->Write(5, 'When: '); $pdf->SetFont('', ''); $pdf->Write(5, "Saturday, March 5th @ 11:00\n\n");