Download PDF in HORIZONTAL format of DataTable?

0

Greetings,

I'm trying to download a PDF file that generates the DataTable but I download it in vertical format and it looks bad, I need it horizontally Does anyone know how?

<?php
	$TIPO_BUSQUEDA = $_POST["TIPO_BUSQUEDA"];
    function ejecuta_consulta($labusqueda)
    {
        include("conexiond.php");

        $conexion= mysqli_connect($db_host, $db_usuario, $db_contra);

        if (mysqli_connect_errno()) {
            echo "Fallo al conectar con la base de datos";
            exit();
        }

        mysqli_select_db($conexion, $db_nombre) or die("No se encuentra la base de datos.");


        $consulta = "SELECT datosbasicos.CED_PAC,datosbasicos.NOM_PAC,datosbasicos.APE_PAC,datosbasicos.SEX_PAC,datosmedicos.COD_CONSULTA,datosmedicos.ALT_PAC,datosmedicos.PESO_PAC,datosmedicos.FECHA,datosmedicos.TIPO_CONSULTA,datosmedicos.SINTOMAS,datosmedicos.OBSERV,datosmedicos.HIS_PAC,datosmedicos.MEDI_PAC,datosmedicos.OPERADO,datosmedicos.ALERGIAS FROM datosbasicos INNER JOIN datosmedicos ON datosbasicos.CED_PAC=datosmedicos.CED_PAC WHERE datosbasicos.NOM_PAC LIKE '%$labusqueda%' OR datosbasicos.CED_PAC LIKE '$labusqueda' OR datosmedicos.COD_CONSULTA LIKE '%$labusqueda%' OR datosbasicos.CED_PAC LIKE '$labusqueda' OR datosmedicos.FECHA LIKE '$labusqueda'  ";

        $resultados = mysqli_query($conexion, $consulta);

        $filas = array(); // Crea la variable $filas y se le asigna un array vacío
        // (Si la consulta no devuelve ningún resultado, la función por lo menos va a retornar un array vacío)

        while ($fila=mysqli_fetch_array($resultados, MYSQLI_ASSOC)) {
            $filas[] = $fila; // Añade el array $fila al final de $filas
        }

        mysqli_close($conexion);

        return $filas; // Devuelve el array $filas
    }
?>

<!DOCTYPE html>
<html>

<head>
    <title>Sistema de historias médicas - Dr. Darling Davila</title>
    <meta charset="utf-8">
    <link rel="stylesheet"  href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/estilo.css">
    <link href="https://fonts.googleapis.com/css?family=Lato|Roboto" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
    <link rel="stylesheet"  href="https://cdn.datatables.net/buttons/1.4.0/css/buttons.dataTables.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script >
            $(document).ready(function(){
        $('#tabla').DataTable();
    });

    </script>
</head>

<body>
    <?php
        $mibusqueda=$_GET["buscar"];

        $mipag=$_SERVER["PHP_SELF"];

        if ($mibusqueda!=null) {
            $pacientes = ejecuta_consulta($mibusqueda);
    ?>

        <div id="main-container">
        <img src='imagenes/header.png' class='img'>
            <table id="tabla">
                <thead>
                    <tr>
                        <th>Codigo</th>
                        <th>Fecha</th>
                        <th>Cedula</th>
                        <th>Nombres</th>
                        <th>Apellidos</th>
                        <th>Sexo</th>
                        <th>Altura</th>
                        <th>Peso</th>
                        <th>Sintomas</th>
                        <th>Observaciones</th>
                        <th>Tipo de consulta</th>
                        <th>Medicamentos actuales</th>
                        <th>Alergias</th>
                        <th>Operado</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    // Si la variable $pacientes esta definida y no está vacía
                    if (isset($pacientes) && !empty($pacientes)) {
                        // Recorre cada $paciente dentro del array $pacientes
                        foreach ($pacientes as $paciente) {
                            ?>
                        <tr>
                            <td><?php echo $paciente['COD_CONSULTA'] ?></td>
                            <td><?php echo $paciente['FECHA'] ?></td>
                            <td><?php echo $paciente['CED_PAC'] ?></td>
                            <td><?php echo $paciente['NOM_PAC'] ?></td>
                            <td><?php echo $paciente['APE_PAC'] ?></td>
                            <td><?php echo $paciente['SEX_PAC'] ?></td>
                            <td><?php echo $paciente['ALT_PAC'] ?></td>
                            <td><?php echo $paciente['PESO_PAC'] ?></td>
                            <td><?php echo $paciente['SINTOMAS'] ?></td>
                            <td><?php echo $paciente['OBSERV'] ?></td>
                            <td><?php echo $paciente['TIPO_CONSULTA'] ?></td>
                            <td><?php echo $paciente['MEDI_PAC'] ?></td>
                            <td><?php echo $paciente['ALERGIAS'] ?></td>
                            <td><?php echo $paciente['OPERADO'] ?></td>
                        </tr>
                    <?php
                        }
                    } ?>
                </tbody>
        </div>
    <?php
        } else {
            echo("<form action='". $mipag . "' method='GET'>
                <img src='imagenes/header.png'>
                    <h2>Busqueda de paciente</h2>
                    <div class='contenedor'>
                    <select name='TIPO_BUSQUEDA' class='input-100 text-center col-md-12'>
						<option value='Cedula' selected='selected' <?PHP if($TIPO_BUSQUEDA=='Cedula'){ echo 'selected='selected'; } ?> Cedula</option>
	 					<option value='Edad' <?PHP if($TIPO_BUSQUEDA=='Edad'){ echo 'selected='selected'; } ?> Edad</option>
      					<option value='Nombre' <?PHP if($TIPO_BUSQUEDA=='Nombre'){ echo 'selected='selected'; } ? >Nombre</option>
      					<option value='Fecha' <?PHP if($TIPO_BUSQUEDA=='Fecha'){ echo 'selected='selected'; } ?> Fecha</option>
					</select>
                    <input type='text' name='buscar' class='input-100 text-center inline-block col-md-6 btn-enviar espacio-arriba'></label>

                    <input type='submit' name='enviando' value='Consulta' class='text-center inline-block col-md-12 espacio-arriba btn-enviar'>
                </div>
                </form>");
        }
     ?>


     <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
     <script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
     <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.4.0/js/dataTables.buttons.min.js"></script>
     <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.4.0/js/buttons.flash.min.js"></script>
     <script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>

     <script type="text/javascript">
         $('#tabla').DataTable( {
        dom: 'Bfrtip',
        buttons: [
        {
            extend: 'pdf',
            text: 'Save as PDF',
            exportOptions: {
                modifier: {
                    orientation:'landscape'
                }
            }
        }
    ]
        });
     </script>
</body>

</html>
    
asked by Pablo Pernia 23.08.2017 в 04:07
source

1 answer

0

The orientation option is not available within exportOptions , which only serves to determine the data that is exported, it should be used directly in the button configuration options.

So it should be written as follows:

buttons: [
  {
    extend: 'pdf',
    text: 'Save as PDF',
    orientation: 'landscape'

  }
]

Documentation .

    
answered by 23.08.2017 / 06:25
source