简体   繁体   中英

html2pdf class, convert and redirect to a page doesn't works

I'm trying to redirect after html to pdf conversion but it doesn't works. I even tried to use a JavaScript readirect via window.load, still not working. This is the code...

<?php
session_start();
include('../includes/connection.php');
include('../includes/verify.php');

$id = $_GET['id'];
$_SESSION['id_accettazione'] = $id;
$query = "SELECT * FROM ((lavori INNER JOIN mezzi ON lavori.id_mezzo = mezzi.id_mezzo) INNER JOIN clienti ON mezzi.id_proprietario = clienti.id_cliente) WHERE id_lavorazione = $id";
$mezzo = $mysqli->query($query);
$info = mysqli_fetch_array($mezzo, MYSQLI_ASSOC);
$data = $info['data_accettazione'];
// var_dump($info);
// die();

$filename = $info['nome'] . ' ' . $info['cognome'] . ' - ' . $info['marca'] . ' ' . $info['modello'] . ' - ' . $data . '.pdf';

    // Carico HTML
    ob_start();

    include(dirname(__FILE__).'/template/foglio_lavorazione.php');

    $content = ob_get_clean();

    // Conversione in PDF
    require_once(dirname(__FILE__).'/html2pdf.class.php');
    try
    {
        $nomefile = $filename;
        $html2pdf = new HTML2PDF('P', 'A4', 'it', true, 'UTF-8', array(10,10,10,10));
        $html2pdf->setDefaultFont('Arial');
        $html2pdf->writeHTML($content);
        $html2pdf->Output($nomefile, 'D');
        header('location:../page.php');

    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }

?>

According to the documentation , it seems that there is a mistake in your header(). It's

 header('Location: ../page.php');

not

 header('location:../page.php');

Mind the case (and maybe also the space after ':'), I guess. It should at least solve one problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM