Using external class

class page_pdf extends Page{
public function init() {
parent::init();
require dirname(FILE).’…/…/…/libs/src/Knp/Snappy/GeneratorInterface.php’;
require dirname(FILE).’…/…/…/libs/src/Knp/Snappy/AbstractGenerator.php’;
require dirname(FILE).’…/…/…/libs/src/Knp/Snappy/Image.php’;

    require dirname(__FILE__).'../../../libs/src/Knp/Snappy/Pdf.php';
    $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
    $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money dude.</p>', dirname(__FILE__).'../../logs/bill-123.pdf');
}

}

Error :
Exception_PathFinder: Class is not defined in file

Hi,

the Pdf Class is using namespaces. It should work like that:

<?php class page_pdf extends Page{ public function init() { parent::init(); require dirname(__FILE__).'/../libs/src/Knp/Snappy/GeneratorInterface.php'; require dirname(__FILE__).'/../libs/src/Knp/Snappy/AbstractGenerator.php'; require dirname(__FILE__).'/../libs/src/Knp/Snappy/Image.php'; require dirname(__FILE__).'/../libs/src/Knp/Snappy/Pdf.php'; $snappy = new \Knp\Snappy\Pdf('/usr/local/bin/wkhtmltopdf'); $snappy->generateFromHtml('

Bill

You owe me money dude.

', dirname(__FILE__).'../../logs/bill-123.pdf'); } } I changed some paths and corrected some typos e.g. FILE to __FILE___. Sincerly, Phil

Thank you,
for : new \Knp\Snappy\Pdf

:smile:

I have created a ATK4 wrapper around wkhtmltopdf library, by using quite old version of this class: https://github.com/mikehaertl/phpwkhtmltopdf

It works fine for about a year in production system.
There are some bugs in it, but it’s not my class bugs, but bugs in wkhtmltopdf library as such.
For example this one with font sizes: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2171