Aditya
Aditya

Reputation: 63

How to print (thermal 58) starting from the top position using TCPDF PHP

I'm trying to create an invoice using php (tcpdf), but the results from the thermal (58 print) format always appear in the middle position.

How to make print from top position ?

Output PDF

Example Code :

<?php
require("fpdf/fpdf.php");
include_once "connectdb.php";

$pdf = new FPDF ('P','mm',array(80,145));
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(60,8,'AmmadMaf POS',1,1,'C');
$pdf->SetFont('Arial','B',8);
$pdf->Cell(60,5,'Block 5 Saadi Town, Karachi',0,1,'C');
$pdf->Cell(60,5,'Contact : +92 3222563301',0,1,'C');
$pdf->Cell(60,5,'E-mail Address : [email protected]',0,1,'C');
$pdf->Cell(60,5,'fb.com/ammadmaf',0,1,'C');
. bla . .
. bla . .
. bla . .
$pdf->Output();
?>

Upvotes: 0

Views: 2788

Answers (2)

K J
K J

Reputation: 11830

Dont try to print unitless PDF to a thermal printer, you will be attempting to send a Page Language to an esc/POS rolling 203 DPI printer that has variable lengths by using a roll cutter. IF you must use PDF ensure the content is matched to the roll width and cut length (harder done than said) @ the correct pixel resolution in monochrome and you may still often get castellated aliased graphics.

Your key issue is the page is defined for that printout as 128 inches high (1 full page height = 1 roll length) thus you need a format and driver that is not designed for pages.

For the Zj printers there are Cups system alternate driver at https://github.com/futurelink/cups-thermo-printer or https://github.com/klirichek/zj-58 and the manufacturer supplies a multi windows version XP to 10 driver for use with the printer.

Normally I would recommend using SeaGull BarTender for Windows USB thermal printing but that model is not clearly supported https://www.seagullscientific.com/support/downloads/drivers/

Idealy you should use the printers own variant of esc/POS thermal language as instantly runs text or esc/POS binary through the port direct, not PDF through a much slower system driver with a PDF translation into monochrome escodes/text/bitmap stream for slow spooling. The printer stream will NOT be a %PDF- it will look at the start somthing like

p @P@B

v0 0  yï¾ûï¾ûï¾ûï

It should contain "open drawer" and "stop rolling at end of print", plus for blade enabled plotters a "cut roll" command. A good esc/POS SDK will include template designers for ensuring the text and graphics are pixel perfect. This Epson template designer can produce an editable XML structure for use with simple web javascript. enter image description here

You say you still want an answer to the original question and in this case one option is to force the print page to the top of the paper roll page with a custom lower margin ! just beware there is no cut to be seen , so I would expect the whole page to be ejected all over the floor.

enter image description here

Upvotes: 1

Martin Zeitler
Martin Zeitler

Reputation: 76769

I'd suggest to use or write a proper ESC/POS driver; for example: https://github.com/klirichek/zj-58 There's even official drivers and mobile SDK: http://www.zjiang.com/en/init.php/service/driver
Together with a PHP library eg. escpos-php, so that one could eventually control the printer.

There's usually a page mode and line mode. Controlling the printer directly with escape sequences gives full control of line feeds, the cutter and the cash drawer. Opening the cash drawer with a key after having entered to amount is not how it's meant to work (which is where this questionable approach would lead). Just render to HTML with any monospaced font for on-screen preview.

Upvotes: 3

Related Questions