Question

I followed the directions on the readme file but I didn't get any errors nor any output or anything written to the log file. so, what is the right way of converting and HTML file to PDF with prince, thank you in advance.

ini_set('display_errors', '1');
error_reporting(-1);

require 'prince.php';



$exepath='/Users/agk/Desktop/prince/bin/prince';
$prince= new Prince($exepath);

if(!$prince) die("Prince instantiation failed");


$prince->setHTML(TRUE);
$prince->setLog('prince.log');


$xmlPath='/Applications/MAMP/htdocs/test/newhtml.html';



$msgs= array();
$convert=$prince->convert_file($xmlPath, $msgs);


if(!$convert)
{
echo 'nothing converted';
var_dump($msgs);

 }
Was it helpful?

Solution

I notice you are using MAMP - and this is where I hit the same issue - and here's how I fixed it.

I managed to find an answer elsewhere on SO relating to running shell commands via PHP on MAMP, so will share this.

The problem is that the DYLD_LIBRARY_PATH is set in MAMP, and the shell/shell_exec command in PHP is looking elsewhere.

As explained in the original post, this might not be the best fix but it has me up and running for now - and the alternative suggestions there didn't work for me.

So, try this:

Open the /Applications/MAMP/Library/bin/envvars file and comment the following lines as below:

#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH

then restart Apache

It might mess up other MAMP settings, but I can live with that for now, as I need this to work locally on my Mac for testing before I load it all on a live Linux server.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top