Пример #1
0
 function polygon($points, $color, $width = null, $style = null, $fill = false)
 {
     $this->_set_fill_color($color);
     $this->_set_stroke_color($color);
     if (!$fill && isset($width)) {
         $this->_set_line_style($width, "square", "miter", $style);
     }
     $y = $this->y(array_pop($points));
     $x = array_pop($points);
     $this->_pdf->moveto($x, $y);
     while (count($points) > 1) {
         $y = $this->y(array_pop($points));
         $x = array_pop($points);
         $this->_pdf->lineto($x, $y);
     }
     if ($fill) {
         $this->_pdf->fill();
     } else {
         $this->_pdf->closepath_stroke();
     }
 }
Пример #2
0
 /**
  * Returns the CFD as PDF
  *
  * @param array $data the CFD array
  * @param boolean $print_headers if set true, it prints the PDF directly
  * @return mixed
  */
 public static function getPDF(array &$data, $print_headers = false)
 {
     try {
         $p = new PDFlib();
         $p->set_parameter("errorpolicy", "return");
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SimpleCFD.php");
         $p->set_info("Author", self::encText($data['Emisor']['nombre']));
         $p->set_info("Title", "Factura No. " . $data['folio']);
         $p->set_info("Subject", "Factura emitada a " . self::encText($data['Receptor']['nombre']) . " el " . $data['fecha']);
         // set letter size
         $p->begin_page_ext(612, 792, "");
         $font = $p->load_font("Helvetica-Bold", "iso8859-1", "");
         $p->setfont($font, 12);
         $p->fit_textline("Factura", 30, 750, "fontsize=16 position=left");
         // Serie
         if (isset($data['serie'])) {
             $p->fit_textline("Serie: ", 120, 765, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={25 10}");
             $p->fit_textline($data['serie'], 145, 765, "fontsize=8 " . "position={bottom left} boxsize={60 10}");
         }
         // Folio
         $p->fit_textline("Folio: ", 120, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={25 10}");
         $p->fit_textline($data['folio'], 145, 750, "fontsize=8 " . "position={bottom left} boxsize={90 10}");
         // AnoAprobacion
         $p->fit_textline(self::encText("Año de Aprobación: "), 250, 765, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={80 10}");
         $p->fit_textline($data['anoAprobacion'], 330, 765, "fontsize=8 " . "position={bottom left} boxsize={20 10}");
         // NoAprobacion
         $p->fit_textline(self::encText("Número de Aprobación: "), 250, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={95 10}");
         $p->fit_textline($data['noAprobacion'], 345, 750, "fontsize=8 " . "position={bottom left} boxsize={65 10}");
         // Fecha
         $p->fit_textline("Fecha:", 425, 750, "fontsize=8 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={30 10}");
         $p->fit_textline($data['fecha'], 455, 750, "fontsize=8 " . "position={bottom left} boxsize={80 10}");
         // line
         $p->moveto(30, 740);
         $p->lineto(580, 740);
         $p->stroke();
         $p->setlinewidth(0.5);
         // Emisor
         $p->fit_textline("Emisor", 30, 720, "fontsize=10 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={200 20}");
         $p->fit_textline(self::encText($data['Emisor']['nombre']), 30, 695, "fontsize=18 " . "position={bottom left} boxsize={270 20}");
         $p->fit_textline("RFC: " . $data['Emisor']['rfc'], 30, 675, "fontsize=14 " . "position={bottom left} boxsize={270 15}");
         $domicilio = self::encText($data['DomicilioFiscal']['calle']) . " No. " . $data['DomicilioFiscal']['noExterior'];
         $domicilio .= isset($data['DomicilioFiscal']['noInterior']) ? " - " . $data['DomicilioFiscal']['noInterior'] : '';
         $p->fit_textline(self::encText($domicilio), 30, 660, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         unset($domicilio);
         $p->fit_textline(self::encText($data['DomicilioFiscal']['colonia']), 30, 645, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline(self::encText($data['DomicilioFiscal']['municipio']), 30, 630, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline("C.P. " . $data['DomicilioFiscal']['codigoPostal'], 30, 615, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         $p->fit_textline(self::encText($data['DomicilioFiscal']['estado']), 30, 600, "fontsize=12 " . "position={bottom left} boxsize={270 10}");
         // Receptor
         $p->fit_textline("Receptor", 380, 720, "fontsize=10 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={200 20}");
         $p->fit_textline(self::encText($data['Receptor']['nombre']), 310, 695, "fontsize=18 " . "position={bottom right} boxsize={270 20}");
         $p->fit_textline("RFC: " . $data['Receptor']['rfc'], 310, 675, "fontsize=14 " . "position={bottom right} boxsize={270 15}");
         $domicilio = self::encText($data['Domicilio']['calle']) . " No. " . $data['Domicilio']['noExterior'];
         $domicilio .= isset($data['Domicilio']['noInterior']) ? " - " . $data['Domicilio']['noInterior'] : '';
         $p->fit_textline($domicilio, 310, 660, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         unset($domicilio);
         $p->fit_textline(self::encText($data['Domicilio']['colonia']), 310, 645, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline(self::encText($data['Domicilio']['municipio']), 310, 630, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline("C.P. " . $data['Domicilio']['codigoPostal'], 310, 615, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         $p->fit_textline(self::encText($data['Domicilio']['estado']), 310, 600, "fontsize=12 " . "position={bottom right} boxsize={270 10}");
         // line
         $p->moveto(30, 585);
         $p->lineto(580, 585);
         $p->stroke();
         // Concepto
         // Cantidad
         $p->fit_textline("Cantidad", 30, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={50 10}");
         // Descripcion
         $p->fit_textline(self::encText("Descripción"), 100, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={65 10}");
         // Precio
         $p->fit_textline("Precio", 483, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={35 10}");
         // Importe
         $p->fit_textline("Importe", 540, 565, "fontsize=11 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={40 10}");
         // line
         $p->moveto(30, 555);
         $p->lineto(580, 555);
         $p->stroke();
         $count = count($data['Concepto']);
         static $pos = 552;
         for ($i = 0; $i < $count; ++$i) {
             $pos -= 20;
             // Cantidad
             $p->fit_textline($data['Concepto'][$i]['cantidad'], 30, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Descripcion
             $p->fit_textline($data['Concepto'][$i]['descripcion'], 100, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Valor unitario
             $p->fit_textline($data['Concepto'][$i]['valorUnitario'], 483, $pos, "fontsize=9 " . "position={bottom left} boxsize={145 10}");
             // Importe
             $p->fit_textline($data['Concepto'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         }
         // line cantidad
         $p->moveto(90, 580);
         $p->lineto(90, $pos - 10);
         $p->stroke();
         // line descripcion
         $p->moveto(470, 580);
         $p->lineto(470, $pos - 10);
         $p->stroke();
         // line
         $p->moveto(30, $pos - 20);
         $p->lineto(580, $pos - 20);
         $p->stroke();
         // Subtotal
         $pos -= 40;
         $p->fit_textline("SubTotal", 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
         $p->fit_textline($data['subTotal'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         // Traslado
         if (isset($data['Traslado'])) {
             $count = count($data['Traslado']);
             for ($i = 0; $i < $count; ++$i) {
                 $pos -= 20;
                 $p->fit_textline($data['Traslado'][$i]['impuesto'], 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline(" (Tasa: " . $data['Traslado'][$i]['tasa'] . "%)", 357, $pos + 1, "fontsize=6 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline($data['Traslado'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
             }
         }
         // Retencion
         if (isset($data['Retencion'])) {
             $count = count($data['Retencion']);
             for ($i = 0; $i < $count; ++$i) {
                 $pos -= 20;
                 $p->fit_textline(self::encText("Retención ") . $data['Retencion'][$i]['impuesto'], 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
                 $p->fit_textline($data['Retencion'][$i]['importe'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
             }
         }
         // Total
         $pos -= 20;
         $p->fit_textline("Total", 375, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom right} boxsize={145 10}");
         $p->fit_textline($data['total'], 435, $pos, "fontsize=9 " . "position={bottom right} boxsize={145 10}");
         // line importe
         $pos -= 10;
         $p->moveto(530, 580);
         $p->lineto(530, $pos);
         $p->stroke();
         // line
         $pos -= 10;
         $p->moveto(30, $pos);
         $p->lineto(580, $pos);
         $p->stroke();
         // noCertificado
         $pos -= 20;
         $p->fit_textline(self::encText("Número de Serie del Certificado:"), 30, $pos, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={145 10}");
         $p->fit_textline(self::encText($data['noCertificado']), 175, $pos, "fontsize=9 position={bottom left} boxsize={100 10}");
         // cadenaOriginal
         $p->fit_textline("Cadena original:", 30, $pos - 20, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={75 10}");
         $cad = explode(":::", wordwrap(self::encText($data['cadenaOriginal']), 150, ":::", true));
         $count = count($cad);
         $position_cad = $pos - 20;
         for ($i = 0; $i < $count; ++$i) {
             $position_cad -= 10;
             $p->fit_textline($cad[$i], 30, $position_cad, "fontsize=7 position={bottom left} boxsize={550 10}");
         }
         unset($count);
         // sello
         $position_cer = $position_cad - 20;
         $p->fit_textline("Sello Digital:", 30, $position_cer, "fontsize=9 fillcolor={rgb 0.6 0.3 0.6} " . "position={bottom left} boxsize={60 10}");
         $cer = explode(":::", wordwrap($data['sello'], 115, ":::", true));
         $count = count($cer);
         $position = $position_cer;
         for ($i = 0; $i < $count; ++$i) {
             $position -= 10;
             $p->fit_textline(self::encText($cer[$i]), 30, $position, "fontsize=7 position={bottom left} boxsize={550 10}");
         }
         unset($count);
         unset($cer);
         // note CFD
         $p->fit_textline(self::encText("Este documento es una impresión de un " . "Comprobante Fiscal Digital "), 150, $position - 30, "fontsize=10 " . "position={bottom left} boxsize={320 10}");
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
         unset($p);
         if ($print_headers) {
             $len = strlen($buf);
             header("Content-type: application/pdf");
             header("Content-Length: {$len}");
             header("Content-Disposition: inline; filename=hello.pdf");
             echo $buf;
             exit;
         }
         return $buf;
     } catch (PDFlibException $e) {
         die("PDFlib exception occurred in Factura:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n");
     } catch (Exception $e) {
         die($e);
     }
 }