Why does the report come out misaligned when a Linux server generates it?
· Toni Martir, arquitecto de software
Every night a server turns the month's invoice listing into a PDF and emails it to each sales rep. On the Windows PC where it was designed, the report is perfect: one customer per line, the amounts lined up. From a Linux server it arrives with names cut off, amounts split over two lines and an extra page. Nobody has touched the report or the database.
What has changed is the font: the report asks for Arial or Calibri, the server lacks it and writes with a wider one. It can be fixed without redesigning anything, though the obvious fix, copying the Windows font onto the server, is forbidden.
The server swaps the font without telling you
Arial, Calibri and Times New Roman are Microsoft fonts. Arial's page says it is «exclusively included» with Microsoft products and services. A Linux server does not come with it.
When a Linux program asks for a missing font, fontconfig, the part of Linux that chooses fonts, picks a replacement. Its documentation says it takes the closest match among those installed: «a font will always be returned», with no guarantee that «it is anything like» the one requested. The PDF still comes out, with no error and no warning.
I tried it with only the DejaVu family installed, the first that Debian's fontconfig package asks for: Arial and Calibri turn into DejaVu Sans, and Times New Roman into DejaVu Serif.
A few millimetres per line
A report puts each item in a box of fixed size, measured for its font. At 9 points, «Thames Valley Office Supplies Limited» takes up 54 millimetres in Arial and 61 in DejaVu Sans: in a 55-millimetre column it no longer fits. Depending on the box, the text is cut off, runs into the next column, or wraps onto a second line and pushes everything below it down, until the listing needs another page.
The font the report asks for, and the one the server uses
Measured on Ubuntu 26.04 with five pieces of invoice text: two customer names, an amount, a delivery note number and a label. The Microsoft fonts were measured through their replacements, which take up the same space. Courier New barely changes because in both fonts every letter has the same width.
Copying the Windows font is not allowed
Microsoft's font redistribution FAQ is clear: apart from embedding them in a document, you may not copy the Windows fonts «to other computers or servers». The right to install the original on a server is sold separately; for many of them, Microsoft points to Monotype.
The practical route is a replacement with the same widths, letter by letter. The Liberation fonts are made to measure the same as Arial, Times New Roman and Courier New, and Carlito the same as Calibri. The letters look slightly different; their widths stay the same. Both families come under the SIL Open Font License, which lets you use them, embed them in a PDF and redistribute them without paying, with conditions such as not selling them on their own.
The report stays as it is: fontconfig already lists those pairs in its
table of equivalent families
and picks the replacement by itself once it is installed. If the program
generating the PDFs relies on fontconfig, fc-match Arial
tells you
which font the server will use. If it answers DejaVu Sans, expect a misaligned
report.
So why does it come out misaligned?
Because the server lacks the font the report was designed with, and quietly writes with another that does not measure the same. The fix is to give the server a font with the same widths: the original, by buying the right to install it on a server, or an openly licensed replacement such as Liberation or Carlito.
Reportman Server,
Report Manager's server in Docker, already
carries replacements with the same widths as Arial, Times New Roman, Courier
New, Arial Narrow, Calibri and Cambria, takes your own fonts in its fuentes/ folder and
shows which fonts the engine sees under Server → Diagnostics → Fonts. With
printreptopdf, the
web report server or your own
application built on the engine, you install the replacements on the server and the
engine picks them through fontconfig.
Sources
- Microsoft, Arial font family, «Download» row: «N/A – Exclusively included with Microsoft products and services where applicable.»
- fontconfig, Fontconfig user documentation, «Font Matching» section: «Fontconfig performs matching by measuring the distance from a provided pattern to all of the available fonts in the system. The closest matching font is selected. This ensures that a font will always be returned, but doesn't ensure that it is anything like the requested pattern.»
- Debian, fontconfig-config package: its font dependency is «fonts-dejavu-core» or, instead, one of a list of alternatives.
- Microsoft, Font redistribution FAQ, «Redistribution and extended rights» section: «Apart from the document embedding rights described previously, you may not redistribute the Windows fonts. You may not copy them to other computers or servers, and you may not convert them to other formats, including bitmap formats, or modify them.» and «Many of the fonts owned by Microsoft can be licensed with extended rights from Monotype.»
- Liberation Fonts, official repository: «The Liberation Fonts is font collection which aims to provide document layout compatibility as usage of Times New Roman, Arial, Courier New.»
- Carlito, official repository: «Carlito is a font designed by Łukasz Dziedzic (@typoland) derived from Lato (also designed by Łukasz Dziedzic) that is metric-compatible with Calibri.»; and its licence: «This Font Software is licensed under the SIL Open Font License, Version 1.1.»
- SIL, Open Font License 1.1: «Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software»; and condition 1: «Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.»
- fontconfig, the conf.d/30-metric-aliases.conf file (fontconfig 2.15.0 source code, in Debian's copy): «Set substitutions for similar/metric-compatible families»; its table pairs Arial with Liberation Sans, Times New Roman with Liberation Serif, Courier New with Liberation Mono and Calibri with Carlito.
- fontconfig, fc-match manual page: «fc-match matches pattern (empty pattern by default) using the normal fontconfig matching rules to find the best font available.»
- Report Manager: Reportman Server («Fonts» section), printreptopdf on Linux, the web report server and PDF output and font selection on Linux.
Toni Martir, arquitecto de software · · sources checked on