public function draw(\PhpSigep\Pdf\ImprovedFPDF $pdf) { $pdf->saveState(); // quantos mm cabem dentro de um pt do pdf $un = 72 / 25.4; // Desenha o retangulo $pdf->SetFillColor(0, 0, 0); $pdf->SetDrawColor(0, 0, 0); $k = $pdf->k; $wRect = $un * 31.5 / $k; $h = $un * 22.5 / $k; $lineWidth = 2 / $k; $pdf->SetLineWidth($lineWidth); $x = $this->x; $y = $this->y; $pdf->RoundedRect($x, $y, $wRect, $h, 5); // Escreve o texto PAC $pdf->SetFont('Arial', 'B', 27); $pdf->SetXY($x, $y + 4.5 / $k); $pdf->Cell($wRect, 27 / $k, 'PAC', 0, 2, 'C'); // Número contrato e DR $pdf->SetFont('', '', 7); $texto = $this->accessData->getNumeroContrato() . '/' . $this->accessData->getAnoContrato() . '-DR/' . $this->accessData->getDiretoria()->getSigla(); $pdf->Cell($wRect, 6 / $k, $texto, 0, 2, 'C'); // Nome do remetente $pdf->SetFont('', 'B', 9); $pdf->MultiCell($wRect, 8 / $k, $pdf->_($this->nomeRemetente), 0, 'C'); // Insere a logo do correios na parte inferior $pdf->SetDrawColor(255, 255, 255); $pdf->SetLineWidth(2 / $k); $x1 = $x + 3.15 * $un / $k; $x2 = $x1 + 0.54 / $k; $y1 = $y + $h + 0.45 / $k; $y2 = $y1 - 0.9 / $k; $space = 3.6 / $k; $x1 += $space; $x2 += $space; $x1 += $space; $x2 += $space; $x1 += $space; $pdf->SetFontSize(9); $stringWidth = $pdf->GetStringWidth('CORREIOS'); $x2 += $space + $stringWidth; $pdf->SetLineWidth(2.5 / $k); $pdf->Line($x1, $y + $h, $x2, $y + $h); $pdf->Image(realpath(dirname(__FILE__)) . '/../correios-logo.png', $x1, $y1 - 3); $pdf->restoreLastState(); }
private function labeledText(ImprovedFPDF $pdf, $label, $text, $maxW, $ln = 0, $multLines = false) { $pdf->saveState(); $pdf->SetFont('', ''); $wLabel = $pdf->GetStringWidthXd($label . ' '); $pdf->SetFont('', 'B'); $xLabel = $pdf->x; $pdf->CellXp($wLabel, $label); $pdf->SetFont('', ''); $maxTextW = $maxW - $wLabel; if ($multLines) { if (is_float($multLines) || is_int($multLines)) { $pdf->setLineHeightPadding($multLines); } $x = $pdf->x - $wLabel; $pdf->MultiCellXp($maxTextW, $text); if ($ln === 0) { $pdf->SetX($x + $maxTextW); } else { if ($ln == 1) { $pdf->SetX($pdf->lMargin); } else { if ($ln == 2) { $pdf->SetX($x); } } } } else { while ($text && $maxTextW < $pdf->GetStringWidth($text)) { $text = substr($text, 0, strlen($text) - 1); } $pdf->CellXp($maxTextW, $text, '', $ln); if ($ln == 2) { $pdf->x -= $wLabel; } } $lastX = $pdf->x; $lastY = $pdf->y; $pdf->restoreLastState(); if ($ln === 0) { $pdf->SetX($xLabel + $maxW); } else { if ($ln === 1) { $pdf->SetXY($lastX, $lastY); } else { if ($ln === 2) { $pdf->SetXY($lastX, $lastY); } } } }
public function draw(\PhpSigep\Pdf\ImprovedFPDF $pdf) { $pdf->saveState(); // quantos mm cabem dentro de um pt do pdf $un = 72 / 25.4; // Desenha o retangulo $pdf->SetFillColor(0, 0, 0); $pdf->SetDrawColor(0, 0, 0); $k = $pdf->k; $wRect = $un * 35 / $k; $h = $un * 25 / $k; $lineWidth = 2 / $k; $pdf->SetLineWidth($lineWidth); $x = $this->x; $y = $this->y; $pdf->Rect($x, $y, $wRect, $h); // Escreve o texto PAC $pdf->SetFont('Arial', 'B', 30); $pdf->SetXY($x, $y + 5 / $k); $pdf->Cell($wRect, 30 / $k, 'PAC', 0, 2, 'C'); // Número contrato e DR $pdf->SetFont('', '', 7); $texto = $this->accessData->getNumeroContrato() . '/' . $this->accessData->getAnoContrato() . '-DR/' . $this->accessData->getSigla(); $pdf->Cell($wRect, 7 / $k, $texto, 0, 2, 'C'); // Nome do remetente $pdf->SetFont('', 'B', 9); $pdf->MultiCell($wRect, 9 / $k, $pdf->_($this->nomeRemetente), 0, 'C'); // Escreve o texto CORREIOS $pdf->SetDrawColor(255, 255, 255); $pdf->SetLineWidth(2 / $k); $x1 = $x + 3.5 * $un / $k; $x2 = $x1 + 0.6 / $k; $y1 = $y + $h + 0.5 / $k; $y2 = $y1 - 1 / $k; $space = 4 / $k; $pdf->Line($x1, $y1, $x2, $y2); $x1 += $space; $x2 += $space; $pdf->Line($x1, $y1, $x2, $y2); $x1 += $space; $x2 += $space; $pdf->Line($x1, $y1, $x2, $y2); $texto = 'CORREIOS'; $x1 += $space; $pdf->SetFontSize(10); $stringWidth = $pdf->GetStringWidth($texto); $x2 += $space + $stringWidth; $pdf->SetLineWidth(2.5 / $k); $pdf->Line($x1, $y + $h, $x2, $y + $h); $pdf->Text($x1, $y1, $texto); // $pdf->Cell($stringWidth, 10/$k, $texto, 0); $x1 += $space + $pdf->GetStringWidth($texto); $x2 += $space; $pdf->Line($x1, $y1, $x2, $y2); $x1 += $space; $x2 += $space; $pdf->Line($x1, $y1, $x2, $y2); $x1 += $space; $x2 += $space; $pdf->Line($x1, $y1, $x2, $y2); $pdf->restoreLastState(); }
public function CircularText(\PhpSigep\Pdf\ImprovedFPDF $pdf, $x, $y, $r, $text, $align = 'top', $kerning = 120, $fontwidth = 100) { $transf = new Transform(); $kerning /= 100; $fontwidth /= 100; if ($kerning == 0) { $pdf->Error('Please use values unequal to zero for kerning'); } if ($fontwidth == 0) { $pdf->Error('Please use values unequal to zero for font width'); } //get width of every letter $t = 0; for ($i = 0; $i < strlen($text); $i++) { $w[$i] = $pdf->GetStringWidth($text[$i]); $w[$i] *= $kerning * $fontwidth; //total width of string $t += $w[$i]; } //circumference $u = $r * 2 * M_PI; //total width of string in degrees $d = $t / $u * 360; $transf->StartTransform($pdf); // rotate matrix for the first letter to center the text // (half of total degrees) if ($align == 'top') { $transf->Rotate($pdf, $d / 2, $x, $y); } else { $transf->Rotate($pdf, -$d / 2, $x, $y); } //run through the string for ($i = 0; $i < strlen($text); $i++) { if ($align == 'top') { //rotate matrix half of the width of current letter + half of the width of preceding letter if ($i == 0) { $transf->Rotate($pdf, -($w[$i] / 2 / $u) * 360, $x, $y); } else { $transf->Rotate($pdf, -(($w[$i] / 2 + $w[$i - 1] / 2) / $u) * 360, $x, $y); } if ($fontwidth != 1) { $transf->StartTransform($pdf); $transf->ScaleX($pdf, $fontwidth * 100, $x, $y); } $pdf->SetXY($x - $w[$i] / 2, $y - $r); } else { //rotate matrix half of the width of current letter + half of the width of preceding letter if ($i == 0) { $transf->Rotate($pdf, $w[$i] / 2 / $u * 360, $x, $y); } else { $transf->Rotate($pdf, ($w[$i] / 2 + $w[$i - 1] / 2) / $u * 360, $x, $y); } if ($fontwidth != 1) { $transf->StartTransform($pdf); $transf->ScaleX($pdf, $fontwidth * 100, $x, $y); } $pdf->SetXY($x - $w[$i] / 2, $y + $r - $pdf->FontSize); } $pdf->Cell($w[$i], $pdf->FontSize, $text[$i], 0, 0, 'C'); if ($fontwidth != 1) { $transf->StopTransform($pdf); } } $transf->StopTransform($pdf); }