class PDF extends FPDF not working - php

I am using FPDF to generate PDF invoices for osCommerce. My pdfinvoice.php file contains the following code to enhance the standard FPDF class:
class PDF extends FPDF {
}
For some reason unknown to me all functions defined within the PDF class are not working. To be able to successfully generate a PDF file I have go back to:
$pdf = new FPDF('P', 'pt', array(500,233));
instead of:
$pdf=new PDF( PDF_INV_PORTRAIT_LANDSCAPE,'mm', 'A4' );
In addition, any other reference to a function defined in the PDF class will stop the PDF file from being generated
NOTE: This behaviour only occurs when pdfinvoice.php is put into a specific subfolder. In my main folder all works fine!
For full details please refer to: http://forums.oscommerce.com/topic/271214-contribution-pdf-customer-invoice/page-34#entry1713911
Kind regards,
Dennis

Related

How to use namespace in the TCPDF?

I am trying to use TCPDF to print a pdf file in my php mvc project (model view controller), my problem is how to use namespace and use to make the tcpdf work.
i try this idea require_once(dirname(__FILE__).'/../TCPDF/TCPDF.php'); and it worked but i want to make it like this use MYPROJECT\TCPDF\TCPDF; and also i have been added this namespace MYPROJECT\TCPDF in all tcpdf php file and i get this erreur in the end class TCPDF_FONTS not found, although the TCPDF_FONTS file was added???
thanks for the help
You search for TCPDF_FONTS in class TCPDF_FONTS.
Then replace TCPDF_FONTS in function with namespace\TCPDF_FONTS.
I did the same and it worked.
Example:
public static function UTF8ArrayToUniArray($ta, $isunicode=true) { <br>
if ($isunicode) { <br>
return array_map(array('**src\pdf\tcpdf\include\TCPDF_FONTS**',
'unichrUnicode'), $ta);
} <br>
return array_map(array('**src\pdf\tcpdf\include\TCPDF_FONTS**', 'unichrASCII'), $ta); <br>
}

How to use PHPSpreadsheet in CodeIgniter 3 to read data from Excel (.xlsx and .xls) file?

Recently in one of my CodeIgniter based project, I need to read data from Excel file ( .xlsx and .xls ) and insert those data into MySQL. Unfortunately, I did not use PHPSpreadsheet before (as I did not require to work with Excel :( ).
So far what I did was, download the PHPSpreadsheet from Github and extract it to the root directory of my CodeIgniter Project.
PHPSpreadsheet in CodeIgniter root directory.
File Structure of PHPSpreadsheet.
So far I've tried to import the official docs example into my CI apps:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpSpreadsheet\IOFactory;
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$inputFileType = 'Xlsx';
$inputFileName = 'test.xlsx';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
print_r( $spreadsheet );
}
}
But it shows the following error!!
Can anyone tell me how can I use PHPSpreadsheet in CodeIgniter to read data from Excel file and store them into MySQL database?
Thanks
The easiest way to include PhpSpreadsheet is to use Composer - the documentation at https://phpspreadsheet.readthedocs.io/en/latest/ explains how to do this.
Otherwise you will need a PSR4 autoloader to load the class specified by your use statement or to include the files yourself. If you include files yourself, to read an Excel file you will need to include PhpSpreadsheet/src/PhpSpreadsheet/IOFactory.php

tcpdf codeigniter getting error

I am trying to implement tcpdf library in codeigniter but getting error
Fatal error: Cannot redeclare class Pdf in C:\xampp\htdocs\project\system\libraries\Pdf.php on line 6
here code example
path : "project\system\libraries\Pdf.php"
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';
class Pdf extends TCPDF
{
function __construct()
{
parent::__construct();
}
}
/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */
also Download latest
TCPDF
also want to know which is best TCPDF or DOMPDF to generate quick PDF ?
When using/making custom libraries, smart move would be (as CI makers advise too) to put it in APPPATH.'libraries/' because of upgrading version could overwrite/delete added files from system directory. That is why application folder is used for - to make any kind of custom files related to CI framework not touching default files/directories.
Other than that, error you've got there says there is more than one or better say there is two classes with same name. PHP doesn't allow that and every used file and/or class must have unique name. Possible solution should be renaming your file to
BASEPATH.'Pdf_lib.php'
and class name accordingly.
But again, if you are not limited with something else, move your class to
APPPATH.'libraries/Pdf_lib.php'
with following directories and subdirectories and files of tcpdf and use it from there.
I fix this error using bellow method. its happen coz same class is call from other TCPDF included file here's the solution
path : "project\system\libraries\Pdf.php"
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once '/tcpdf/tcpdf.php';
if (!class_exists('Pdf')) {
class Pdf extends TCPDF
{
function __construct()
{
parent::__construct();
}
}
}

TCPDF generate one PDF from multiple

I have a PDF class that extends TCPDF. I need to create several PDFs so I then have individual PDF classes which extend PDF. So for instance, I have something like this
class FirstPDF extends Pdf {
....code
}
class SecondPDF extends Pdf {
....code
}
Each of the PDF classes uses the Output function. Everything works great, I can happily create my PDFs like so
$pdf = new FirstPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false, $project);
$pdf->Output();
$pdf2 = new SecondPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false, $project);
$pdf2->Output();
I now want to give the option to generate all PDFs within a single PDF. The way I do it above produces separate PDF files.
Is there any way I can do this with TCPDF?
Thanks

How to convert HTML to PDF in PHP Codeigniter

I have a HTML form data getting from database.
I use PHP framework codeigniter . we want generate a PDF file from this HTML form data. tell me how to do.
You may wanna look at html2Pdf. It is a php class based on FPDF and it allows you to create PDF file from HTML. So just format your text using html and then create its pdf. Its very flexible and give greate control.
SorceForge Link
Or You can also look at this: Convert HTML + CSS to PDF with PHP?
Look at DomPDF https://github.com/dompdf/dompdf
Examples: http://pxd.me/dompdf/www/examples.php
By the way, on my project I use Zend Framework and ZendParadoxPDF to ge generate pdf. But it requires Java, so ASAP I'll redevelop it using DomPDF.
You can also use mPDF Library to create pdf in codeignator. create the mpdf.php file. After that put it into the CodeIgniter library directory.
copy this code to mpdf.php
if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once APPPATH.'/third_party/mpdf/mpdf.php';
class M_pdf {
public $param;
public $pdf;
public function __construct($param = "'c', 'A4-L'")
{
$this->param =$param;
$this->pdf = new mPDF($this->param);
}
}
Then, download mPDF Library from github or mpdf website.After downloading, Extract it and put the mpdf folder into CodeIgniter third_party directory.Then,
Open your controller(here,i am using Welcome controller) ,create a method on that controller as following
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function my_mPDF(){
$filename = time()."_order.pdf";
$html = $this->load->view('unpaid_voucher',$data,true);
// unpaid_voucher is unpaid_voucher.php file in view directory and $data variable has infor mation that you want to render on view.
$this->load->library('M_pdf');
$this->m_pdf->pdf->WriteHTML($html);
//download it D save F.
$this->m_pdf->pdf->Output("./uploads/".$filename, "F");
}
}
?>
Here, my_ mPDF function of Welcome controller will generate pdf file of common/template view file.
It’s done. I hope it will help you.

Categories