Forum How do I...?

Cannot load default config file

zebedee
Hi,
I managed to get prince working on my windows machine, but I now wanted to get it up and running on linux. So I installed prince-5.0-beta4-linux.tar.gz and got the "Installation complete"... message and no errors.

Now when I try to run prince on the examples/magic.xml file, I get the following errors:

Fontconfig error: Cannot load default config file
prince: warning: no glyphs for character U+0054
prince: internal error: no fallback glyph for character U+0054

Does anyone know what I'm doing wrong? What's this about a config file?

Prince is installed in my home directory:
/home/username/princexml

I've copied the examples directory to:
/home/username/princexml/examples

I run prince with the following:
/home/username/princexml/bin/prince examples/magic.xml

Any help much appreciated :)

Thanks
mikeday
Prince uses the Fontconfig library on Linux to find fonts that are installed on the system. Fontconfig is a standard component these days in most desktop Linux distributions such as Ubuntu and Red Hat / Fedora.

The error message from Fontconfig may indicate a configuration problem with the Fontconfig config files (usually located in /etc/fonts). Alternatively, it could be a library versioning problem with Prince.

May I ask which Linux distribution you are using? Is Fontconfig installed on your system? (Try checking /etc/fonts, or check the installed package list using 'dpkg --list' on Debian or 'rpm -qa' on Red Hat / Fedora).
zebedee
I'm not too knowledgeable on how things are set up in linux, but here's the info...

Heres the version and distro:

Linux version 2.4.23 (gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-118.7.2))

rpm -qa | grep font gives me:

ghostscript-fonts-5.50-3
ttfonts-ja-1.0-8
kon2-fonts-0.3.9b-14.as21.1
chkfontpath-1.9.5-2
urw-fonts-2.0-12
ttfonts-1.0-4
tetex-fonts-1.0.7-38.4

If something needs to get installed, I can ask our sys admin...
Thanks for the quick reply
mikeday
Ah, Red Hat 7.2 does not use Fontconfig; that explains why the Fontconfig library is complaining about not being able to find its config files on your system.

There are two possible solutions to this issue. The first possibility is to install Fontconfig, however that might not be enjoyable if it requires building the library from source and messing around with config files by hand.

The second is to just tell Prince where to find the fonts you want to use, which is probably a better solution as it is easier and does not involve changing your system or installing new software. Here is how to do it:

* Find fonts.css in the Prince installation (in your case this should be in /home/username/princexml/lib/prince/style/fonts.css)

* You will see that fonts.css contains three @font-face rules defining the default "serif", "sans-serif" and "monospace" font families; these fonts are mapped to "Times New Roman", "Arial" and "Courier New", respectively. (Without Fontconfig Prince cannot find these fonts on the system).

* The solution is to specify an absolute path to the TrueType font files so that Prince can just load them by itself:

@font-face {
    font-family: serif;
    font-style: normal;
    font-weight: normal;
    src: url("/usr/share/fonts/truetype/msttcorefonts/times.ttf")
}

@font-face {
    font-family: serif;
    font-style: normal;
    font-weight: bold;
    src: url("/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf")
}

@font-face {
    font-family: serif;
    font-style: italic;
    font-weight: normal;
    src: url("/usr/share/fonts/truetype/msttcorefonts/timesi.ttf")
}

@font-face {
    font-family: serif;
    font-style: italic;
    font-weight: bold;
    src: url("/usr/share/fonts/truetype/msttcorefonts/timesbi.ttf")
}

(Unfortunately this requires four rules rather than one, to explicitly specify the normal, bold, italic, and bold-italic variations. You can just use one rule if you like, but then bold and italic will have no effect).

The above code assumes that you have the msttcorefonts (Microsoft Core Fonts, available for free download even for Linux) installed under /usr/share/fonts/truetype/msttcorefonts; please adjust the paths appropriately if they are located somewhere else on your system.

If you would rather use different fonts just substitute your preferred set of TrueType font files.

If you get any error messages about "no fallback glyphs" that means that Prince hasn't been able to load any fonts and thus cannot continue. (If you run Prince with the --verbose argument it will print a message for each font that it loads).

I hope that helps! Unfortunately with the wide range of Linux distributions out there it is difficult for Prince to locate the right fonts on every system automatically; hopefully when all the distributions come with Fontconfig pre-installed the situation will become more manageable :)
Anonymous
Thanks for the detailed info.
I had the sys admin install Fontconfig for me, and it all works now!

I'm just using it for myself right now, and am looking at buying the single user licence to start. But if I then decide to roll this out for multiple users, can I just pay the difference from the single to a server licence? Rather than having to buy the full server licence on top of the single user licence.

On a completely different note, I took your PHP 5 Prince class and made it compatible with PHP 4.0, and added phpDoc compatible comments. (I'm testing with a piece of legacy software that's not going to be upgraded). If anyone wants it, send me a PM.
mikeday
I had the sys admin install Fontconfig for me, and it all works now!

Great, that's good to hear :)

I'm just using it for myself right now, and am looking at buying the single user licence to start. But if I then decide to roll this out for multiple users, can I just pay the difference from the single to a server licence?

Sure, just contact us when you wish to upgrade to a server license.

On a completely different note, I took your PHP 5 Prince class and made it compatible with PHP 4.0, and added phpDoc compatible comments.

If this would be useful for other PHP 4.0 users out there then perhaps it would be good to merge your changes with our PHP class; what do you think?