2013-12-17 124 views
1

我想使用PHP生成報告。我跟着this instruction。但是,我收到了一個我無法解決的錯誤。這是我重複發生的錯誤。PHP生成報告(JasperReports)TCPDF錯誤:

TCPDF錯誤:有些數據已經輸出,無法發送PDF文件。

以下是我的PHP代碼

 <html> 
    <head> 
     <meta charset="UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <form method="POST" action=""> 
      <input type="hidden" name="submit" value=""> 
     <input type="submit" name="commit" value="Login"> 
     </form>   
    </body> 
</html> 
<?php 
if(isset($_POST['submit'])) 
{ 
//Import the PhpJasperLibrary 
include_once("PhpJasperLibrary/tcpdf/tcpdf.php"); 
include_once("PhpJasperLibrary/PHPJasperXML.inc.php"); 



    //database connection details 

$server="localhost"; 
$db="hotel"; 
$user="root"; 
$pass=""; 
$version="0.8b"; 
$pgport=5432; 
$pchartfolder="./class/pchart2"; 



//display errors should be off in the php.ini file 
ini_set('display_errors', 0); 

//setting the path to the created jrxml file 
$xml = simplexml_load_file("Report/report9.jrxml"); 

$PHPJasperXML = new PHPJasperXML(); 
//$PHPJasperXML->debugsql=true; 
//$PHPJasperXML->arrayParameter=array("parameter1"=>1); 
$PHPJasperXML->xml_dismantle($xml); 

$PHPJasperXML->transferDBtoArray($server,$user,$pass,$db); 
$PHPJasperXML->outpage("I"); //page output method I:standard output D:Download file 

}?> 

這是我的JRXML

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report9" language="groovy" pageWidth="460" pageHeight="800" columnWidth="420" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> 
    <property name="ireport.zoom" value="1.0"/> 
    <property name="ireport.x" value="0"/> 
    <property name="ireport.y" value="0"/> 
    <queryString> 
     <![CDATA[SELECT * FROM hkschedule]]> 
    </queryString> 
    <field name="scheduleid" class="java.lang.Integer"/> 
    <field name="staffID" class="java.lang.String"/> 
    <field name="day" class="java.lang.String"/> 
    <field name="TimeRange" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="79" splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band height="35" splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="30" splitType="Stretch"> 
      <staticText> 
       <reportElement x="13" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[scheduleid]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="156" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[day]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="285" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[TimeRange]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="33" splitType="Stretch"> 
      <textField> 
       <reportElement x="13" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{scheduleid}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="156" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{day}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="285" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{TimeRange}]]></textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
    <columnFooter> 
     <band height="45" splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band height="54" splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band height="42" splitType="Stretch"/> 
    </summary> 
</jasperReport> 

回答

1

請注意,在你的PHP代碼你寫這實際上是原因錯誤某些HTML標記「TCPDF ERROR :有些數據已經輸出,不能發送PDF文件。「

所以,如果你想生成一個PDF文件,在你的PHP代碼,你不需要寫任何HTML標記或任何PHP報表打印樣回聲,打印等

根據給定的步驟做: -

1.保存的HTML代碼中create_report.html: -

<html> 
<head> 
    <meta charset="UTF-8"> 
    <title></title> 
</head> 
<body> 
    <form method="POST" action="create_report_view.php"> 
     <input type="hidden" name="submit" value=""> 
    <input type="submit" name="commit" value="Login"> 
    </form>   
</body> 

======================== ================================================== === =======

2.並保存在create_report_view.php PHP代碼: - ?

<?php 

    if(isset($_POST['submit'])) 
    { 
    //Import the PhpJasperLibrary 

    include_once("PhpJasperLibrary/tcpdf/tcpdf.php"); 
    include_once("PhpJasperLibrary/PHPJasperXML.inc.php"); 
    //database connection details 

    $server="localhost"; 
    $db="hotel"; 
    $user="root"; 
    $pass=""; 
    $version="0.8b"; 
    $pgport=5432; 
    $pchartfolder="./class/pchart2"; 


    //display errors should be off in the php.ini file 
    ini_set('display_errors', 0); 

    //setting the path to the created jrxml file 
    $xml = simplexml_load_file("Report/report9.jrxml"); 

    $PHPJasperXML = new PHPJasperXML(); 
    //$PHPJasperXML->debugsql=true; 
    //$PHPJasperXML->arrayParameter=array("parameter1"=>1); 
    $PHPJasperXML->xml_dismantle($xml); 

    $PHPJasperXML->transferDBtoArray($server,$user,$pass,$db); 
    $PHPJasperXML->outpage("I"); //page output method I:standard output D:Download file 

}>

============ ================================================== ======================

我希望它能幫助你創建pdf報告。

如果你想在一個單一的PHP頁面做上述事情,你只需要使用一些JavaScript的彈出窗口。