pdf download html2pdf
Frage
Ich bin mit html2pdf Klasse pdf zu erzeugen. in meinem Problem erzeugt seine pdf für den HTML-Code aber nicht dem Dialogfeld Option geben, dass PDF zum Download bereit. plz help meine cose folgt.
<?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; }
?>
Lösung
Angebot zu Download von Ihrem Browser u die Header hinzufügen muß Befestigung für sein ...
header("Content-Disposition: attachment; filename=sample.pdf");
Fügen Sie den obigen Code am Anfang der Seite und dann mit der html2pdf Umwandlung gehen ..
Andere Tipps
Aus der Dokumentation, Verfahren Ausgabe
/**
* 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
*
Ändern Sie diese Zeile $html2pdf->Output('pdf_demo.pdf');
zu
$html2pdf->Output('pdf_demo.pdf', 'D');
und es wird Browser zwingen, um automatisch die pdf-Datei herunterladen.
Senden von PDF in Browser mit einem bestimmten Namen
$ html2pdf-> Ausgabe ( 'document_name.pdf');
$ html2pdf-> Ausgabe ( 'document_name.pdf', false);
$ html2pdf-> Ausgabe ( 'document_name.pdf', '');
$ html2pdf-> Ausgabe ( 'document_name.pdf', 'I');
Kraft des Browser die PDF-Datei mit einem bestimmten Namen
zum Download$ html2pdf-> Ausgabe ( 'document_name.pdf', 'D');
Schreiben Sie den Inhalt einer PDF-Datei auf dem Server
Achtung, diese Schrift auf dem Server muss mit Vorsicht verwendet werden. Keine Überprüfung auf das Vorhandensein der Datei
gemacht$ html2pdf-> Ausgabe ( 'Verzeichnis / filename_xxxx.pdf', 'F');
Rufen Sie die Inhalte der PDF und dann tun, was Sie wollen
$ content_PDF = $ html2pdf-> Ausgabe ( '', true);
$ content_PDF = $ html2pdf-> Ausgabe ( '', 'S');