Forum How do I...?

Running from server

iancevans
I have been using Prince for about 6 months for generating PDFs of my academic papers. I have it installed on my hard drive, but keep the XHTML versions of my papers on my website for viewing. I manually generate the PDFs and then upload them to my server with a link should anyone viewing my papers want to print them.

It occurred to me that it would be much more convenient if I could just install Prince on my server and dynamically generate a PDF whenever someone wanted to print.

So I installed the latest version of Prince on my server. When I attempt to call it from the command line on a document, I get the following errors:

prince: InfiniteProgress2.html:257: error: htmlParseEntityRef: no name prince: InfiniteProgress2.html:258: error: htmlParseEntityRef: no name prince: internal error: no available fonts

I know this isn't enough information for troubleshooting, but I'm not sure what you need to know, so just ask and I'll provide!

Thanks for any help you can offer!

ian
mikeday
This is almost certainly caused by an unescaped ampersand (&) in an attribute value, which needs to be escaped as &
iancevans
Thanks for the quick response. I fixed the unescaped ampersands, but I'm still getting the following error:

prince: internal error: no available fonts

I've gotten this error on the Prince test documents as well. Any thoughts?

ian
mikeday
It means there are no available fonts. :)

You can install the msttcorefonts, or use other fonts, as described here.
iancevans
javascript:emoticon(':oops:')

I dropped a copy of Georgia on the server and added the following to the fonts.css file in the prince directory:

/*Georgia */

@font-face {
    font-family: Georgia;
    font-weight: normal;
    font-style: normal;
    src: url("/home/iancevans/iancevans.com/fonts/Georgia.ttf");
}

@font-face {
    font-family: Georgia;
    font-weight: normal;
    font-style: italic;
    src: url("/home/iancevans/iancevans.com/fonts/GeorgiaItalic.ttf");
}

@font-face {
    font-family: Georgia;
    font-weight: bold;
    font-style: normal;
    src: url("/home/iancevans/iancevans.com/fonts/GeorgiaBold.ttf");
}

@font-face {
    font-family: Georgia;
    font-weight: bold;
    font-style: italic;
    src: url("/home/iancevans/iancevans.com/fonts/GeorgiaBoldItalic.ttf");
}


I then made a little test XHTML file that calls a stylesheet that sets the font to Georgia. I still get the same error. Am I making a dumb mistake again?
mikeday
Perhaps bind the default serif font family to Georgia as well:
@font-face {
    font-family: serif;
    src: local("Georgia")
}
iancevans
Thanks for the replies, and sorry to keep bugging you, but I really want to get this working.

I moved the Georgia truetype files to Prince's font folder. Tried adding the following:


/*Serif*/

@font-face {
    font-family: serif;
    font-weight: normal;
    font-style: normal;
    src: url("../fonts/Georgia.ttf");
}

@font-face {
    font-family: serif;
    font-weight: normal;
    font-style: italic;
    src: url("../fonts/GeorgiaItalic.ttf");
}

@font-face {
    font-family: serif;
    font-weight: bold;
    font-style: normal;
    src: url("../fonts/GeorgiaBold.ttf");
}

@font-face {
    font-family: serif;
    font-weight: bold;
    font-style: italic;
    src: url("../fonts/GeorgiaBoldItalic.ttf");
}


No help. Then I downloaded a copy of Lido STF, dropped it in the same folder, tried the same thing, again no luck.

So I add fonts to the directory, bind them with fonts.css, but then when I call them in a stylesheet for my test document, I get the "no available fonts" error.

BUT if I call the fonts that come with Prince (the ones from Ray Larabie), everything works just fine. Is dragging a TrueType font file into the directory and adding CSS not sufficient to "install" the font?
mikeday
That's puzzling. What if you try a very simple document with no fonts specified at all, like this:
<html>
<body>
<p>Hello, world!</p>
</body>
</html>

Is this formatted successfully?
iancevans
Puzzling indeed.

The simple document you suggest generates the "no available fonts" error with the default fonts.css file, as I do not have the microsoft core fonts installed.

So I altered fonts.css so that serif, sans-serif, cursive, monospace, and fantasy all use "Minya Nouvelle," setting specific rules for normal, italic, bold, and bold italic. I know that documents which are explicitly told to use Minya Nouvelle by a stylesheet work. The test document in question, though, again generated "no available fonts."

