使用FPDF库输出空白PDF-Codeigniter [英] Blank Output PDF using FPDF library - codeigniter

查看:53
本文介绍了使用FPDF库输出空白PDF-Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用FPDF库生成PDF报告,但输出为空白。没有显示错误,如何解决此问题?

I'm going to generate a PDF report using FPDF library, but the output is blank. There is no error displayed, how can I fix this problem?

无论如何,我在LOCALHOST中尝试了这段代码,并且效果很好,但是当我将其上传到云中时,没有任何输出要显示。这样的函数输出。.

Anyway, I tried this code in LOCALHOST and it works perfectly, but when I upload it to the cloud, there's no output to be displayed.. I tried to make the function output like this..

$this->fpdf->OUTPUT('try.pdf','I'); but nothing happens..

注意:在我的输出中,C:/ backup / employee _ .. php,输出在文件夹中,没有错误,并且工作正常。.但是当我上传此文件时,没有输出要显示

NOTE: In my output, C:/backup/employee_..php, the output is in the folder, there's no error and it works fine.. but when I upload this one, there no output to be display

这是我的控制器:

public function backup_employees_pdf()
{

    $this->load->library('fpdf');   

    define('FPDF_FONTPATH',$this->config->item('fonts_path'));
    $this->fpdf =new FPDF('L', 'mm', 'Legal', true, 'UTF-8', false);
    $this->fpdf->AliasNbPages();
    $this->fpdf->AddPage();

    //load data
    $data = array();
    $row = $this->m_employee->load_data_employees();
    $data = $row->result();

    // Whatever written here will come in header of the pdf file.

    $this->fpdf->Image('assets/images1/mpowerstafflogo.jpg',10,5,50,50,'','www.mpowerstaff.com');
    $this->fpdf->SetFont('Arial','B',15);
    $this->fpdf->Cell(140);
    $this->fpdf->Cell(50,10,'Employee File Management Website',0,0,'C');
    $this->fpdf->Ln(5);
    $this->fpdf->Cell(140);
    $this->fpdf->Ln(5);
    $this->fpdf->SetFont('Arial','',12);
    $this->fpdf->Cell(140);
    $this->fpdf->Cell(50,10,'3F Room 305 Jackson Bldg. 926 Arnaiz Ave., San Loreno Village Makati City, 1223 PHILIPPINES',0,0,'C');
    $this->fpdf->Ln(5);     
    $this->fpdf->Ln(5);
    $this->fpdf->Cell(140);
    $this->fpdf->Cell(50,10,'Tel. (632) 810-4026 * 810-9121',0,0,'C');
    $this->fpdf->Ln(5);
    $this->fpdf->Ln(5);
    $this->fpdf->Cell(140);
    $this->fpdf->Cell(50,10,'Email: mpowerstaff@yahoo.com',0,0,'C');
    $this->fpdf->Ln(10);
    $this->fpdf->SetFont('Arial','B',12);
    $this->fpdf->Cell(140);
    $this->fpdf->Cell(50,10,'Employees Report',0,0,'C');
    $this->fpdf->Ln(15);

    // Colors, line width and bold font
    $this->fpdf->SetFillColor(105,100,231);
    $this->fpdf->SetTextColor(255);
    $this->fpdf->SetDrawColor(60,89,117);
    $this->fpdf->SetLineWidth(0.3);
    $this->fpdf->SetFont('', 'B');

    // Header   
    $w = array(35,80,40,40,40,40,61);

    $this->fpdf->Ln();

    //border LRTB
    $this->fpdf->Cell(5);
    $this->fpdf->Cell(90,10,'NAME',1,0,'C', 'LR');
    $this->fpdf->Cell(60,10,'ACCOUNT NUMBER',1,0,'C', 'LR');
    $this->fpdf->Cell(60,10,'ADDRESS',1,0,'C', 'LR');
    $this->fpdf->Cell(60,10,'BIRTHDAY',1,0,'C', 'LR');
    $this->fpdf->Cell(60,10,'CONTACT NO.',1,0,'C', 'LR');
    $this->fpdf->Ln(10);

    // Color and font restoration
    $this->fpdf->SetFillColor(224, 235, 255);
    $this->fpdf->SetTextColor(0);
    $this->fpdf->SetFont('');

    $fill = 0;
    //data
    foreach($data as $empsItem)
    {      
        $this->fpdf->Cell(5);
        $this->fpdf->Cell(90,10,$empsItem->name,1,0,'C',$fill);
        $this->fpdf->Cell(60,10,$empsItem->account_no,1,0,'C',$fill);
        $this->fpdf->Cell(60,10,$empsItem->address,1,0,'C',$fill);
        $this->fpdf->Cell(60,10,$empsItem->birthday,1,0,'C',$fill);
        $this->fpdf->Cell(60,10,$empsItem->contact_no,1,0,'C',$fill);
        $this->fpdf->Ln(10);
        $fill=!$fill;   
    }

    $this->fpdf->Ln(30);
    $this->fpdf->SetFont('Arial','B',10);
    $this->fpdf->Cell(20, 5,'Total Employees: '.$row->num_rows(), '', 0, 'LR', 0);

    $this->fpdf->SetY(184);
    $this->fpdf->SetFont('Arial','I',8);
    $this->fpdf->Cell(0,10,'Copyright. All Rights Reserved',0,0,'C');
    $this->fpdf->Cell(0,10,'Page '.$this->fpdf->PageNo().' of {nb}',0,0,'C');

    $dir = 'C:/backup/';
    $filename = "employee report";

    $this->fpdf->Output($dir.$filename.'.pdf');
}

// ====这是我的模型=== //

//====THIS IS MY MODEL===//

public function load_data_employees()
{
    $query = $this->db->query("SELECT concat(e_first_name,' ',e_middle_name,' ',e_last_name) AS 'name',account_number AS 'account_no',address AS 'address',birthday AS 'birthday',contact_number AS 'contact_no'FROM tb_emp where status='available'");
    return $query;
}

// == CONFIG.PHP == //

//== CONFIG.PHP==//

$config['fonts_path']= "./system/fonts/font/";

这就是详细信息。我试图解决此问题,但仍然没有输出。

that's the details. I tried to fix this but still, there no output.

推荐答案

我遇到了同样的问题,这是我的解决方案:

I had the same problem and this was my solution:

而不是使用

$this->fpdf =new FPDF() 

我用过

$pdf = new FPDF();

然后您可以使用$ pdf-> ...而不是$ this-> pdf->。 ..

then u can use $pdf->... and not $this->pdf->...

这里是一个示例:

define('FPDF_FONTPATH',$this->config->item('fonts_path'));
$this->load->library(array('fpdf','fpdf_rotate','pdf'));
$this->pdf->Open();
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);
$pdf->SetDrawColor(0);
$pdf->MultiCell(100,5,"Test\n line of text");
$pdf->Output('test.pdf', 'D');

像吊饰一样工作;)

这篇关于使用FPDF库输出空白PDF-Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