• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FPDF

#1
Hello together,

I implemented the FPDF Library in my CI4 project. It is in app\Libraries\fpdf.php + font folder.

I added the following to autoload:
Code:
$classmap = [
    'FPDF' => APPPATH .'Libraries/fpdf.php'
];

In my Controller:
PHP Code:
use FPDF;

$pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        $pdf->Output(); 

If I open the page there is just the following output:

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp  �Z*�[����(hx����+���(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0��>��L�%�DI�8���~�%E*r�ﻻvҪHX�gvVk?/���Ῑ��`]�[�x5 �3\z��P�}����PO���j�Jݍ^���x6/f�����������|���4}�z�����}���@�,ۖ-��˺E�u�^�,���<� �Z_�K� IQ����Yd����C�K�_�%q�8>�!J"V!2&bGģ%r"H��D��\}2EL1n��h�j���e��"a*H����:��d��9c���[�X1~��"�3�g��Ñ�;O��> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R >> /XObject << >> >> endobj 7 0 obj << /Producer (FPDF 1.82) /CreationDate (D:20200512140733) >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 9 0000000000 65535 f 0000000228 00000 n 0000000867 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000749 00000 n 0000000971 00000 n 0000001047 00000 n trailer << /Size 9 /Root 8 0 R /Info 7 0 R >> startxref 1096 %%EOF

...If I use the same files / library in a standalone .php file it creates the PDF Undecided
[url=https://forum.codeigniter.com/javascript:void(0)][/url]

Does anyone has an idea how to get fpdf running?

best regards,
Niklas
Reply

#2
Before outputting data to the browser, you need to set the correct type of content.

PHP Code:
$this->response->setHeader('Content-Type''application/pdf');

$mpdf->Output(); 
Reply

#3
(05-12-2020, 09:26 AM)vitnibel Wrote: Before outputting data to the browser, you need to set the correct type of content.

PHP Code:
$this->response->setHeader('Content-Type''application/pdf');

$mpdf->Output(); 

Thank you!! That's it.
Reply

#4
hello @niklas
can you send me full code example how use fpdf?
i need it to my website
Reply

#5
hello,
i get this error:
is_file(): open_basedir restriction in effect. File(/var/www/vhosts/procreagency.com/dev.procreagency.com/CI/app/Libraries/fpdf182/fpdf.php/Config/Events.php) is not within the allowed path(s): (/var/www/vhosts/procreagency.com/:/tmp/)

How can fix it?
Reply

#6
(09-10-2020, 02:45 AM)pws Wrote: hello @niklas
can you send me full code example how use fpdf?
i need it to my website

Hello @pws
Copy fpdf library into ThridParty folder of your app.

in file app/Config/Autoload.php

PHP Code:
$classmap = [
 
  'FPDF' => APPPATH 'ThirdParty/fpdf182/fpdf.php',
]; 


in file app/Controllers/Test.php

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Test extends Controller {
    public function fpdf() {
        $pdf = new \FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        
        $this
->response->setHeader('Content-Type''application/pdf');
        $pdf->Output();
    }

Reply

#7
(09-11-2020, 08:10 PM)vitnibel Wrote:
(09-10-2020, 02:45 AM)pws Wrote: hello @niklas
can you send me full code example how use fpdf?
i need it to my website

Hello @pws
Copy fpdf library into ThridParty folder of your app.

in file app/Config/Autoload.php

PHP Code:
$classmap = [
 
  'FPDF' => APPPATH 'ThirdParty/fpdf182/fpdf.php',
]; 


in file app/Controllers/Test.php

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Test extends Controller {
    public function fpdf() {
        $pdf = new \FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        
        $this
->response->setHeader('Content-Type''application/pdf');
        $pdf->Output();
    }


In the previous version (3) the pdf logic was in the view , why you're doing this in the controller ?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.