~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(pdf): render emojis in exported PDFs via Noto Color Emoji fallback (#4730)
LearningCircuit3437fb5d3643
diff --git a/Dockerfile b/Dockerfileindex 91d1dc9d22..2bde00f32d 100644--- a/Dockerfile+++ b/Dockerfile@@ -280,6 +280,10 @@ RUN apt-get update && apt-get upgrade -y \# in exported PDFs — without these the slim base image has no CJK# coverage and CJK text vanishes from the output (issue #4055).fonts-noto-cjk \+ # Emoji font so emojis in the markdown don't render as "tofu" boxes+ # in the PDF. The base image has no emoji coverage; WeasyPrint picks+ # "Noto Color Emoji" up via the font-family stack in pdf_service.py.+ fonts-noto-color-emoji \&& rm -rf /var/lib/apt/lists/*# Create non-root user for running service (security best practice)diff --git a/changelog.d/+pdf-emoji-font-stack.bugfix.md b/changelog.d/+pdf-emoji-font-stack.bugfix.mdnew file mode 100644index 0000000000..7183516e3f--- /dev/null+++ b/changelog.d/+pdf-emoji-font-stack.bugfix.md@@ -0,0 +1 @@+Emojis in exported PDFs no longer render as empty "tofu" boxes. The default WeasyPrint stylesheet now lists ``"Noto Color Emoji"`` (with ``"Noto Emoji"`` as a monochrome fallback and ``"Segoe UI Emoji"`` / ``"Apple Color Emoji"`` for native installs) at the tail of both the body and ``code``/``pre`` font-family stacks, and the official Docker image now bundles ``fonts-noto-color-emoji`` alongside ``fonts-noto-cjk``. Non-Docker users on Linux without an emoji font installed still need to install one (e.g. ``apt install fonts-noto-color-emoji``) — see ``docs/faq.md``. This change also fixes a pre-existing flaw in the ``custom_css`` path: ``markdown_to_pdf(custom_css=...)`` previously *replaced* the default stylesheet entirely, silently dropping the CJK fallback from #4055; it now layers custom CSS on top of the default so the font fallbacks survive.diff --git a/docs/faq.md b/docs/faq.mdindex 85ab56e3e6..1c2dd25f22 100644--- a/docs/faq.md+++ b/docs/faq.md@@ -227,6 +227,19 @@ PDF export uses WeasyPrint, which resolves glyphs through the host's installed fAfter installing, restart LDR and re-export the PDF.+### Emojis show up as empty boxes in exported PDFs++Emojis in the markdown are routed through the host's emoji font by WeasyPrint. If the system has no emoji font installed, each emoji codepoint renders as an empty box ("tofu") in the PDF. Install an emoji font package:++- **Debian/Ubuntu:** `sudo apt install fonts-noto-color-emoji && fc-cache -fv`+- **Fedora/RHEL 10+:** `sudo dnf install google-noto-color-emoji-fonts && fc-cache -fv`+- **RHEL 9 / CentOS Stream 9:** `sudo dnf install google-noto-emoji-color-fonts && fc-cache -fv` (package was renamed to `google-noto-color-emoji-fonts` in EL10)+- **Alpine:** `apk add font-noto-emoji` (the package name omits "color" but ships the color `NotoColorEmoji.ttf`)+- **macOS / Windows:** emoji fonts ship with the OS — no install needed.+- **Docker (official image):** `fonts-noto-color-emoji` is bundled, no action needed.++After installing, restart LDR and re-export the PDF.+## Search Engines### SearXNG connection errorsdiff --git a/docs/install-pip.md b/docs/install-pip.mdindex af8098d8f8..a5014948ad 100644--- a/docs/install-pip.md+++ b/docs/install-pip.md@@ -56,6 +56,16 @@ pip install "local-deep-research[mcp]">> Docker users on the official image do not need to do anything; `fonts-noto-cjk` is bundled.+> **Emoji in PDF exports:** Emojis in the markdown are rendered through the host's emoji font. If they appear as empty boxes ("tofu") in the PDF, install an emoji font package:+>+> - **Debian/Ubuntu:** `sudo apt install fonts-noto-color-emoji && fc-cache -fv`+> - **Fedora/RHEL 10+:** `sudo dnf install google-noto-color-emoji-fonts && fc-cache -fv`+> - **RHEL 9 / CentOS Stream 9:** `sudo dnf install google-noto-emoji-color-fonts && fc-cache -fv` (package was renamed to `google-noto-color-emoji-fonts` in EL10)+> - **Alpine:** `apk add font-noto-emoji` (the package name omits "color" but ships the color `NotoColorEmoji.ttf`)+> - **macOS / Windows:** ships with the OS — no install needed.+>+> Docker users on the official image do not need to do anything; `fonts-noto-color-emoji` is bundled.+## Development from SourceFor contributing or running from the latest code, see the [Development Guide](developing.md).diff --git a/src/local_deep_research/web/services/pdf_service.py b/src/local_deep_research/web/services/pdf_service.pyindex 2bdb8539bc..b263726803 100644--- a/src/local_deep_research/web/services/pdf_service.py+++ b/src/local_deep_research/web/services/pdf_service.py@@ -94,82 +94,103 @@ def get_weasyprint_install_instructions() -> str:)+# Default stylesheet for PDF export. Exposed as a module-level constant so+# tests can assert against the source string (WeasyPrint's CSS object does+# not retain its input).+#+# CJK families are listed as fallbacks so WeasyPrint substitutes a+# glyph-bearing font when the primary stack lacks coverage. Without+# this, Chinese/Japanese/Korean text disappears silently from the+# PDF even though it renders fine in the HTML view (issue #4055).+# Glyphs still require the corresponding system font (e.g.+# fonts-noto-cjk) to actually be installed.+#+# The emoji families at the tail of each stack cover emoji+# codepoints that Arial and the CJK fonts lack entirely — without+# them, emojis in the markdown render as "tofu" boxes in the PDF+# even though they look fine in the HTML view. Color first+# (preferred when WeasyPrint can render the CBDT/CBLC bitmap+# tables — the format Debian's fonts-noto-color-emoji ships),+# then a monochrome fallback for renderers without CBDT support.+# Note: "Noto Color Emoji" is provided by fonts-noto-color-emoji;+# the monochrome "Noto Emoji" is a separate package+# (fonts-noto-emoji / fonts-noto-extra) and is a best-effort+# fallback for hosts that happen to have it installed.+MINIMAL_CSS = """+@page {+ size: A4;+ margin: 1.5cm;+}++body {+ font-family: Arial, "Noto Sans CJK SC", "Noto Sans CJK TC",+ "Noto Sans CJK JP", "Noto Sans CJK KR", "Noto Sans SC",+ "PingFang SC", "PingFang TC", "Hiragino Sans",+ "Hiragino Kaku Gothic ProN", "Apple SD Gothic Neo",+ "Microsoft YaHei", "Microsoft JhengHei",+ "Yu Gothic", "Malgun Gothic", "SimSun",+ "Noto Color Emoji", "Noto Emoji", "Segoe UI Emoji",+ "Apple Color Emoji", sans-serif;+ font-size: 10pt;+ line-height: 1.4;+}++table {+ border-collapse: collapse;+ width: 100%;+ margin: 0.5em 0;+}++th, td {+ border: 1px solid #ccc;+ padding: 6px;+ text-align: left;+}++th {+ background-color: #f0f0f0;+}++h1 { font-size: 16pt; margin: 0.5em 0; }+h2 { font-size: 14pt; margin: 0.5em 0; }+h3 { font-size: 12pt; margin: 0.5em 0; }+h4 { font-size: 11pt; margin: 0.5em 0; font-weight: bold; }+h5 { font-size: 10pt; margin: 0.5em 0; font-weight: bold; }+h6 { font-size: 10pt; margin: 0.5em 0; }++code, pre {+ font-family: monospace, "Noto Sans Mono CJK SC",+ "Noto Sans Mono CJK TC", "Noto Sans Mono CJK JP",+ "Noto Sans Mono CJK KR", "Noto Sans CJK SC",+ "PingFang SC", "Hiragino Sans", "Apple SD Gothic Neo",+ "Microsoft YaHei", "SimSun",+ "Noto Color Emoji", "Noto Emoji", "Segoe UI Emoji",+ "Apple Color Emoji";+ background-color: #f5f5f5;+}++code {+ padding: 1px 3px;+}++pre {+ padding: 8px;+ overflow-x: auto;+}++a {+ color: #0066cc;+ text-decoration: none;+}+"""++class PDFService:"""Service for converting markdown to PDF using WeasyPrint."""def __init__(self):"""Initialize PDF service with minimal CSS for readability."""- # CJK families are listed as fallbacks so WeasyPrint substitutes a- # glyph-bearing font when the primary stack lacks coverage. Without- # this, Chinese/Japanese/Korean text disappears silently from the- # PDF even though it renders fine in the HTML view (issue #4055).- # Glyphs still require the corresponding system font (e.g.- # fonts-noto-cjk) to actually be installed.- self.minimal_css = CSS(- string="""- @page {- size: A4;- margin: 1.5cm;- }-- body {- font-family: Arial, "Noto Sans CJK SC", "Noto Sans CJK TC",- "Noto Sans CJK JP", "Noto Sans CJK KR", "Noto Sans SC",- "PingFang SC", "PingFang TC", "Hiragino Sans",- "Hiragino Kaku Gothic ProN", "Apple SD Gothic Neo",- "Microsoft YaHei", "Microsoft JhengHei",- "Yu Gothic", "Malgun Gothic", "SimSun", sans-serif;- font-size: 10pt;- line-height: 1.4;- }-- table {- border-collapse: collapse;- width: 100%;- margin: 0.5em 0;- }-- th, td {- border: 1px solid #ccc;- padding: 6px;- text-align: left;- }-- th {- background-color: #f0f0f0;- }-- h1 { font-size: 16pt; margin: 0.5em 0; }- h2 { font-size: 14pt; margin: 0.5em 0; }- h3 { font-size: 12pt; margin: 0.5em 0; }- h4 { font-size: 11pt; margin: 0.5em 0; font-weight: bold; }- h5 { font-size: 10pt; margin: 0.5em 0; font-weight: bold; }- h6 { font-size: 10pt; margin: 0.5em 0; }-- code, pre {- font-family: monospace, "Noto Sans Mono CJK SC",- "Noto Sans Mono CJK TC", "Noto Sans Mono CJK JP",- "Noto Sans Mono CJK KR", "Noto Sans CJK SC",- "PingFang SC", "Hiragino Sans", "Apple SD Gothic Neo",- "Microsoft YaHei", "SimSun";- background-color: #f5f5f5;- }-- code {- padding: 1px 3px;- }-- pre {- padding: 8px;- overflow-x: auto;- }-- a {- color: #0066cc;- text-decoration: none;- }- """- )+ self.minimal_css = CSS(string=MINIMAL_CSS)def markdown_to_pdf(self,@@ -185,7 +206,10 @@ class PDFService:markdown_content: The markdown text to converttitle: Optional title for the documentmetadata: Optional metadata dict (author, date, etc.)- custom_css: Optional CSS string to override defaults+ custom_css: Optional CSS string layered on top of the default+ stylesheet. Rules here win on equal specificity via the+ cascade, but the default's CJK/emoji font fallbacks and+ page setup are always applied.Returns:PDF file as bytes@@ -206,12 +230,15 @@ class PDFService:# url_fetcher blocks SSRF targets reachable via body/citation URLs.html_doc = HTML(string=html_content, url_fetcher=_safe_url_fetcher)- # Apply CSS (custom or minimal default)- css_list = []+ # Always apply the default stylesheet first, then layer any+ # caller-provided custom_css on top. WeasyPrint resolves+ # conflicts by cascade order, so later stylesheets win on+ # equal specificity — this preserves the CJK and emoji font+ # fallbacks in MINIMAL_CSS even when a caller supplies their+ # own CSS, while still letting them override any default.+ css_list = [self.minimal_css]if custom_css:css_list.append(CSS(string=custom_css))- else:- css_list.append(self.minimal_css)# Generate PDF# Use BytesIO to get bytes instead of writing to filediff --git a/tests/web/services/test_pdf_service.py b/tests/web/services/test_pdf_service.pyindex 013c7310c3..f2c76efded 100644--- a/tests/web/services/test_pdf_service.py+++ b/tests/web/services/test_pdf_service.py@@ -33,6 +33,35 @@ class TestPDFServiceInit:# The CSS string should be accessibleassert service.minimal_css is not None+ def test_minimal_css_includes_emoji_font_families(self):+ """Body and code font stacks must fall back to an emoji font.++ Without an emoji family in the stack, WeasyPrint renders emoji+ codepoints as "tofu" boxes because Arial and the CJK fonts have+ no emoji coverage. Regression test for the emoji font stack.+ """+ from local_deep_research.web.services.pdf_service import MINIMAL_CSS++ assert "Noto Color Emoji" in MINIMAL_CSS+ assert "Noto Emoji" in MINIMAL_CSS++ # Both the body and code/mono stacks should have emoji fallbacks.+ # Pull out just the font-family declarations to make the assertion+ # resilient to other CSS edits.+ import re++ font_family_blocks = re.findall(r"font-family:\s*([^;]+);", MINIMAL_CSS)+ assert len(font_family_blocks) >= 2, (+ "expected at least body + code font-family declarations"+ )+ for block in font_family_blocks:+ assert "Noto Color Emoji" in block, (+ f"font-family block missing color emoji fallback: {block!r}"+ )+ assert "Noto Emoji" in block, (+ f"font-family block missing monochrome emoji fallback: {block!r}"+ )+class TestMarkdownToHTML:"""Tests for _markdown_to_html method."""@@ -199,6 +228,43 @@ class TestMarkdownToPDF:assert isinstance(pdf_bytes, bytes)assert len(pdf_bytes) > 0+ def test_custom_css_layers_on_top_of_default(self):+ """custom_css must extend, not replace, the default stylesheet.++ Regression test: previously markdown_to_pdf used an if/else that+ dropped self.minimal_css entirely when custom_css was provided,+ silently losing the CJK and emoji font fallbacks. Verify the+ default stylesheet is always passed to WeasyPrint.+ """+ from unittest.mock import patch, MagicMock+ from local_deep_research.web.services.pdf_service import PDFService++ service = PDFService()+ custom_css = "body { color: red; }"++ with (+ patch(+ "local_deep_research.web.services.pdf_service.CSS",+ side_effect=lambda **kwargs: MagicMock(**kwargs),+ ),+ patch(+ "local_deep_research.web.services.pdf_service.HTML"+ ) as mock_html,+ ):+ mock_html.return_value.write_pdf.return_value = b"%PDF-1.7"++ service.markdown_to_pdf("# x", custom_css=custom_css)++ # write_pdf must receive both the default and the custom CSS.+ call_kwargs = mock_html.return_value.write_pdf.call_args.kwargs+ stylesheets = call_kwargs.get("stylesheets", [])+ assert len(stylesheets) == 2, (+ f"expected [default, custom]; got {len(stylesheets)} sheets"+ )+ assert stylesheets[0] is service.minimal_css, (+ "default MINIMAL_CSS must always be applied first"+ )+def test_markdown_to_pdf_complex_document(self):"""Test PDF conversion with complex document."""from local_deep_research.web.services.pdf_service import PDFService