infiniflow/ragflow · error · Exception
PDF generation failed: {str(e)}
Error message
PDF generation failed: {str(e)} What it means
Catch-all wrapper thrown by DocGenerator._generate_pdf (agent/component/docs_generator.py): any exception from the pandoc PDF conversion (engine invocation, header/font args, overlay step) is re-raised as Exception('PDF generation failed: <original message>'). The root cause is in the appended inner text — always read the suffix, not this headline.
Source
Thrown at agent/component/docs_generator.py:614
try:
file_path, _ = self._generate_pandoc_binary_output(
content,
"pdf",
"pdf",
include_timestamp_in_body=False,
extra_args=[
"--standalone",
f"--pdf-engine={engine}",
f"--include-in-header={header_path}",
*self._get_pdf_font_args(),
],
)
finally:
if os.path.exists(header_path):
os.remove(header_path)
return self._apply_pdf_overlay(file_path)
except Exception as e:
raise Exception(f"PDF generation failed: {str(e)}")
def _generate_docx(self, content: str) -> tuple[str, bytes]:
try:
file_path, _ = self._generate_pandoc_binary_output(
content,
"docx",
"docx",
include_timestamp_in_body=False,
extra_args=["--standalone"],
)
return self._decorate_docx(file_path)
except Exception as e:
raise Exception(f"DOCX generation failed: {str(e)}")
def _generate_txt(self, content: str) -> tuple[str, bytes]:
try:
return self._generate_pandoc_text_output(content, "plain", "txt")
except Exception as e:View on GitHub (pinned to 554fb1133a)
Solutions
- Read the text after 'PDF generation failed:' — it names the real fault (e.g. 'Font Noto Sans CJK SC not found')
- Install the font named in the inner error (fonts-noto-cjk) or the missing engine per error 154 guidance
- Reproduce outside the agent: echo content | pandoc -o out.pdf --pdf-engine=xelatex -V mainfont='Noto Sans CJK SC'
- If content is the problem, sanitize markdown (escape LaTeX-special chars like $, %, &, {}) or switch to docx/html output
Example fix
# before: content with raw LaTeX specials content = "Cost is 100% of $50 & rising" # after: escape or wrap content = "Cost is 100\\% of \$50 \& rising"
Defensive patterns
Strategy: try-catch
Validate before calling
import shutil
def pdf_prerequisites_ok():
return shutil.which('xelatex') and shutil.which('pandoc')
# plus: verify fonts exist, e.g. fc-list | grep -i 'Noto Sans CJK' Try / catch
try:
file_path, file_bytes = generator._generate_pdf(content)
except Exception as e:
inner = str(e).removeprefix('PDF generation failed: ')
logger.error('PDF generation root cause: %s', inner)
if 'not found' in inner and 'font' in inner.lower():
hint = 'Install fonts-noto-cjk'
elif 'pandoc' in inner.lower():
hint = 'Install pandoc/pypandoc-binary'
else:
hint = 'Reproduce with pandoc --pdf-engine=xelatex'
raise RuntimeError(f'{inner} ({hint})') from e Prevention
- Always parse the suffix after 'PDF generation failed:' — the headline is generic
- Bake xelatex + Noto CJK fonts into deployment images
- Smoke-test pdf generation (tiny markdown) after environment changes
- Escape LaTeX-special characters ($ % & { } # _) in dynamic content
When it happens
Trigger: Running DocGenerator with output_format 'pdf' where pandoc/xelatex fails: missing fonts specified by _get_pdf_font_args (Noto Sans CJK SC), malformed markdown that xelatex rejects, pandoc not installed (pypandoc raises OSError), or the _apply_pdf_overlay step failing. The try wraps the whole pandoc call plus overlay.
Common situations: Containers with xelatex but without the CJK fonts; pandoc version mismatches; special characters/unbalanced braces in content breaking LaTeX; reportlab overlay errors (missing STSong-Light CID font).
Related errors
- DOCX generation failed: {str(e)}
- TXT generation failed: {str(e)}
- Markdown generation failed: {str(e)}
- HTML generation failed: {str(e)}
- Document file is empty
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/328048f5f4b6244e.
Report an issue: GitHub.