Just for completeness' sake, I told the document to use "test.css" which just says:

body { font-family: serif; }


Again, "no available fonts". And to make sure the situation is as I thought, when I change "test.css" to read:

body { font-family: Minya Nouvelle; }


Prince worked just fine.

So I take it that the lesson is that there are two problems:

(1) I can't bind anything to "serif."
(2) The only fonts that work when explicitly set are those that come with the Prince distribution.

I'm at a loss. Oh well, it's not that much of a chore running Prince from my local machine, and that still works like a charm.[/list]
mikeday
Hmm, do you have a font called "Serif" installed on that machine? I think there could be a potential problem if there is a system font called serif that is not in TrueType format, we'll need to investigate that.

For that matter, does the system have any fonts installed at all? (Try running Prince with the --debug command-line argument and see if it lists any font families).
iancevans
I don't know how to test whether a font called "Serif" is installed; but I certainly didn't install it. This is all just taking place on the server space I pay for through DreamHost. I don't have root access or anything like that.

Based on the results of "--debug", it appears that there are some fonts installed, but that there isn't one called "Serif." Here's what I get:

prince: debug: loading license: /home/iancevans/lib/prince/license/license.dat
prince: debug: font-family: Bitstream Vera Sans
prince: debug: font-family: Bitstream Vera Sans Mono
prince: debug: font-family: Bitstream Vera Serif
prince: debug: font-family: Century Schoolbook L
prince: debug: font-family: Dingbats
prince: debug: font-family: Nimbus Mono L
prince: debug: font-family: Nimbus Roman No9 L
prince: debug: font-family: Nimbus Sans L
prince: debug: font-family: Standard Symbols L
prince: debug: font-family: URW Bookman L
prince: debug: font-family: URW Chancery L
prince: debug: font-family: URW Gothic L
prince: debug: font-family: URW Palladio L
prince: loading style sheet: /home/iancevans/lib/prince/style/fonts.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/fonts.css
prince: debug: loaded resource: type: no
prince: loading HTML input: test.html
prince: debug: loaded document: test.html
prince: debug: sniffed doctype: XHTML (no namespace)
prince: loading style sheet: /home/iancevans/lib/prince/style/xhtml.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/xhtml.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /home/iancevans/lib/prince/style/common.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/common.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /home/iancevans/lib/prince/style/hyph.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/hyph.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /home/iancevans/lib/prince/style/xlink.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/xlink.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /home/iancevans/lib/prince/style/mathml.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/mathml.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /home/iancevans/lib/prince/style/svg.css
prince: debug: loaded resource: /home/iancevans/lib/prince/style/svg.css
prince: debug: loaded resource: type: no
prince: loading style sheet: test.css
prince: debug: loaded resource: test.css
prince: debug: loaded resource: type: no
prince: debug: prepack
prince: used font: Minya Nouvelle, Regular
prince: debug: writing output: test.pdf


Maybe Bitstream Vera Serif is causing problems? Well, I just tried using it (by adjusting test.css) and it worked fine. Apparently it is a TrueType font. Still doesn't work if I try to bind it to serif, it seems. Some of those fonts aren't TrueType, though--URW Palladio L, for instance, isn't.

Thanks for your persistence!
mikeday
Oh, I have an idea: is the original @font-face rule in fonts.css still there? The rule that maps "serif" to "Times New Roman", "Times", etc.? If so, it may be shadowing any other rules that you've added, and since there is no Times New Roman font installed, could be causing problems.
iancevans
I wish that were the problem, but I commented those old rules out. I deleted them just now to be sure, same problem. Just got rid of all the cruft from testing, too, now fonts.css just contains:


@font-face {
    font-family: serif;
    src: local("Bitstream Vera Serif");
}

@font-face {
    font-family: sans-serif;
    src: local("Bitstream Vera Sans");
}

@font-face {
    font-family: monospace;
    src: local("Bitstream Vera Sans Mono");
}

@font-face {
    font-family: cursive;
    src: local("Bitstream Vera Sans");
}


Same situation: if I have test.css set the font to serif (or sans-serif, or mono, or whatever) it doesn't work, but if I set it to "Bitstream Vera Serif" (or the others) it works. Aargh!

