-
Notifications
You must be signed in to change notification settings - Fork 297
PDF Renderer Converter
flexmark-java Docx-Renderer extension
The flexmark-pdf-converter module renders HTML to PDF using
Open HTML To PDF so the full conversion requires
rendering Markdown to HTML then passing it to the PDF converter extension.
Sample application is provided PdfConverter.java.
Bundled fonts in the OpenHtmlToPDF library support only basic latin unicode characters. To render other character sets additional fonts must be included in the HTML being converted.
A solution to the font problem is to define an embedded TrueType font in the style or stylesheet
and set the body tag to use this font. OpenHtmlToPDF will use the characters from the font
which has them defined.
For example including Noto Serif/Sans/Mono fonts and adding
noto-serif, noto-sans and noto-mono families to CSS to allow PDF to use these for
rendering text.
However, the PDF converter requires TrueType fonts and Noto CJK fonts are OpenFonts which
cannot be used. The solution is to download a TrueType Unicode font that supports CJK character
set and add it to the custom rendering profile to be used for PDF.
For my test I used arialuni.ttf from https://www.wfonts.com/font/arial-unicode-ms
If the installation directory for the fonts is /usr/local/fonts/ then the following in the
stylesheet or the page <head> <style>...</style> </head> should be added:
ℹ️ Don't forget to change the path to your OS and installation directory. On
windows the path should start with file:/X:/... where X:/... is the drive letter followed by
the full installation path.
@font-face {
font-family: 'noto-cjk';
src: url('file:///usr/local/fonts/arialuni.ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'noto-serif';
src: url('file:///usr/local/fonts/NotoSerif-Regular.ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'noto-serif';
src: url('file:///usr/local/fonts/NotoSerif-Bold.ttf');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'noto-serif';
src: url('file:///usr/local/fonts/NotoSerif-BoldItalic.ttf');
font-weight: bold;
font-style: italic;
}
@font-face {
font-family: 'noto-serif';
src: url('file:///usr/local/fonts/NotoSerif-Italic.ttf');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'noto-sans';
src: url('file:///usr/local/fonts/NotoSans-Regular.ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'noto-sans';
src: url('file:///usr/local/fonts/NotoSans-Bold.ttf');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'noto-sans';
src: url('file:///usr/local/fonts/NotoSans-BoldItalic.ttf');
font-weight: bold;
font-style: italic;
}
@font-face {
font-family: 'noto-sans';
src: url('file:///usr/local/fonts/NotoSans-Italic.ttf');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'noto-mono';
src: url('file:///usr/local/fonts/NotoMono-Regular.ttf');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'noto-sans', 'noto-cjk', sans-serif;
overflow: hidden;
word-wrap: break-word;
font-size: 14px;
}
var,
code,
kbd,
pre {
font: 0.9em 'noto-mono', Consolas, "Liberation Mono", Menlo, Courier, monospace;
}