i want to print the bill to printer from php mysql database?
is it possible?
help me please!!!!!

Dani AI

Generated

Short answer: PHP cannot directly print to a user’s printer. Browsers control printing for security, so you cannot reliably bypass the print dialog with plain PHP/JS. If you truly need one-click or silent printing, use a trusted local helper (for example, QZ Tray) or a kiosk/managed environment. Otherwise, generate a print-friendly page or a PDF and let the user print it.

For dot‑matrix (DMP) invoices, browsers rasterize pages like a graphics printer, which can look slow or misaligned. DMPs work best with raw text and ESC/P or ESC/POS commands. If your DMP is a network printer reachable from the server (port 9100), you can send raw bytes from PHP:

<?php
$fp = @fsockopen("192.168.1.50", 9100, $errno, $errstr, 5);
if ($fp) {
    $esc = chr(27);
    $data  = $esc."@";                  // initialize
    $data .= $esc."E".chr(1)."ACME CORP\n".$esc."E".chr(0);
    $data .= "Invoice #12345\n";
    $data .= "Total: $12.34\n";
    $data .= chr(12);                   // form feed / cut on some models
    fwrite($fp, $data);
    fclose($fp);
}

Notes:

  • This only works if the printer is reachable from the server and supports raw/JetDirect (9100). Use the correct command set for your model (see the Epson ESC/POS reference).
  • For missing images: avoid CSS backgrounds (often not printed), use <img> with absolute URLs, ensure the images are publicly reachable, and check the browser’s “Background graphics” option if you rely on backgrounds. For crisp layout, prefer server‑generated PDFs.

PHP is a server-side scripting language. If you need to control printing, that's going to be handled client side. For example, you can include a button on your page, or an icon of a printer that lauches the printer controls of the user's PC. What you need to do is display the page accordingly so it's layout is printer friendly. You do that by appying the appropriate styles. You can use the @media rule to set the layout printer friendly.

Hi as JorgeM said you need a js for it to be done...my suggestion is

  1. Full the data from your db and arrange it as you desire
  2. On page load use windows.print() or add a button or image that when click will call the print dialog box.

like

on page load

<html>
<head>

</head>
<body onload="window.print()">

<?php

DATA FROM DB


?>

</body>
</html>

or using an image or button

 <html>
<head>

</head>
<body>

<?php

DATA FROM DB


?>
<img src="printer.png" width="28" height="28" onclick="window.print()" />

<input type="button" value="Print this page" onclick="printpage()">


</body>
</html>

i have tried

<input type="button" value="Print this page" onclick="printpage()">

but it shows no output
and when i use

<img src="printer.png" width="28" height="28" onclick="window.print()" />

its open printer diup box, if is good for laser printer/color printer, but it cteate problem for DMP printer i want solution for DMP printer

Unless you have defined a printpage() function in JavaScript, that button will not do anything. Your <img> tag uses the right code window.print(), you could change the button to use the same thing:

<input type="button" value="Print this page" onclick="window.print()">

As for problems with a dot-matrix printer, those aren't going to be resolved by anything you can do in the browser. The print dialog opened by window.print() is the browser's print dialog the same as if the user chose to print the page themselves. What problems exactly are you encountering?

Hello sir i am developing a project where i want to print a page/part of the page from web browser without print window using javascript or php. could u please help me how i could do so? if possible then please send me code or process. thank u.

here i have a problem..

i want to print a page in php with image, but image is not print..
please help somebuddy..

open a new thread, explain the issue and show the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.