PDF تنزيل html2pdf
سؤال
أنا أستخدم فئة HTML2PDF لإنشاء PDF. في مشكلتي ، توليد PDF لرمز HTML ولكنه لا يعطي خيار مربع الحوار لتنزيل هذا PDF. الرجاء مساعدة بلدي cose يتبع.
<?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; }
?>
المحلول
لتقديم التنزيل من متصفحك ، تحتاج إلى إضافة رأس لكونه مرفق ...
header("Content-Disposition: attachment; filename=sample.pdf");
أضف الرمز أعلاه في بداية الصفحة ثم متابعة مع تحويل HTML2PDF ..
نصائح أخرى
من الوثائق ، إخراج الطريقة
/**
* 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
*
تغيير هذا الخط $html2pdf->Output('pdf_demo.pdf');
إلى$html2pdf->Output('pdf_demo.pdf', 'D');
وسوف يجبر المتصفح على تنزيل ملف PDF تلقائيًا.
أرسل PDF إلى المتصفح باسم محدد
$ html2pdf-> الإخراج ('document_name.pdf') ؛
$ html2pdf-> الإخراج ('document_name.pdf' ، false) ؛
$ html2pdf-> الإخراج ('document_name.pdf' ، '') ؛
$ html2pdf-> الإخراج ('document_name.pdf' ، 'i') ؛
إجبار المستعرض على تنزيل ملف PDF باسم محدد
$ html2pdf-> الإخراج ('document_name.pdf' ، 'd') ؛
اكتب محتويات ملف PDF على الخادم
الاهتمام ، يجب استخدام هذه الكتابة على الخادم الخاص بك بحذر. لا يتم التحقق من وجود الملف
$ HTML2PDF-> الإخراج ('DIRECTORY/FILENAME_XXXX.PDF' ، 'F') ؛
استرجع محتويات PDF ثم افعل ما تريد
$ content_pdf = $ html2pdf-> الإخراج ('' ، صحيح) ؛
$ content_pdf = $ html2pdf-> الإخراج ('' ، 's') ؛