开发者

html2fpdf issue

开发者 https://www.devze.com 2023-04-02 10:32 出处:网络
I have the following php: html2fpdfconverter.php <?php require(\'html2fpdf.php\'); if(isset($_POST[\'data\'])){

I have the following php:

html2fpdfconverter.php

<?php

require('html2fpdf.php');

if(isset($_POST['data'])){
  $urlcontents = $_POST['data'];
  $filename = $_POST['filename'];
  $date = $_POST['date'];
  convert($urlcontents, $filenam开发者_Python百科e, $date);
}

function convert($contents, $name, $date){ 
  $pdf=new HTML2FPDF();
  $pdf->AddPage();
  $pdf->SetFont('Arial','B',16);
  $pdf->Cell(40,10, "Entry Report");
  $pdf->SetFont('Arial', '', 12);
  $pdf->Cell(90,12,'-   '. $date);
  $contents = strip_tags($contents, '<html><body><meta><img><h2><h4><br><div>');
  $pdf->SetY(20);
  $pdf->WriteHTML($contents );
  $pdf->Output($name, "D");  
}
?>

I trigger it using an AJAX call in jQuery based on the press of an HTML anchor:

 $("#exportentry").click(function(e){
 e.preventDefault();
 if(submitted){
   //export
   var data = $("#container").html();
   var filename = "Entry Report.pdf";
   var dateString = $("#datepicker").datepicker().val();
   $.ajax({
     type:"POST",
             url: "html2pdfconverter.php",
     data: {data:data, filename:filename, date:dateString},
             dataType: "json",
             success: function(data) {                
           //get min max dates assigned            
     alert('success');             
     }         
   })
 }else{
   alert("No Report To Export");
 }
 });

Nothing downloads however. I have this working using the exact same code for another file. I cannot figure out the problem.

Using firebug, I can see that the correct data is posted to htmlfpdfconverter.php. However, I cannot get the alert to trigger or the PDF to download. Any ideas?


You can see posted data so look for aresponse. It may be an error on php side andin that case error callback function is executed. Also dont forget to set error_reporting(0);

0

精彩评论

暂无评论...
验证码 换一张
取 消