Generate pdf with dompdf in php

0

I want to generate a pdf document, using the dompdf library, of the variables collected from a form with the PHP POST method. When trying to generate the pdf, calling a third page does not show me the content of the variables.

    <?php 
ob_start();
?>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
  <head>
    <meta  charset='utf-8' />
    <title>Currículum Vitae</title>
    <link href="estilo.css" rel="stylesheet" />
  </head>

  <body>


<h1>Currículum Vitae</h1>

<h2>Datos Personales</h2>
<?php
$nombre = $_POST['nombre'];
$_SESSION['nombre'] = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
//$apellidos = $_SESSION['apellidos'];
$fecha_nacimiento = $_POST['fecha_nacimiento'];
//$apellidos = $_SESSION['apellidos'];
$telefono = $_POST['telefono'];
$genero = $_POST['genero'];
$domicilio = $_POST['domicilio'];
$localidad = $_POST['localidad'];

?>
<p>Mi nombre es: <?php echo $nombre.$apellidos ?>.</p>
<p>Mi fecha de nacimiento es: <?php echo $fecha_nacimiento ?>.</p>
<p>Mi género es: <?php echo $genero ?>.</p>
<p>Mi teléfono de contacto es: <?php echo $telefono ?>.</p>
<p>Vivo en: <?php echo $domicilio ?>.</p>
<p>Localidad: <?php echo $localidad ?>.</p>


<h2>Experiencia Profesional</h2>
<?php
$empresa = $_POST['empresa'];
$funciones = $_POST['funciones'];
$desde = $_POST['desde'];
$hasta = $_POST['hasta'];   
?>
<p>Empresa: <?php echo $empresa ?>.</p>
<p>Mis funciones eran: <?php echo $funciones ?>.</p>
<p>Estuve desde <?php echo $desde ?> hasta <?php echo $hasta ?>.</p>

<h2>Experiencia Académica</h2>
<?php
$titulo = $_POST['titulo'];
$centro = $_POST['centro'];
$desde1 = $_POST['desde1']; 
$hasta1 = $_POST['hasta1'];   
?>
<p>Titulo: <?php echo $titulo ?>.</p>
<p>Centro: <?php echo $centro ?>.</p>
<p>Desde <?php echo $desde ?></p> <p>Hasta <?php echo $hasta ?>.</p>

<h2>Datos de Interés</h2>
<?php
$idiomas = $_POST['idiomas'];
$carnet = $_POST['carnet'];
$comentarios = $_POST['comentarios'];
?>
<p>Mis idiomas son: <?php echo $idiomas ?>.</p>
<p>Carnet de conducir: <?php echo $carnet ?>.</p>
<p>Comentarios <?php echo $comentarios ?></p>



<form>
<input type="submit" action="processar_pdf.php" method='post' value="PDF"> <br/>
<br/>

</form> 

I do not know in what way the content of the variables can be maintained. I do not know whether to use SESSION. How should I create the third page?

  

proces_pdf.php

Please, someone gives me a hand. Thanks.

    
asked by Calej 19.11.2017 в 13:24
source

1 answer

0

It works for me in the following way:

<?php
require_once("dompdf/dompdf_config.inc.php");
$CargoSupervisor=$row['CARGO_SUP'];
$code='aquí va el html <tr>
        <td></td>
        <td class='ConBorde'>Cargo:</td>
        <td colspan='5' class='ConBorde'>".$CargoSupervisor."</td></td>
    </tr>'
// se crea una nueva instancia al DOMPDF
$dompdf = new Dompdf();
// se carga el codigo html
$dompdf->load_html(utf8_decode($code));
// aumentamos memoria del servidor si es necesario
ini_set("memory_limit","50M"); 
// lanzamos a render
$dompdf->render();
// guardamos a PDF
$dompdf->stream("PA03-PR04-F02.pdf");
?>

You have to keep in mind that DOMPDF only works for PHP 5 backwards, not in PHP 7 + versions.

Greetings!

    
answered by 29.01.2018 / 17:02
source