Print directly to printer connected via JS or PHP

1

Imagine that I have a web page and I want to print a receipt for the client, that clicking on a button "Print" of the page gives me the option to choose the printer to print the PICTURE that you see on the screen.

Test code:

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Formulario de Login - Cliente</title>
        <link rel="stylesheet" href="css/estilos_iniciar_sesion.css">
        <script type="text/javascript" src="js/validar_iniciar_sesion_cliente.js"></script>
    </head>

    <body background="imagenes/fondo_campo2.jpg">
        <form name="miformulario" id="miformulario" action="logueo_cliente.php" method="POST" class="form" onsubmit="return validar_iniciar_sesion_cliente();">
            <h2>CLIENTE</h2>
            <h4>INICIAR SESIÓN</h4>
            <input type="text" placeholder="&#128272; Usuario" name="email" id="email" tabindex="1">
            <input type="password" placeholder="&#128272; Contraseña" name="password" id="password" tabindex="2">
            <div id="mensaje" align="center">
                <?php if(isset($_GET['error']) && $_GET['error'] == 'true'): ?>
                    <h4><p style="color:red;">¡Sus datos no son correctos!</p></h4>
                <?php endif; ?>
            </div>
            <div id="iniciar" align="center">
                <input type="submit" value="Iniciar sesión"><br/>
                <p class="form-link">¿Aún no tienes una cuenta? <a href="registrar.php">Regístrate aquí</a></p><br/>
                <p class="form-link"><a href="recuperar_contrasena.php">He olvidado mi contraseña</a></p><br/><hr/><br/>
                <p class="form-link"><img src="imagenes/entrar.jpg" height="10px" width="10px" alt="invitado"/>&nbsp;<a href="reservar.php">Entrar como invitado</a></p>
            </div>
        </form>
    </body>
</html>

I would have to add a " PRINT " button, what would be your code to send it to a printer and print it? Is there any class?

I put this image as proof so it should be printed.

    
asked by omaza1990 08.01.2018 в 00:02
source

3 answers

2

With this code you can do it

<A HREF="javascript:window.print()">Imprimir</A>
    
answered by 09.01.2018 / 13:31
source
2
answered by 08.01.2018 в 03:26
0

You talk about printing a receipt for the client. Since I see that you use PHP in your code, I could suggest what you do about the mPDF library. link But I do not know if it really is what you need.

    
answered by 08.01.2018 в 21:04