0

Quiero probar un reporte, en la pagina donde estoy tengo siguiente codigo:

<!-- MODULO CABECERA -->
<?php
    include "views/modules/cabecera.php";
 ?>

 <!-- MODULO BOTONERA -->
 <?php
    include "views/modules/botonera.php";
 ?>

<?php

 if(isset($_POST['pdfPrint'])){

    require_once "../lib/tcpdf/tcpdf/tcpdf.php";

    $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Miguel Caro');
    $pdf->SetTitle($_POST['reporte_name']);
    $pdf->setPrintHeader(false); 
    $pdf->setPrintFooter(false);
    $pdf->SetMargins(20, 20, 20, false); 
    $pdf->SetAutoPageBreak(true, 20); 
    $pdf->SetFont('Helvetica', '', 10);
    $pdf->addPage();

    $content = '';

    $content .= '
        <div class="row">
            <div class="col-md-12">

      <table border="1" cellpadding="5">
        <thead>
          <tr>
            <th>DNI</th>
            <th>A. PATERNO</th>
            <th>A. MATERNO</th>
            <th>NOMBRES</th>
            <th>AREA</th>
            <th>SUELDO</th>
          </tr>
        </thead>
    ';

    $content .= '</table>';

    $content .= '
        <div class="row padding">
            <div class="col-md-12" style="text-align:center;">
                <span>Pdf Creator </span><a href="http://www.redecodifica.com">By Miguel Angel</a>
            </div>
        </div>

    ';

    $pdf->writeHTML($content, true, 0, true, 0);

    $pdf->lastPage();
    $pdf->output('Reporte.pdf', 'I');
}

?>


<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Reportes
        <small>Reporte de Lote y Orden de Trabajo</small>
      </h1>
  </section>
    <!-- Main content -->
    <section class="content container-fluid">
    <br><br><br>

      <div class="reporte">
            <input type="text" id="loteReport" class="text" placeholder="Digite el lote">
            <button class="btn btn-primary" id="reportBtn">Buscar lote para reporte</button>
      </div>
      <form action="POST">
        <button class="btn btn-secondary" name="pdfPrint">Imprimir</button> 
      </form>
      <br><br>

      </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

Cada vez que le doy al boton imprimir, me devuelve a la página de inicio de mi proyecto, como puedo hacer para que me abra el "pdf generado" o cual es mi error en el codigo?

(Tengo una lista blanca para los enlaces no si se tambien afecte a la hora de enviart el POST).

1 respuesta 1

1

En tu formulario, tienes declarada la action="POST", cuando eso va en method, tu formulario debería quedar de la siguiente manera,

<form action="" method="POST">.....

Cuando haces la impresión del pdf, agrega un die();, tu código continua ejecutando, y agrega las lineas que están en la parte inferior, haciendo que el pdf no se vea.

....
$pdf->output('Reporte.pdf', 'I');
die();
4
  • Igual sigue, me lanza al inicio
    – Baker1562
    el 24 feb. 2018 a las 22:46
  • en alguno de los dos ficheros que incluyes en la parte superior no haces la redirección al inicio? el 24 feb. 2018 a las 22:47
  • esos ficheros solo cargan otros php, como son la botonera y la cabecera, cada vez que toco el boton, me lanza al inicio y la url pasa a esto: http://localhost:8080/empaque/POST?pdfPrint= tiene algo que ver que este vacio despues del =?
    – Baker1562
    el 24 feb. 2018 a las 22:52
  • deja tu form de la siguiente forma <form action="" method="POST">.... el 24 feb. 2018 a las 22:54

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.