Domanda

sto usando la classe html2pdf per generare pdf.nel mio problema genera pdf per il codice html ma non fornisce l'opzione nella finestra di dialogo per scaricare quel pdf.per favore aiutami, le mie cose stanno seguendo.

<?php
ob_start();
include(dirname(__FILE__).'/res/pdf_demo.php');
$content = ob_get_clean();

// conversion HTML => PDF
require_once(dirname(__FILE__).'/../html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('P','A4', 'fr', false, 'ISO-8859-15');
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output('pdf_demo.pdf'); 
}
catch(HTML2PDF_exception $e) { echo $e; }
?>
È stato utile?

Soluzione

per offrire il download dal browser u bisogno aggiunge l'intestazione per essere allegato ...

header("Content-Disposition: attachment; filename=sample.pdf");

Aggiungere il codice di cui sopra all'inizio della pagina e quindi procedere con la conversione html2pdf ..

Altri suggerimenti

Dalla documentazione, metodo Output

    /**
     * Send the document to a given destination: string, local file or browser.
     * Dest can be :
     *  I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
     *  D : send to the browser and force a file download with the name given by name.
     *  F : save to a local server file with the name given by name.
     *  S : return the document as a string. name is ignored.
     *  FI: equivalent to F + I option
     *  FD: equivalent to F + D option
     *  true  => I
     *  false => S
     *

Cambia questa linea $html2pdf->Output('pdf_demo.pdf'); a $html2pdf->Output('pdf_demo.pdf', 'D'); e costringerà browser per scaricare automaticamente il file pdf.

Invia PDF per browser con un nome specifico

$ html2pdf-> Output ( 'document_name.pdf');

$ html2pdf-> Output ( 'document_name.pdf', false);

$ html2pdf-> Output ( 'document_name.pdf', '');

$ html2pdf-> Output ( 'document_name.pdf', 'I');

forzare il browser a scaricare il file PDF con un nome specifico

$ html2pdf-> Output ( 'document_name.pdf', 'D');

Scrivi il contenuto di un file PDF sul server

Attenzione, questa scrittura sul server deve essere utilizzato con cautela. Nessuna verifica è effettuata sulla esistenza del file

$ html2pdf-> Output ( 'directory / filename_xxxx.pdf', 'F');

Recuperare il contenuto del PDF e poi fai quello che vuoi

$ content_PDF = $ html2pdf-> Output ( '', true);

$ content_PDF = $ html2pdf-> Output ( '', 'S');

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top