Project

General

Profile

Documentation errors??

Added by Sloan Thrasher 11 months ago

In the example code, I see several ways to load the MultiCell class, none seem to work as shown. I've tried:

require_once("./libraries/fpdf/interpid/PdfLib/Multicell.php");

It does load the file, but then I try to instantiate the class, I get a class not found error.

$this->multiCell = new Multicell($this->pdf);

Ive seen examples using namespace, different class names, but haven't been able to get any of them to work. I've downloaded the latest version of both FPDF and MultiCell.

Sloan


Replies (11)

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

Also, I tried to run the example included in the download, and it doesn't run.

The error reported:

Fatal error: Class 'Interpid\PdfLib\Pdf' not found in /_hidden patth for security_/libraries/fpdfMultiCell/fpdf_multicell_2.6.3/library/interpid/PdfExamples/MyPdf.php on line 23

RE: Documentation errors?? - Added by Andrei Bintintan 11 months ago

Sloan Thrasher wrote:

In the example code, I see several ways to load the MultiCell class, none seem to work as shown. I've tried:

There are no several ways used to load the classes. The composer autoloader is being used.


require_once __DIR__ . "/../autoload.php";

Because namespaces are used, you'll have to use an autoloader, it's bad practice to include all the classes manually.

If you use composer, you can just add to it the library paths:


    "autoload": {
        "classmap": [
            "library/fpdf",
            "library/interpid"
        ]
    }

If you don't use composer, just include the provided autoloader.

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

Thanks for the info.

So, instead of

require_once("./libraries/fpdfMultiCell/fpdf_multicell_2.6.3/library/interpid/PdfLib/Multicell.php");

I should use:

require_once("./libraries/fpdfMultiCell/fpdf_multicell_2.6.3/autoload.php");

Is that correct?

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

I have a working PDF generator, I'm just trying to add the Multicell add-on so I can format one field with tags.

RE: Documentation errors?? - Added by Andrei Bintintan 11 months ago

Sloan Thrasher wrote:

I have a working PDF generator, I'm just trying to add the Multicell add-on so I can format one field with tags.

It will work. The integration should work well.

Keep in mind to extend the \Interpid\PdfLib\Pdf class as main pdf class instead of FPDF, because the mutlicell uses some properties from the FPDF which are not publicly available through interfaces.



use Interpid\PdfLib\Multicell;
use Interpid\PdfExamples\PdfFactory;
use Interpid\PdfLib\Pdf;

// Pdf extends FPDF
$pdf = new Pdf();

// Initialize the pdf object. Set the margins, adds a page, set default fonts etc...
PdfFactory::initPdf($pdf);

// Create the Advanced Multicell Object and inject the PDF object
$multicell = new Multicell($pdf);

Here the PdfFactory usage is optional. You can use your own initialization

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

I'm not familiar with namespaces, so I'm pretty confused. How are the paths to the actual files resolved. My program is running in a different folder.

My code is in CardPDF.

See the screenshot attached.

Screenshot_1.jpg View Screenshot_1.jpg 23.7 KB folder structure

RE: Documentation errors?? - Added by Andrei Bintintan 11 months ago

PHP Namespaces are the same concept as in Java, C#.
More details can be found here: https://www.php.net/manual/en/language.namespaces.php

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

As I said, not familiar with namespaces, and I had already read the stuff in the link you provided - didn't clear it up for me.

I have a class I''m using, I've tried putting the namespace and use statements before the class definition. I've also tried several variations. I declared "libraries" as the root, with the use statements having the path from there to the various class files. I've tried just the namespace/use statements based on the interpid folder as in the examples. Nothing seems to work.

Can you give an example where the class including the multicell class are in different folders?

RE: Documentation errors?? - Added by Andrei Bintintan 11 months ago

Just include the autoload properly.

require_once __DIR__ . "/../../library/fpdf_multicell_2.6.3/autoload.php";

Attached are examples of how to include the library from another folder.

RE: Documentation errors?? - Added by Sloan Thrasher 11 months ago

Thanks Andrei!!

I really appreciate your time answering my newbie-questions.

I'll give this a try shortly, but is the clearest example I've seen.

Sloan

    (1-11/11)