<?php
    
    $arr = array(
"Olivia Christ",
"Magnus Christ",
"David Christ",
"Leonie Gebs",
"Lea Mayer",
"Marie von Kleinsorgen",
"Anna von Kleinsorgen",
"Jonathan Brennich",
"Lukas Kotterer",
"Luisa Sparakowski",
"Kiara Kurt",
"Sebastian Langer",
"Johanna Kureck",
"Sebastian Tappe",
"Isabel Karolin Bindl",
"Karolin Zobeley",
"Julia Kohlhofer",
"Antonia Schneider",
"Julia Stöber",
"Thomas Zobeley",
"Alina Müller",
"Elia Seybold",
"Otto	Heppe",
"Ida Fäustle",
"Johann Steiger" 
    );
    
    require_once($_SERVER['DOCUMENT_ROOT'].'tcpdf/tcpdf.php');
    
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, 'A5', false, 'UTF-8', false);
    
    // set document information
    $pdf->SetCreator('Zeltlageranmeldung');
    $pdf->SetAuthor('www.fischerkoenig.de');
    $pdf->SetTitle('Zeltlager Namensaufkleber');

    // remove default header/footer
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);

    $pdf->SetMargins(0, 0, 0, 0);
    
    // set auto page breaks
    $pdf->SetAutoPageBreak(false, PDF_MARGIN_BOTTOM);
    
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    
  foreach ($arr as &$name)
  {
    
      // add a page
      $pdf->AddPage();
      
      $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 255)));
      
      for ($i = 0; $i < 6; $i++) 
      {
          drawRec($pdf,$name, 22, 2, 2 + ($i * 15));
      }
      
      for ($i = 0; $i < 10; $i++) 
      {
          drawRec($pdf,$name, 16, 85, 2 + ($i * 12));
      }
      
       for ($i = 0; $i < 12; $i++) 
      {
          drawRec($pdf,$name, 12, 2, 100 + ($i * 11));
      }
      
      for ($i = 0; $i < 9; $i++) 
      {
          drawRec($pdf,$name, 8, 60, 130 + ($i * 9));
      }
      
       for ($i = 0; $i < 9; $i++) 
      {
          drawRec($pdf,$name, 8, 100, 130 + ($i * 9));
      }

  }
    
    
    $pdf->Output('namensaufkleber.pdf', 'I');
    function drawRec($pdf,$text, $size, $x, $y )
    {
        $width = (strlen($text)* $size / 12 ) + (2 * $size) + 1 ;
        $height = $size / 2 + 2;
        $pdf->Polygon(array($x, $y, $x, $y + $height, $x + $width, $y + $height, $x + $width, $y));
        $pdf->SetFont('Helvetica', '', $size);
        $pdf->Text($x, $y + 1, $text);
    
    }

?>