Well, at least I know I'm not violating any font copyright laws so long as I can't get this working. :)
iancevans
Forgot to mention: the original fonts.css (from the Linux distribution) has a large number of lines that aren't closed with a semi-colon (just downloaded a fresh copy to make sure this was the case). Doesn't seem to be what was causing my problems, but might cause others.
mikeday
The semicolons shouldn't be an issue, they aren't required on the last declaration in a block as technically they are declaration separators rather than declaration terminators.

So, the current situation is:

- You can use fonts like Bitstream Vera Sans that are installed on the system by specifying the name using font-family, and Prince picks them up automatically using fontconfig.

- You can use the Larabie fonts that come with Prince by specifying the name using font-family, and Prince picks them up from the @font-face rules defined in the fonts.css file.

- You can't use any other fonts that you've referenced using @font-face rules? For example, if you take the rules in fonts.css and change them to point to your own Georgia.ttf, it doesn't work any more?

- You can't bind any fonts to "serif", either system fonts using local() or font files using url().

- You don't get any warnings about font file formats or inability to access or load font files, just the "no available fonts" message?

I have to say this is pretty strange, but I think with persistence we might be able to work it out. :)
iancevans
I think you've summed up the situation accurately; tell me what to do, doc.
mikeday
I think the only way forwards is for us to make a quick debug build of Prince that you can run to track down exactly why it's not finding the specified fonts. We'll try and have it ready in a day or so.
iancevans
great!
mikeday
Today we have released Prince 6.0 rev 5, which includes some extra debugging output when running with the --debug command-line option. Could you try running with this and post the debug output that gets produced when it can't find the fonts?
tvongaza
I'm running into the same problem, I haven't touched anything with the fonts, using a default config. I have two spots in my style sheet which set the font-family.

body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
}
a {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #36648b;
}

I get the following debug output:

Tue Jan 29 19:16:48 2008: ---- begin
Tue Jan 29 19:16:48 2008: debug: loading license: /home/behvca/apps/prince/lib/prince/license/license.dat
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/fonts.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/fonts.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading HTML input: -
Tue Jan 29 19:16:48 2008: debug: loaded document: -
Tue Jan 29 19:16:48 2008: debug: sniffed doctype: XHTML (no namespace)
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/xhtml.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/xhtml.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/common.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/common.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/hyph.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/hyph.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/xlink.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/xlink.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/mathml.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/mathml.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /home/behvca/apps/prince/lib/prince/style/svg.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /home/behvca/apps/prince/lib/prince/style/svg.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: loading style sheet: /chroot/home/behvca/behv.ca/rtab_rails/public/stylesheets/application.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: /chroot/home/behvca/behv.ca/rtab_rails/public/stylesheets/application.css
Tue Jan 29 19:16:48 2008: debug: loaded resource: type: no
Tue Jan 29 19:16:48 2008: debug: prepack
Tue Jan 29 19:16:48 2008: debug: ["Arial", "Helvetica", "sans-serif"] -> [font_record(font_desc("sans-serif", [], normal, [], []), [redirect("Arial"), redirect("Helvetica"), redirect("OpenSymbol"), redirect("DejaVu Sans")])]
Tue Jan 29 19:16:48 2008: debug: ["Arial"] -> []
Tue Jan 29 19:16:48 2008: debug: ["Helvetica"] -> []
Tue Jan 29 19:16:48 2008: debug: ["OpenSymbol"] -> []
Tue Jan 29 19:16:48 2008: debug: ["DejaVu Sans"] -> []
Tue Jan 29 19:16:48 2008: internal error: no available fonts
Tue Jan 29 19:16:48 2008: ---- end

How can I get this working? Prince should really gracefully degrade if the font isn't available instead of crashing.

Tys
mikeday
If there are no fonts installed on the server, then Prince can't generate PDF files. Do you have any fonts installed? Is the fontconfig library available?
tvongaza
It is a shared host... I've got them to install the microsoft default fonts and it seems to be generating pdf's now.... however the PDF's aren't recognized by Apple's preview. Here is the error I get:

"Couldn't open the file. It may be corrupt or a file format that Preview doesn't recognize."

Tys
mikeday
Please put a PDF file online or email one to me, and I'll check it out.