如何使用JasperReports将生成的PDF保存到服务器Yii中

时间:2016-10-18 07:30:26

标签: php yii jasper-reports

我需要将生成的PDF文件保存到我的服务器中。我正在使用JasperReports。

PDF生成的代码示例:

$this->widget('ext.Yiijasperserver.Yiijasperserver', array(
    'path' => '/reports/Crescent/call_list_report',
    'format' => 'pdf',
    'out' => 'I',
    'file' => 'call_list_report',
    'parameter' => array(
        'user_id' => $user_id,
        'from_date' => $from_date,
        'to_date' => $to_date,
        'status_id' => $status_id
    )
));

1 个答案:

答案 0 :(得分:0)

最后我得到了答案。在扩展文件夹yii

中的Yiijasperserver.php文件中添加了以下代码
public function run()
    {
        $client = new Jasper\JasperClient('localhost',
                   8080,
                  'jasperadmin', 
                  'jaspSyo@321*',
                  '/jasperserver');


    $report = $client->runReport($this->path, $this->format,$this->page,$this->parameter);

    header('Content-type: '.$this->mimetype[$this->format]);
            if($this->out=="I")
    header('Content-Disposition: inline; filename="'.$this->file.'.'.$this->format.'"');
    if($this->out=="D")
            header('Content-Disposition: attachment; filename="'.$this->file.'.'.$this->format.'"');


$file1 = 'C:\HostingSpaces\new.pdf';//New code added
file_put_contents($file1, $report);//New code added
echo $report;

}