0

I want to use this library: http://www.princexml.com/ That helps me create PDF files from an HTML/XML files.

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?

Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
  • In my experience, when you load a library, it creates an instance of that libraries worker (i.e. new Prince()), and adds it as a member to the CI object. So after you load it like you're doing: `$this->load->library('prince');`, you can access prince functions with `$this->();` – Glubus Mar 01 '16 at 15:21
  • no.. The first errors I get is because it's expecting a variable in the construct function within the library. and I'm not sure what to do. I tried adding the EXE path (using the ALIAS: `http://localhost/prince/prince.exe`) but it doesn't seem to work like that :X – Imnotapotato Mar 01 '16 at 15:31
  • Can you then verify that this does not work when you're removing the second line where you manually instantiate the Prince class? – Glubus Mar 01 '16 at 15:48
  • @Glubus yes, I get the same error :X – Imnotapotato Mar 02 '16 at 07:35
  • You might also try PrinceXML's cloud-partner: https://docraptor.com. That would remove the need for installing a library. – jamespaden Mar 02 '16 at 16:04

2 Answers2

0

You should try this:

public function banana(){
    // it should be a local path instead of URL
    $exe_path = 'c:\\some_folder\prince\prince.exe';
    // you can add parameter for the constructor call
    $this->load->library('prince', $exe_path);
    // it also should be a local path where the folder should be writable by apache
    $xmlPath = 'c:\\some_folder\temp\test.html';

    $this->prince->convert_file_to_passthru($xmlPath);
}
Zaragoli
  • 676
  • 4
  • 7
  • Not working. I tried both: `$exe_path = 'C:/Program%20Files%20(x86)/Prince/engine/bin/prince.exe';` and `$exe_path = 'C:\Program Files (x86)\Prince\engine\bin\prince.exe';` and this: `$xmlPath = 'C:\wamp\www\banana\index.html';` – Imnotapotato Mar 06 '16 at 10:00
  • And I have the `pronce.php` file in the library folder. What am I doing wrong? – Imnotapotato Mar 06 '16 at 10:00
  • I tried moving this to my ubuntu server and i got the same errors. I changed the variable from a string to `$params = array('exePath' => '/usr/bin/prince');` and I only get an error of `Array to string conversion php` – Imnotapotato Mar 06 '16 at 11:01
0

To use "Prince" as a library on CI:

  1. Add the Prince.php to the library folder (/application/library/Prince.php) and make sure the file names first letter is capitalized.

  2. 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);
    

    }

  3. 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.

Imnotapotato
  • 5,308
  • 13
  • 80
  • 147