Skip to content

Instantly share code, notes, and snippets.

@evilnapsis
Last active February 18, 2022 16:34
Show Gist options
  • Save evilnapsis/583fbb73244452a4975ef4c71cd1ef15 to your computer and use it in GitHub Desktop.
Save evilnapsis/583fbb73244452a4975ef4c71cd1ef15 to your computer and use it in GitHub Desktop.
Formato de ticket para impresora de ticket
<?php
include "fpdf/fpdf.php";
$pdf = new FPDF($orientation='P',$unit='mm', array(45,350));
$pdf->AddPage();
$pdf->SetFont('Arial','B',8); //Letra Arial, negrita (Bold), tam. 20
$textypos = 5;
$pdf->setY(2);
$pdf->setX(2);
$pdf->Cell(5,$textypos,"NOMBRE DE LA EMPRESA");
$pdf->SetFont('Arial','',5); //Letra Arial, negrita (Bold), tam. 20
$textypos+=6;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'-------------------------------------------------------------------');
$textypos+=6;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'CANT. ARTICULO PRECIO TOTAL');
$total =0;
$off = $textypos+6;
$producto = array(
"q"=>1,
"name"=>"Computadora Lenovo i5",
"price"=>100
);
$productos = array($producto, $producto, $producto, $producto, $producto );
foreach($productos as $pro){
$pdf->setX(2);
$pdf->Cell(5,$off,$pro["q"]);
$pdf->setX(6);
$pdf->Cell(35,$off, strtoupper(substr($pro["name"], 0,12)) );
$pdf->setX(20);
$pdf->Cell(11,$off, "$".number_format($pro["price"],2,".",",") ,0,0,"R");
$pdf->setX(32);
$pdf->Cell(11,$off, "$ ".number_format($pro["q"]*$pro["price"],2,".",",") ,0,0,"R");
$total += $pro["q"]*$pro["price"];
$off+=6;
}
$textypos=$off+6;
$pdf->setX(2);
$pdf->Cell(5,$textypos,"TOTAL: " );
$pdf->setX(38);
$pdf->Cell(5,$textypos,"$ ".number_format($total,2,".",","),0,0,"R");
$pdf->setX(2);
$pdf->Cell(5,$textypos+6,'GRACIAS POR TU COMPRA ');
$pdf->output();
@grekodev
Copy link

grekodev commented Nov 6, 2019

Era lo que necesitaba gracias

@cley9
Copy link

cley9 commented Oct 22, 2021

crack

@Alrod8901
Copy link

$pdf = new FPDF($orientation='P',$unit='mm', array(45,350));
Alguna idea para no tener que pasar un tamaño largo en el height?
En impresoras térmicas funciona a la maravilla porque corta el papel luego de la última línea, pero en impresoras matriciales no(Si todavía hay quien las usa :-) )

@cley9
Copy link

cley9 commented Feb 18, 2022 via email

@Alrod8901
Copy link

Voy a darle un vistazo, Gracias 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment