I want to use this library: http://www.princexml.com/ That helps me create PDF files from an HTML/XML files.
I downloaded the PHP zip file from here: http://www.princexml.com/download/wrappers/ and added it to my "libraries" folder in the codeigniter directory. from what I know, I just have to include/call the library and use it's functions regularly. https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
I am using WAMP (Windows) so I created an Alias to C:\Program Files (x86)\Prince\engine\bin
where the prince.exe is found, and called it "prince" (http://localhost/prince
).
had this on my controller:
public function banana(){
$this->load->library('prince');
$prince = new Prince('http://localhost/prince/prince.exe');
$xmlPath = 'http://localhost/temp/test.html';
$this->prince->convert_file_to_passthru($xmlPath);
}
And I got these errors:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Prince::__construct(), called in C:\wamp\www\tools\system\core\Loader.php on line 1247 and defined
Filename: libraries/prince.php
Line Number: 48
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 48 Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: exePath
Filename: libraries/prince.php
Line Number: 50
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 50 Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Warning
Message: proc_open(): CreateProcess failed, error code - 87
Filename: libraries/prince.php
Line Number: 796
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 796 Function: proc_open
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528 Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
An uncaught Exception was encountered
Type: Exception
Message: Failed to execute "" --structured-log=buffered "http://localhost/temp/test.html" -o -
Filename: C:\wamp\www\tools\application\libraries\prince.php
Line Number: 814
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528 Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
This is my first time running an external library from CodeIgniter, I am not sure what to do and codeigniter docs don't mention too much information.
Creating the ALIAS didn't work, so I think this is why it's not recognizing the variable of the exePath
.
How do I all the "Prince" library and get it working on CodeIgniter?
To use "Prince" as a library on CI:
Add the Prince.php to the library folder (/application/library/Prince.php) and make sure the file names first letter is capitalized.
To pass in variables to the library it has to be done using an array, and not a simple string. $exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
public function banana(){
// it should be a local path instead of URL
$exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
// you can add parameter for the constructor call
$this->load->library('prince', $exePath);
// it also should be a local path where the folder should be writable by apache
$xmlPath = 'C:\wamp\www\tools\files\banana\test.html';
$pdfPath = 'C:\wamp\www\tools\files\banana\test.pdf';
$this->prince->convert_file_to_file($xmlPath, $pdfPath);
}
The construct grabs the variable as an array and not as a string like it should be! So I edited the __construct
a little bit:
public function __construct($exePathArr)
{
// var_dump($exePathArr);
$exePath = "banana"; // just to make sure that this var is a string :P
// var_dump($exePath);
$exePath = $exePathArr['exePath'];
// var_dump($exePath);
$this->exePath = $exePath;
$this->styleSheets = '';
$this->scripts = '';
...
.......
..........
This is the post opened in "Prince" website: http://www.princexml.com/forum/topic/3318/princexml-and-codeigniter-how-to-add-the-library?p=1#16234
Hope this will help people who need this too.
I tested this both on WAMP and UBUNTU SERVER.