Forum How do I...?

convert3 not working, but convert2 does

mathieu
I built a test for PrinceXML originally on a Windows server, and got it working quite well.

Now I'm trying to get this same test to work on my hosting provider servers, which run on Unix.

I managed to get convert2 to work (converting an HTML file to a PDF file), but convert3 refuses to work (converting an HTML file to PDF and dumping to screen).

The call to convert3 always returns false (displaying "Failure") and no data is ever dumped to the screen.

HomeDVD.ca
PlanetBachelorette.com

Edited by mathieu

mathieu
Here is the HTML file (test.html):

<html>

<style>
	body,
	h1,
	p {
		font-family: Unispace;
	}
</style>

<body>

<h1>Test Header</h1>

<p>Testing some content in here!</p>

</body>

</html>


Here is the PHP code:

error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);

require_once("prince.php");

$oPrince = new Prince("/magma/users/test/prince/bin/prince");

$oPrince->setBaseURL("http://www.planetbachelorette.com");
$oPrince->setHTML(true);
$oPrince->setLog("/magma/users/test/prince.log");

$iType = 0;

if($iType == 0)
{
	//header("Content-Type: application/pdf");
	//header("Content-Disposition: attachment; filename=test.pdf");

	chdir("/magma/users/test/prince/bin/");

	$bSuccess = $oPrince->convert3("/magma/users/test/test.html");

	echo ($bSuccess ? "Success<br>\n" : "Failure<br>\n");
}
else
{
	$bSuccess = $oPrince->convert2("/magma/users/test/test.html", "/magma/users/test/test.pdf", $aMessages);

	echo ($bSuccess ? "Success<br>\n" : "Failure<br>\n");

	echo "<pre>";
	var_dump($aMessages);
	echo "</pre>";
}


This is what prince.log contains after running convert3:

Tue Sep 18 11:45:39 2007: ---- begin
Tue Sep 18 11:45:39 2007: internal error: no available fonts
Tue Sep 18 11:45:39 2007: ---- end


As you can see, I even tried a chdir to the prince folder but it still can't find any available fonts. I had the same missing font situation with convert2 but fixed it by making the default font Unispace. That doesn't seem to satisfy convert3.

Any ideas?

HomeDVD.ca
PlanetBachelorette.com

mikeday
Strange; there should not be any difference between convert2 and convert3 when it comes to loading fonts.

When you run Prince from the command-line does it work? What if you try it like this, taking the input from stdin:

$ /path/to/prince - <input> out.pdf

Do you have any TrueType fonts installed on this machine besides the fonts that come with Prince? In particular, can you install the Microsoft Core Fonts, available in the msttcorefonts package for Linux? Also, do you have fontconfig installed?
mathieu
I figured it out... stupidest thing =) convert3 takes a string containing the markup, not a filename! I had a slightly different version for testing on the Windows environment. Goes to show how important it is to compare apples with apples

The convert3 line should instead read as:

$bSuccess = $oPrince->convert3(file_get_contents("/magma/users/test/test.html")); 


Hopefully someone else will encounter this same problem and find their solution here, otherwise this has been a big waste of debugging time! ;-)

Cheers

HomeDVD.ca
PlanetBachelorette.com