Project

General

Profile

Task #1707

PHP Fatal error: Uncaught Error: Class 'Pdf_Multicell' not found

Added by Jerry Quinnell over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
Start date:
12/24/2018
Due date:
% Done:

0%

Estimated time:

Description

Hi Andrei,
Sorry to bother you but I've just got round to upgrading our product the Advanced Table and I'm getting the above error when running the code.

PHP Fatal error: Uncaught Error: Class 'Pdf_Multicell' not found in C:\xampp2\htdocs\skyline\PDFvendor\tcpdf_table\classes\pdfmulticell.php:24 Stack trace: #0 C:\xampp2\htdocs\skyline\pdf0-AAControl.php(281): require_once() #1 {main} thrown in :\xampp2\htdocs\skyline\PDFvendor\tcpdf_table\classes\pdfmulticell.php on line 24

I've moved the files into my project - so i have a folder called classes and tcpdf - and copied your files across...

My code is as follows - so I've got the require statements in ...
// Include the Advanced Multicell Class
require_once( "PDFvendor/tcpdf_table/classes/pdfmulticell.php" );
require_once( "PDFvendor/tcpdf_table/classes/pdftable.php" );
require_once( "PDFvendor/tcpdf_table/classes/pdf.php" );

Could you advise what I may be missing ?

Thanks in advance !!


Files

Screenshot_238.png View Screenshot_238.png 77.1 KB Andrei Bintintan, 12/28/2018 11:02 AM
Screenshot_239.png View Screenshot_239.png 129 KB Andrei Bintintan, 12/28/2018 11:02 AM
Screenshot_240.png View Screenshot_240.png 107 KB Andrei Bintintan, 12/28/2018 11:04 AM
#1

Updated by Andrei Bintintan over 5 years ago

The latest version is using an autoloader for the classes, so require_once stuff is not needed anymore. You'll have to define/include the autoloader in your php files.

Are the provided examples working in your case?

#2

Updated by Andrei Bintintan over 5 years ago

  • Status changed from New to Feedback
  • Assignee changed from Andrei Bintintan to Jerry Quinnell
#3

Updated by Jerry Quinnell over 5 years ago

Thanks for replying so quickly ...

I'm afraid I'm still not sure what I need to do - I've had a look at the examples and some are dated 2014. Some have requires. I've removed my requires as you suggest and it cant fiind the 'Pdf' class - so I'm assuming I do need a require somewhere ?

Could you advise what the autoloader is that you mention?

If you can point me to the actual code I need to include that would be a great help !

Thanks again ...
Jerry

#4

Updated by Andrei Bintintan over 5 years ago

I'll provide tomorrow a code sample. Please let me know which version are you using.

#5

Updated by Jerry Quinnell over 5 years ago

Hi,

I've downloaded both tcpdf_table_5.4.0 and tcpdf_table_5.4.1

Its 5.41 I'm trying to get working at present for Table and 2.6.1 for Multicell ...

Many thanks again,

Jerry

#6

Updated by Andrei Bintintan over 5 years ago

The new structure uses the composer autoload feature of the composer to map the class names to the specific files. It is very fast and reliable and it's the way to go for the future. It saves you tons of requires. It also allows a more easy inclusion in modern projects (which all use composer).
In the provided package there is a "vendor" library and that contains also the autoloader for the classes. It is provided and should work out of the box. If you are not familiar with composer, I do recommend to get familiar with.

Now, it may happen that you place the files somewhere else, in that case you will need to update the composer.json file classmap and the run the composer dump-autoload command to update the class mapping.
Also, the pdf classes were updated and the structure is changed, you might be using a very old structure that you need to change.

Have a look at the provided examples; they should work out of the box and should be a good example reference how to set it up.

See also the attached images.

#7

Updated by Jerry Quinnell over 5 years ago

Thank-you for the information - I will give it a proper go on Monday but my knowledge of classes etc is very minimal. We got a developer to write soe code for us which I extended across our system.

She wrote a piece of code - which extends the pdf class. I can get her to look at this but if you can spot anythig obvious with the class extend (and the reference tothe multicell bit ) then that may help too.

Sorry I know I'm asking a lot but do appreciate your help ... !

Rgds
Jerry

PS our extended class code below :-

