{"record":{"id":"328048f5f4b6244e","repo":"infiniflow/ragflow","slug":"pdf-generation-failed-str-e","errorCode":null,"errorMessage":"PDF generation failed: {str(e)}","messagePattern":"PDF generation failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"agent/component/docs_generator.py","lineNumber":614,"sourceCode":"            try:\n                file_path, _ = self._generate_pandoc_binary_output(\n                    content,\n                    \"pdf\",\n                    \"pdf\",\n                    include_timestamp_in_body=False,\n                    extra_args=[\n                        \"--standalone\",\n                        f\"--pdf-engine={engine}\",\n                        f\"--include-in-header={header_path}\",\n                        *self._get_pdf_font_args(),\n                    ],\n                )\n            finally:\n                if os.path.exists(header_path):\n                    os.remove(header_path)\n            return self._apply_pdf_overlay(file_path)\n        except Exception as e:\n            raise Exception(f\"PDF generation failed: {str(e)}\")\n\n    def _generate_docx(self, content: str) -> tuple[str, bytes]:\n        try:\n            file_path, _ = self._generate_pandoc_binary_output(\n                content,\n                \"docx\",\n                \"docx\",\n                include_timestamp_in_body=False,\n                extra_args=[\"--standalone\"],\n            )\n            return self._decorate_docx(file_path)\n        except Exception as e:\n            raise Exception(f\"DOCX generation failed: {str(e)}\")\n\n    def _generate_txt(self, content: str) -> tuple[str, bytes]:\n        try:\n            return self._generate_pandoc_text_output(content, \"plain\", \"txt\")\n        except Exception as e:","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/docs_generator.py#L596-L632","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"# before: content with raw LaTeX specials\ncontent = \"Cost is 100% of $50 & rising\"\n\n# after: escape or wrap\ncontent = \"Cost is 100\\\\% of \\$50 \\& rising\"","handlingStrategy":"try-catch","validationCode":"import shutil\n\ndef pdf_prerequisites_ok():\n    return shutil.which('xelatex') and shutil.which('pandoc')\n\n# plus: verify fonts exist, e.g. fc-list | grep -i 'Noto Sans CJK'","typeGuard":null,"tryCatchPattern":"try:\n    file_path, file_bytes = generator._generate_pdf(content)\nexcept Exception as e:\n    inner = str(e).removeprefix('PDF generation failed: ')\n    logger.error('PDF generation root cause: %s', inner)\n    if 'not found' in inner and 'font' in inner.lower():\n        hint = 'Install fonts-noto-cjk'\n    elif 'pandoc' in inner.lower():\n        hint = 'Install pandoc/pypandoc-binary'\n    else:\n        hint = 'Reproduce with pandoc --pdf-engine=xelatex'\n    raise RuntimeError(f'{inner} ({hint})') from e","preventionTips":["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"],"tags":["doc-generator","pdf","pandoc","runtime","error-wrapping"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}