When working with PrinceXML for PDF generation, you'll frequently encounter the need for Microsoft Core Fonts (msttcorefonts). This package includes essential TrueType fonts like Arial, Times New Roman, and Courier New that many PDF generation workflows require for proper document rendering.
The error message you're seeing occurs because Ubuntu no longer includes these fonts in its main repositories due to licensing considerations. The package exists but requires enabling the non-free repository:
$ sudo apt-get install msttcorefonts
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package msttcorefonts is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package msttcorefonts has no installation candidate
Here's how to properly install the fonts on modern Ubuntu systems:
# First, enable the universe repository and update
sudo add-apt-repository universe
sudo apt update
# Install the font installer package
sudo apt install ttf-mscorefonts-installer
# Accept the EULA when prompted
After installation, verify the fonts are available to PrinceXML:
# Check if fonts are installed
fc-list | grep -i "Arial"
# Expected output should show:
# /usr/share/fonts/truetype/msttcorefonts/Arial.ttf: Arial, Arial MT:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normalny,Обычный,Normálne,Navadno,Arrunta
In your PrinceXML configuration or CSS, you can now reference these fonts:
@font-face {
font-family: "Arial";
src: url("/usr/share/fonts/truetype/msttcorefonts/Arial.ttf");
font-weight: normal;
font-style: normal;
}
body {
font-family: Arial, sans-serif;
}
If PrinceXML still can't find the fonts, try these steps:
# Refresh the font cache
sudo fc-cache -f -v
# Check the font path in PrinceXML
prince --input=example.html --verbose | grep -i "font"
For cases where you can't install system-wide fonts:
- Package fonts directly with your project
- Use font substitutions in PrinceXML configuration
- Consider open-source font alternatives like Liberation fonts
When generating PDFs with PrinceXML, you might encounter font rendering issues if the required Microsoft Core Fonts (msttcorefonts) aren't installed. The standard installation approach fails because the package is no longer directly available in Ubuntu's main repositories.
The error message Package msttcorefonts has no installation candidate
appears because Ubuntu moved these fonts to the ubuntu-restricted-extras
meta-package. Here's what's happening behind the scenes:
sudo apt-cache show msttcorefonts
Package: msttcorefonts
State: not a real package (virtual)
The current recommended way to install these fonts is:
sudo apt update
sudo apt install ttf-mscorefonts-installer
During installation, you'll need to accept Microsoft's EULA. For automated installations, you can preseed the agreement:
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | sudo debconf-set-selections
After installation, check if the fonts are properly registered in fontconfig:
fc-list | grep -i "Arial"
Sample output should show something like:
/usr/share/fonts/truetype/msttcorefonts/Arial.ttf: Arial:style=Regular,Normal,obyčejné,Standard,Κανονικά
For Docker containers or automated build systems, you might need this approach:
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
add-apt-repository multiverse && \
apt-get update && \
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
apt-get install -y ttf-mscorefonts-installer
If fonts still don't appear correctly in your PDF output, try explicitly declaring them in your CSS:
@font-face {
font-family: "Arial";
src: local("Arial"), local("Arial MT");
}
body {
font-family: Arial, sans-serif;
}