class RedkitePdf extends Pdf
{

private $headerTxt;
private $address;
private $registration;
private $telephone;
private $email;
private $website;

public function construct($headerTxt, $address, $registration, $telephone, $email, $website ) {
$this->headerTxt = $headerTxt;
$this->address = $address;
$this->registration = $registration;
$this->telephone = $telephone;
$this->email = $email;
$this->website = $website;
parent::
construct();
}

/**
 * Custom Header
 *
 * @see Pdf::Header()
 */
public function Header()
{
    $this->SetY( 10 );

    /**
     * yes, even here we can use the multicell tag! this will be a local object
     */
    $oMulticell = PdfMulticell::getInstance( $this );
    $oMulticell->setStyle( "h1", 'Helvetica', "", 7, "170, 170, 170" );
    $oMulticell->multiCell( 160, 5, "<h1>". $this->headerTxt . date('j M Y') ."</h1>" );
    $this->SetY( $this->tMargin );
}


/**
 * Custom Footer
 *
 * @see Pdf::Footer()
 */
public function Footer()
{
    $this->SetY( -30 );
    $oMulticell = PdfMulticell::getInstance( $this );

    $oMulticell->setStyle( "span", 'Helvetica', "", 6, "170, 170, 170" );
    $oMulticell->multiCell(120,-1,'<span>'. $this->address. '</span>', 0, 'L');
    $oMulticell->multiCell( 0, 4, '<span>t: '.$this->telephone.' e: '.$this->email.'</span>', 0, 'R');      
    $oMulticell->multiCell( 150, 7, '<span>'.$this->registration.'</span>');
    $oMulticell->setStyle( "h1", 'Helvetica', "B", 10, "170, 170, 170" );
    $oMulticell->multiCell( 100, 7, '<h1>'.$this->website.'</h1>' );

    $this->SetFont( $this->getDefaultFontName(), 'I', 7 );
    $this->SetTextColor( 170, 170, 170 );

// $this->MultiCell( 0, 4, "Page {$this->PageNo()} / {$this->getAliasNbPages()}", 0, 'C' );
$this->MultiCell( 0, 4, "Page {$this->getPageNumGroupAlias()} / {$this->getPageGroupAlias()}", 0, 'C' );
}

/**
 * Returns the default Font to be used
 *
 * @return string
 */
public function getDefaultFontName()
{
    return 'helvetica';
}

/**
 * Draws the margin lines.
 * It's helpful during development
 */

public function drawMarginLines()
{
//draw the top and bottom margins
$ytop = $this->tMargin;
$ybottom = $this->h - 20;

    $this->SetLineWidth( 0.1 );
    $this->SetDrawColor( 150, 150, 150 );
    $this->Line( 0, $ytop, $this->w, $ytop );
    $this->Line( 0, $ybottom, $this->w, $ybottom );
    $this->Line( $this->rMargin, 0, $this->rMargin, $this->h );
    $this->Line( $this->w - $this->rMargin, 0, $this->w - $this->rMargin, $this->h );
}

}

#8

Updated by Jerry Quinnell over 5 years ago

Hi Andrei,

Ok so I've written a small program which now works - so I understand what I need to do within the program code now for tables.

But this program only works if it resides in your examples subfolder.

My program code sits in a parent folder above your code. So folder structure for my code is htdocs/myproject/mycode.php .... and your code is as /htdocs/myproject/PDFvendor/examples plus the other subfolders of content, library, tcpdf_table and vendor.

Now i dont want to really have all my code in your examples folder - so what do I have to do to your code (JSON file and others) so I can have my code in myproject folder? What library reference do i have to chnage and towhat ?

I've played around with it and keep getting errors referencing classes and functions - could you advise ?

Thanks very much in advance,

Jerry

Mycode that works if it resides in your examples folder is :-

<?php
echo (DIR);
require_once DIR . "/../autoload.php";
use Interpid\PdfLib\Multicell;
use Interpid\PdfLib\Table;
use Interpid\PdfExamples\pdfFactory;
$factory = new pdfFactory();
$oPdf = pdfFactory::newPdf( 'table' );
$oTable = new Table( $oPdf );
$oTable->initialize( array( 30, 55, 85 ) );
$oTable->close();
ob_end_clean();

$oPdf->Output();

#9

Updated by Andrei Bintintan over 5 years ago

The was you describe it, you could add this code in the htdocs/myproject/mycode.php and just adjust the "autoload.php" path.

Example:

require_once DIR. "/PDFvendor/autoload.php";
use Interpid\PdfLib\Multicell;
use Interpid\PdfLib\Table;
use Interpid\PdfExamples\pdfFactory;
$factory = new pdfFactory();
$oPdf = pdfFactory::newPdf( 'table' );
$oTable = new Table( $oPdf );
$oTable->initialize( array( 30, 55, 85 ) );
$oTable->close();
ob_end_clean();
$oPdf->Output();

#10

Updated by Jerry Quinnell over 5 years ago

Andrei,

That's great - many thanks I have it all working now ... I just need to get the Class extension working now ...

Thank you so much for all your help ...

Kind Regards
Jerry

#11

Updated by Andrei Bintintan over 5 years ago

  • Status changed from Feedback to Closed

You're very welcomed.

Also available in: Atom PDF