Forum How do I...?

Converting html string to PDF, php

yagel
Hi everyone, I'm tring to convert html string into pdf in php using the convert_string_to_file method but I can't make it, I always get an error. My code is:

<?php

require "prince.php";

$exepath = "C:/Program Files (x86)/Prince/Engine/bin/prince";
$prince = new Prince($exepath);

if($prince) {
echo "Prince successfuly installed";
}


$prince->setHTML(1);

$htmlString = "<h1>Hellow World</h1>";

$convert = $prince->convert_string_to_file($htmlString, "test.pdf");

if($convert) {
echo "File successfuly generated";
}

?>


the error that I get when I run the file from localhost/xampp is:

"
Warning: proc_open(): CreateProcess failed, error code - 2 in C:\xampp\htdocs\infibond\prince.php on line 609

Fatal error: Uncaught exception 'Exception' with message 'Failed to execute C:/Program" "Files" ("x86")"/Prince/Engine/bin/prince --server -i "html" - -o "test.pdf"' in C:\xampp\htdocs\infibond\prince.php:627 Stack trace: #0 C:\xampp\htdocs\infibond\prince.php(432): Prince->convert_internal_string_to_file('C:/Program" "Fi...', '<h1>Hellow Worl...', Array) #1 C:\xampp\htdocs\infibond\phpinfo.php(22): Prince->convert_string_to_file('<h1>Hellow Worl...', 'test.pdf') #2 {main} thrown in C:\xampp\htdocs\infibond\prince.php on line 627
"

Please help me solve the problem because I have no idea how to solve it.
Thanks
mikeday
It looks like the filename quoting problem that we thought was fixed. Could you try editing prince.php, finding the __construct() method, and replacing this line:
$this->exePath = $this->addDoubleQuotes(ltrim($exePath));

with this instead:
$this->exePath = '"' . $exePath . '"';

Sorry for the inconvenience!