Forum How do I...?

getting prince to work in PHP

samWhisker
Hi Guys

First i want to apologize cos i am a complete newby to this, i suspect i am not alone so i would love an answer to my very simple question that will hopefully get more people up and running with this software. i assume its a pretty simple process but i am stumped!

so in its simplest form i have this

<?php

require_once $_SERVER["DOCUMENT_ROOT"] . '/Projects/XpressBook/assets/savepdf/prince.php';

$xmlString = 'hello world';
$path = $_SERVER["DOCUMENT_ROOT"] . '/Projects/XpressBook/assets/savepdf/lib/prince/bin/prince';

$prince = new Prince($path);
$prince->convert_string_to_passthru($xmlString)


?>


So my question is, assuming its not a server issue or an install of the library issue, is this enough for it to create a simple pdf file? or am i missing something? if i am waaaaaaaaaay of the mark any suggestions would be great, i dont mind doing a bit of googling to find my answer!

Thanks to anyone that can give me any advice at all

Cheers Guys :D
mikeday
Set the $xmlstring to some XML, with a root element, like "<html><body>Hello, world!</body></html>". If the input won't be well-formed XML, call setHTML(1); You may also wish to call setLog before convert, specifying a writable log file that Prince can save any error or warning messages to.
samWhisker
Hi Mike

Thanks for the response, and i appologise for not responding sooner, i have been focusing on other areas of the project

so it looks like my PHP is ok but i cant even write to an error log, i am wondering (and i appologise if i sound stupid here) do you have to install the program on the server or is it a matter of uploading it and just referencing it?

i have uploaded it to the required location to test, i copied a systemCall.php file from another user

<?php
function my_exec($cmd, $input='') {
    $proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);
    fwrite($pipes[0], $input);fclose($pipes[0]);
    $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);
    $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);
    $rtn=proc_close($proc);
    return "<p>Call <b>$cmd</b> result:" .
           "<dl><dt>stdout</td><dd>$stdout</dd>" .
           "<dt>stderr</dt><dd>$stderr</dd>" .
           "<dt>return</dt><dd>$rtn</dd></dl>";
}

$prince= '/usr/local/bin/prince';
echo(my_exec($prince));
?>


And i am getting this error. am i right in assuming it can find prince but its a server permissions error? have you experience of this? is it because i wasnt logged in as a root user when i uploaded it?

Call /usr/local/bin/prince result:

stdout
stderr
/usr/local/bin/prince: line 3: /usr/local/lib/prince/bin/prince: Permission denied /usr/local/bin/prince: line 3: exec: /usr/local/lib/prince/bin/prince: cannot execute: Permission denied
return
126


One final question, if i dont specify where i want the pdf saving or a name of the file, does it just choose one by default?

Sorry for firing questions over, its took me days to even get this far :-) your support is greatly appreciated

Sam
mikeday
Does /usr/local/lib/prince/bin/prince exist? Do you know what operating system the server is running? How did you upload Prince, and which package did you upload? Do you have command-line access on the server?
samWhisker
Hi Mike

you have been amazing so far thanks so much

I have now managed to get the prince software uploaded and i can find it, massive breakthough! :-)

my next job is to put some fonts on the server! i am getting this which is pretty helpfull

Thu Oct  6 10:32:48 2011: ---- begin
Thu Oct  6 10:32:48 2011: Loading document...
Thu Oct  6 10:32:48 2011: Converting document...
Thu Oct  6 10:32:48 2011: warning: no glyphs for character U+0048, fallback to '?'
Thu Oct  6 10:32:48 2011: internal error: no available fonts
Thu Oct  6 10:32:48 2011: ---- end


i will battle on with this for now! i guess this is out of your hands ha!

Thanks for your assistance so far

Sam