Forum How do I...?

pdf not being written

monsto
first of all, this is a great app mainly because it doesn't pretend to do too much. i like the fact that there are only 4 ways to work the conversion -- that's really all that's necessary imo -- and the config options are few and simple. there's a lot to be said for the K.I.S.S. approach, so nice job.

so . . . i've tried this a couple different ways, but ultimately, the pdf either isn't being saved to webserver or it's data isn't being handled by prince i'm not sure which . . .

what i have now is a complete webpage that generates content (display.php) and a script to convert that webpage (vert.php). so the theory is that when i'm ready to output the display to pdf, i'll run the converter directly.

i've included the php library made some configs and added the additional header (some bits have been changed to protect the elderly)

require_once ('/home/users/. . ./prince-6.0r8-linux/prince-php5-r5/prince.php');

//call and use prince
$prince = new Prince('/usr/local/bin/prince');

//configure
$prince->setHTML(1); 
$prince->setLog('/var/vhosts/domain.com/logs/prince.log'); << permissions 666
$prince->addStyleSheet('/var/vhosts/domain.com/html/style.css'); 
$prince->setBaseURL('http://domain.com/');
header('Content-type: application/pdf'); 


then i run the thing with a little error handling.

$vert = $prince->convert_file_to_file("display.php", "/var/vhosts/domain.com/html/show.pdf", $msgs=array()); // converting display.php to a file
if ($vert === TRUE) {
    echo "Yay." ;
} else {
    echo "Boo.";
    echo "err = " . $msgs['err'] . "<br>";
    echo "wrn = " . $msgs['wrn'] . "<br>";
    echo "inf = " . $msgs['inf'] . "<br>";
}

in the end what happens is that the converter seems to run, spawns the pdf reader, then gives the error msg File does not begin with '%PDF-'. ultimately, there's no file. there is no error echo and there is no entry to the logfile. when i remove the header, the error echo is "Boo." (as above) with empty data.

I've also tried convert_string_to_passthru and convert_string_to_file with variations on the above setup. for string to passthru i using an example from here http://www.princexml.com/bb/viewtopic.php?t=1651&highlight=php . . . everything has performed the same as above.

at this point i'm just looking for suggestions. thanks in advance.

[edit] i understand the controls on the site to prevent spam, but man... annoying... especially since it was saying i had a url in the text that i couldn't find.
mikeday
Firstly is Prince really installed and accessible at "/usr/local/bin/prince" and are you able to run it successfully from the command-line?
monsto
that's where it installed. following the install directions, everything went as the README said. . . ran the script then the couple of command lines. even ran the example making the magic.pdf, which came out as expected.
mikeday
Is the specified log file being created by Prince at all, and left empty, or is not even being created?
monsto
i had to create it and gave it permission 666.

and the dir is 777
mikeday
So Prince didn't create it, or write anything to it? That would seem to indicate that Prince is not being run at all. I'm not sure what's the best way to debug that, perhaps making a temporary modification to the shell script at /usr/local/bin/prince to echo something to the log, to verify that at least the script is being executed?
monsto
been a busy week . . . but i'm back with a vengeance!! Or maybe with some pocket change. . .

the script is being executed because it successfully created the sample that comes with the install.

i'm going to try it on a different server . . . there may be some kind of config issue with this one.
skeud
Hi monsto.

I'm coming on your post because I have exactly the same problem when I try to use PrinceXML with PHP. (in my case I'm sure that Prince is running correctly cause I get perfect PDF with commandline).

Did you find a solution to your problem finally?

Cheers
mikeday
Do you see Prince writing to the log file? Another thing you can do is modify the /usr/bin/prince shell script to verify that it is actually being called, by adding a line like this:
echo called >> /tmp/prince.log