ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How do i use Codeigniter or any existing library to generate pdf files using a blank pdf file

September 25, 2008 12:59am

Subscribe [6]
  • #1 / Sep 25, 2008 12:59am

    natleumas

    2 posts

    Hi all, i’m new to this framework.

    I am working on a project which requires me to

    Open up a pdf file (think of it as a template) with all the logos and boxes done up.
    Then put text into the pdf file using php and finally save it as a new pdf file.

    Anyone have done something similar to this?

    i think the closest library that i found is FPDF_TPL.

    How do i set up FPDF in codeigniter?

  • #2 / Sep 25, 2008 4:08am

    ray73864

    268 posts

    Hi all, i’m new to this framework.

    I am working on a project which requires me to

    Open up a pdf file (think of it as a template) with all the logos and boxes done up.
    Then put text into the pdf file using php and finally save it as a new pdf file.

    Anyone have done something similar to this?

    i think the closest library that i found is FPDF_TPL.

    How do i set up FPDF in codeigniter?

    Checkout this wiki article on the codeigniter wiki: http://codeigniter.com/wiki/fpdf_CIed/

  • #3 / Sep 25, 2008 4:25am

    natleumas

    2 posts

    Thanks ray73864 for the link.

    Any idea how should i setup the FPDF to work with codeigniter? or is it the other way, to setup codeigniter to work with FPDF?

    i am confused ~.~.~.~.~.~.~.~

  • #4 / Sep 25, 2008 5:51am

    outrage

    32 posts

    Kinda goes something like this:

    application
      libraries
        fpdf.php
        fpdf_tpl.php
        fpdi.php
        fpdi_pdf_parser.php
        pdf_context.php
        pdf_parser.php
        wrapper_functions.php


    Controller

    $this->load->library('fpdf');
    define('FPDF_FONTPATH',$this->config->item('fonts_path'));
                
    $this->load->library('fpdi');
                
    // initiate FPDI   
    $pdf =& new FPDI('P','mm','A4');
    // add a page
    $pdf->AddPage();
    // set the sourcefile
    $pdf->setSourceFile('resources/pdfs/your_pdf_template.pdf');
    // import page 1
    $tplIdx = $pdf->importPage(1);
    // use the imported page and place it at point 10,10 with a width of 100 mm
    $pdf->useTemplate($tplIdx, 1, 1, 210);
    // now write some text above the imported page
    $pdf->SetFont('Arial');
    $pdf->SetTextColor(0,0,0);
    
    // Write something
    $pdf->SetXY(88, 31);
    $pdf->Write(0, "Hello world");
    
    // Output
    $pdf->Output('resources/pdfs/archives/'. $pdf_name, 'F');


    Don’t forget the fonts folder:
    Add this to config.php

    $config['fonts_path']= "resources/font/";

    Works great for me, hope this helps.

  • #5 / Sep 25, 2008 10:08pm

    natleumas

    2 posts

    Thanks for that Outrage. this is gold!

    Appreciate it!

  • #6 / Apr 09, 2011 4:14pm

    Paul Hernández's avatar

    Paul Hernández

    10 posts

    Hi, I installed the FPDF and FPDI libraries in CI2.

    I get the following error when I try to load the library

    Instruction:

    $this->load->library('fpdf');
    Fatal error: Call to a member function library() on a non-object
    Message: Undefined property: pdf::$load

    I followed the instruction on the post above, a couple of files are missing: fpdf_tpl.php and wrapper_functions.php but I think it is due to the libraries version

    Any comment would be appreciated

  • #7 / Apr 09, 2011 4:55pm

    JonoB

    133 posts

  • #8 / Apr 09, 2011 6:06pm

    Paul Hernández's avatar

    Paul Hernández

    10 posts

    JonoB:

    Thank you very much for your fast reply 😉

    That’s exactly what i need

  • #9 / Apr 11, 2011 4:38am

    Paul Hernández's avatar

    Paul Hernández

    10 posts

    Hi JonoB:

    I’m still getting the same error when I tried to load the library:

    Message: Undefined property: pdf::$load
    Fatal error: Call to a member function library() on a non-object

    I read the custom libraries naming conventions and the pdf.php library does not meet them. I changed the file name and capitalized the file name (Pdf.php), the same with the class declaration, but I’m still getting the same error.

    Any idea?

    Can you post the config file tcpdf.php

    Thank and regards

  • #10 / Apr 11, 2011 5:37am

    JonoB

    133 posts

    Not sure how you have set it up, but I got it working as follows: http://codeigniter.com/wiki/TCPDF_Integration/

  • #11 / Apr 11, 2011 5:47am

    Paul Hernández's avatar

    Paul Hernández

    10 posts

    I have fixed the load library problem and I had to bump up the memory limit in the php.ini file, now I’m having other problems:

    - Message: Use of undefined constant K_CELL_HEIGHT_RATIO - assumed ‘K_CELL_HEIGHT_RATIO’

    - Message: Cannot modify header information - headers already sent by (output started at /home/pauldj54/Desktop/pdftest/system/core/Exceptions.php:170)

    I’ll check your link and others forum post. Thanks for your time!

  • #12 / Apr 11, 2011 9:22am

    InsiteFX's avatar

    InsiteFX

    6819 posts

  • #13 / Nov 07, 2013 11:59pm

    carelessnomad

    1 posts

    Kinda goes something like this:

    application
      libraries
        fpdf.php
        fpdf_tpl.php
        fpdi.php
        fpdi_pdf_parser.php
        pdf_context.php
        pdf_parser.php
        wrapper_functions.php


    Controller

    $this->load->library('fpdf');
    define('FPDF_FONTPATH',$this->config->item('fonts_path'));
                
    $this->load->library('fpdi');
                
    // initiate FPDI   
    $pdf =& new FPDI('P','mm','A4');
    // add a page
    $pdf->AddPage();
    // set the sourcefile
    $pdf->setSourceFile('resources/pdfs/your_pdf_template.pdf');
    // import page 1
    $tplIdx = $pdf->importPage(1);
    // use the imported page and place it at point 10,10 with a width of 100 mm
    $pdf->useTemplate($tplIdx, 1, 1, 210);
    // now write some text above the imported page
    $pdf->SetFont('Arial');
    $pdf->SetTextColor(0,0,0);
    
    // Write something
    $pdf->SetXY(88, 31);
    $pdf->Write(0, "Hello world");
    
    // Output
    $pdf->Output('resources/pdfs/archives/'. $pdf_name, 'F');


    Don’t forget the fonts folder:
    Add this to config.php

    $config['fonts_path']= "resources/font/";

    Works great for me, hope this helps.


    Outrage - Though your post was made many years ago, that was the key to me figuring out how to use CodeIgniter along with FPDF and FPDI. Thanks a bunch !! I am now able to customize PDF documents with CI and FPDI.

    Thanks.

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases