Ejemplo n.º 1
25
 /**
  * Monta as carteirinhas de acordo em $config e $students
  * @return FPDF
  */
 public function generatePdf()
 {
     $pdf = new FPDF('P', 'mm', 'A4');
     // Variáveis auxiliares
     $yCoordinate = self::VERTICAL_MARGIN;
     $cardVerseX = self::HORIZONTAL_MARGIN + self::GAP_BETWEEN_CARDS + self::CARD_WIDTH;
     $cardsPerPage = (int) ((297 - 2 * self::VERTICAL_MARGIN) / (self::CARD_HEIGHT + self::GAP_BETWEEN_CARDS));
     $frontFieldsX = self::HORIZONTAL_MARGIN + self::CARD_WIDTH - self::CARD_PADDING - self::FRONT_FIELDS_WIDTH;
     foreach ($this->students as $i => $student) {
         if ($i % $cardsPerPage === 0) {
             $pdf->AddPage('P', 'A4');
             $yCoordinate = self::VERTICAL_MARGIN;
         }
         $pdf->SetDrawColor(255);
         // Branco
         $pdf->SetFillColor(255);
         // Branco
         // Posiciona o background selecionado na frente da carteirinha
         $pdf->Image(self::BASE_PATH . '/public/img/' . $this->config['bg_img_url'], self::HORIZONTAL_MARGIN, $yCoordinate, self::CARD_WIDTH, self::CARD_HEIGHT);
         // Posiciona o background selecionado no verso da carteirinha
         $pdf->Image(self::BASE_PATH . '/public/img/' . $this->config['bg_img_url'], $cardVerseX, $yCoordinate, self::CARD_WIDTH, self::CARD_HEIGHT);
         // Posiciona o logo
         $pdf->Image(self::BASE_PATH . '/public/img/' . 'logo_branco.png', self::HORIZONTAL_MARGIN + self::CARD_PADDING, $yCoordinate + self::CARD_PADDING, self::LOGO_WIDTH, self::LOGO_HEIGHT);
         $pdf->Image(self::BASE_PATH . '/public/img/' . 'logo_branco.png', $cardVerseX + self::CARD_PADDING, $yCoordinate + self::CARD_PADDING, self::LOGO_WIDTH, self::LOGO_HEIGHT);
         // Define a fonte, o tamanho e a cor do texto
         $pdf->SetFont(self::FONT, '', self::TITLE_TEXT_SIZE);
         $pdf->SetTextColor(255);
         // Branco
         // Posiciona o nome do cursinho na frente
         $titleWidth = $pdf->GetStringWidth(self::TITLE);
         $pdf->Text(self::HORIZONTAL_MARGIN + self::CARD_WIDTH - $titleWidth - self::CARD_PADDING, $yCoordinate + 9.09, self::TITLE);
         // Posiciona o nome do cursinho no verso
         $pdf->Text($cardVerseX + self::CARD_WIDTH - $titleWidth - self::CARD_PADDING, $yCoordinate + 9.09, self::TITLE);
         // Posiciona a foto do aluno
         $pdf->Image(self::BASE_PATH . '/data/profile/' . $student['img_url'], self::HORIZONTAL_MARGIN + self::CARD_PADDING, $yCoordinate + 19.4, 23.44);
         // Define a fonte, o tamanho e a cor do texto
         $pdf->SetFont(self::FONT, '', self::LABEL_TEXT_SIZE);
         $pdf->SetTextColor(20);
         // Cinza
         // Posiciona o rótulo e o campo do NOME do aluno
         $nameFieldY = $yCoordinate + 24;
         $pdf->Text($frontFieldsX, $nameFieldY - 1.35, "NOME");
         $pdf->Rect($frontFieldsX, $nameFieldY, self::FRONT_FIELDS_WIDTH, self::FRONT_FIELDS_HEIGHT, 'DF');
         // Posiciona o rótulo e o campo do RG do aluno
         $rgFieldY = $yCoordinate + 34.85;
         $pdf->Text($frontFieldsX, $rgFieldY - 1.35, "RG");
         $pdf->Rect($frontFieldsX, $rgFieldY, self::FRONT_FIELDS_WIDTH, self::FRONT_FIELDS_HEIGHT, 'DF');
         // Define a fonte e o tamanho do texto
         $pdf->SetFont(self::FONT, '', self::REGULAR_TEXT_SIZE);
         // Posiciona o NOME do aluno
         $pdf->Text($frontFieldsX + 1.5, $nameFieldY + 2.78, utf8_decode($student['name']));
         // Posiciona o RG do aluno
         $pdf->Text($frontFieldsX + 1.5, $rgFieldY + 2.7, $student['rg']);
         // Posiciona a assinatura do presidente
         $signatureTxt = self::SIGNATURE;
         $ySignatureTxt = $yCoordinate + self::CARD_HEIGHT - self::CARD_PADDING;
         $pdf->Text($cardVerseX + (self::CARD_WIDTH - $pdf->GetStringWidth($signatureTxt)) / 2, $ySignatureTxt, $signatureTxt);
         // Posiciona uma linha acima do texto da assinatura
         $pdf->Line($cardVerseX + self::CARD_WIDTH * 0.2, $ySignatureTxt - 4, $cardVerseX + self::CARD_WIDTH * 0.8, $ySignatureTxt - 4, 'DF');
         $phraseFieldY = $yCoordinate + 17;
         // Posiciona o campo da frase
         $pdf->Rect($cardVerseX + self::CARD_PADDING, $phraseFieldY, self::CARD_WIDTH - 2 * self::CARD_PADDING, self::PHRASE_FIELD_HEIGHT, 'DF');
         // Define a fonte e o tamanho do texto
         $pdf->SetFont(self::FONT, '', self::PHRASE_TEXT_SIZE);
         // Posiciona a frase no verso da carteirinha
         $pdf->SetXY($cardVerseX + self::CARD_PADDING + self::PHRASE_FIELD_PADDING, $phraseFieldY + self::PHRASE_FIELD_PADDING);
         $pdf->MultiCell(self::CARD_WIDTH - 2 * self::CARD_PADDING - 2 * self::PHRASE_FIELD_PADDING, self::PHRASE_FIELD_ROW_HEIGHT, utf8_decode($this->config['phrase']));
         // Posiciona o autor
         $pdf->Text($cardVerseX + self::CARD_WIDTH - self::CARD_PADDING - self::PHRASE_FIELD_PADDING - $pdf->GetStringWidth(utf8_decode($this->config['author'])), $phraseFieldY + self::PHRASE_FIELD_HEIGHT - self::PHRASE_FIELD_PADDING, utf8_decode($this->config['author']));
         // Define a fonte e o tamanho do texto
         $pdf->SetFont(self::FONT, '', self::EXPIRY_TEXT_SIZE);
         // Posiciona a mensagem da data de validade (Válido até <dia> de <mês> de <ano>)
         $str = utf8_decode('Válido até ' . $this->config['expiry']->format('d') . ' de ' . self::MONTHS[(int) $this->config['expiry']->format('n') - 1] . ' de ' . $this->config['expiry']->format('Y'));
         $pdf->Text(self::HORIZONTAL_MARGIN + self::CARD_WIDTH - self::CARD_PADDING - $pdf->GetStringWidth($str), $yCoordinate + self::CARD_HEIGHT - self::CARD_PADDING, $str);
         // coordenada y para construção da próxima carteirinha
         $yCoordinate += self::CARD_HEIGHT + self::GAP_BETWEEN_CARDS;
     }
     return $pdf->Output('Carteirinhas', 'I', true);
 }