Forum How do I...?

Create PDF from PHP

Flip
I installed Prince on our CentOS 5.5 Linux machine and I tried the following script to test :
<?php

  require_once 'prince.php';

  $prince = new Prince('/usr/bin/prince');

  header('Content-Type: application/pdf');
  header('Content-Disposition: inline; filename="foo.pdf"');
  
  $htmlString = '<h1 style="color:red">Test</h1>';
  
  $prince->convert_string_to_passthru($htmlString);
  
?>


But all I get is a grey screen.

The path in the example supplied by Prince is /usr/local/bin/prince but on my machine that path is not present, so I used /usr/bin/prince
mikeday
First, check if Prince works properly from the command-line. Do you have fonts installed on the machine, such as the Microsoft Core Fonts or DejaVu fonts?
Flip
mikeday wrote:
First, check if Prince works properly from the command-line. Do you have fonts installed on the machine, such as the Microsoft Core Fonts or DejaVu fonts?


Good tip.

When I try that I get the following messages :

prince: warning: no glyphs for character U+0054, fallback to '?'
prince: internal error: no fallback glyph for character U+0054

We have no extra fonts installed on that machine as far as I know.
mikeday
I would suggest installing the Microsoft Core Fonts (msttcorefonts package?) or the DejaVu fonts.
Flip
mikeday wrote:
I would suggest installing the Microsoft Core Fonts (msttcorefonts package?) or the DejaVu fonts.


OK, I was trying that already, but I am stuck with installing the MS Core Fonts on CentOS.

Or DejaVu fonts easier to install ?

Which fonts are better for PrinceXML ?
Flip
I tried to install the Dejavu fonts which give a conflict with fonctconfig 2.3.0

Installed dejavu-lgc-fonts.noarch, but trying Prince from the command line still gives me the same errors messages.

So basicly I am stuck here ...
Flip
Finally succeeded in getting it to work.

Downloaded msttcore-fonts-2.0-3.noarch.rpm from a site.

Executed the following command :

rpm -ivh msttcore-fonts-2.0-3.noarch.rpm

And now PrinceXML seems to working from the command line and with my PHP script !

Thanks for the hint and tip Mike !