⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Printing to TCPDF



wonder
  • profile picture
  • Member

Posted 27 November 2015 - 14:37 PM

Hi there,

I have two controllers set up and both work correctly. One sets up a grocery crud table and the other prints a simple pdf page using the TCPDF library.

 

How do I take the output of the grocery crud table and get it to print as a pdf file?

 

Here is my standard grocery crud controller;

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class main extends CI_Controller {
 
    function __construct()
    {
        parent::__construct();
      
        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        /* ------------------ */ 
/* This is where we load the Grocery_CRUD */
        $this->load->library('Grocery_CRUD');
 
    }
 
    public function index()
    {
        echo "<h1>Welcome to the world of Grocery Crud</h1>";//Just an example to ensure that we get into the function
        die();
    }
  
 /* =========================================================================================== */
 /* ================================ PROJECTS CRUD ============================================ */
      public function projects()
    {
        $this->grocery_crud->set_table('projects');
        $output = $this->grocery_crud->render();
 
        $this->_example_output($output);        
    }
  
 /* =========================================================================================== */
 /* ================================ Output to TEMPLATES ====================================== */
    function _example_output($output = null)
 
    {
        $this->load->view('projects.php',$output);  
    }
}
 
/* End of file main.php */
/* Location: ./application/controllers/Main.php */

Here is the controller that creates a pdf;

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pdf_test extends CI_Controller {
 
    function __construct()
    {
        parent::__construct();
        $this->load->library("Pdf");
    }
    
 /* =========================================================================================== */
 /* ================================ create_pdf =============================================== */
    public function create_pdf() {
    // create new PDF document
    $pdf = new TCPDF();    
 
    // Add a page
    $pdf->AddPage();
           
    // Print text
    $pdf->write(5, 'How to get data into this pdf page from Grocery Crud?');   
      
    // Close and output PDF document
    $pdf->Output('example_001.pdf', 'I');    

    }
}
 
/* End of file Pdf_test.php */
/* Location: ./application/controllers/Pdf_test.php */

arronlee
  • profile picture
  • Member

Posted 27 February 2016 - 04:49 AM

Something went wrong with my pdf reader. I wanna convert pdf into text first. Any suggestion will be appreciated. Thanks in advance.