PHP生成报告(JasperReports)TCPDF错误:

时间:2013-12-17 15:30:55

标签: php jasper-reports

我正在尝试使用php生成报告。我跟着this instruction。但是我得到了一个我无法解决的错误。这是我反复犯的错误。

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 个答案:

答案 0 :(得分:1)

请注意,在您的PHP代码中,您已经编写了一些HTML标记,这实际上是错误的原因“TCPDF错误:某些数据已经输出,无法发送PDF文件。”

因此,如果您想在PHP代码上生成PDF文件,则无需编写任何HTML标记或任何php打印语句,如echo,print等。

按照给定的步骤做: -

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。并将PHP代码保存在create_report_view.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

}&GT;

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

我希望它能帮助您创建pdf报告。

如果你想在一个php页面中做上述事情,你只需要使用一些javascript弹出窗口。