A component that generates downloadable PDF, DOCX, or TXT documents from markdown-style content with full Unicode support.
---
The **Docs Generator** component enables you to create professional documents directly within your agent workflow. It accepts markdown-formatted text and converts it into downloadable files, making it ideal for generating reports, summaries, or any structured document output.
## Key features
- **Multiple output formats**: PDF, DOCX, and TXT
- **Full Unicode support**: Automatic font switching for CJK (Chinese, Japanese, Korean), Arabic, Hebrew, and other non-Latin scripts
- **Rich formatting**: Headers, lists, tables, code blocks, and more
- **Customizable styling**: Fonts, margins, page size, and orientation
- **Document extras**: Logo, watermark, page numbers, and timestamps
- **Direct download**: Generates a download button for the chat interface
## Prerequisites
- Content to be converted into a document (typically from an **Agent** or other text-generating component).
## Examples
You can pair an **Agent** component with the **Docs Generator** to create dynamic documents based on user queries. The **Agent** generates the content, and the **Docs Generator** converts it into a downloadable file. Connect the output to a **Message** component to display the download button in the chat.
A typical workflow looks like:
```
Begin → Agent → Docs Generator → Message
```
In the **Message** component, reference the `download` output variable from the **Docs Generator** to display a download button in the chat interface.
| `file_path` | `string` | The server path where the generated document is saved. |
| `pdf_base64` | `string` | The document content encoded in base64 format. |
| `download` | `string` | JSON containing download information for the chat interface. |
| `success` | `boolean` | Indicates whether the document was generated successfully. |
### Displaying the download button
To display a download button in the chat, add a **Message** component after the **Docs Generator** and reference the `download` variable:
1. Connect the **Docs Generator** output to a **Message** component.
2. In the **Message** component's content field, type `/` and select `{Docs Generator_0@download}`.
3. When the agent runs, a download button will appear in the chat, allowing users to download the generated document.
The download button automatically handles:
- File type detection (PDF, DOCX, TXT)
- Proper MIME type for browser downloads
- Base64 decoding for direct file delivery
## Unicode and multi-language support
The **Docs Generator** includes intelligent font handling for international content:
### How it works
1.**Content analysis**: The component scans the text for non-Latin characters.
2.**Automatic font switching**: When CJK or other complex scripts are detected, the system automatically switches to a compatible CID font (STSong-Light for Chinese, HeiseiMin-W3 for Japanese, HYSMyeongJo-Medium for Korean).
3.**Latin content**: For documents containing only Latin characters (including extended Latin, Cyrillic, and Greek), the user-selected font family is used.
### Supported scripts
| Script | Unicode Range | Font Used |
| ------ | ------------- | --------- |
| Chinese (CJK) | U+4E00–U+9FFF | STSong-Light |
| Japanese (Hiragana/Katakana) | U+3040–U+30FF | HeiseiMin-W3 |
| Korean (Hangul) | U+AC00–U+D7AF | HYSMyeongJo-Medium |
| Arabic | U+0600–U+06FF | CID font fallback |
| Hebrew | U+0590–U+05FF | CID font fallback |
| Devanagari (Hindi) | U+0900–U+097F | CID font fallback |
| Thai | U+0E00–U+0E7F | CID font fallback |
### Font installation
For full multi-language support in self-hosted deployments, ensure Unicode fonts are installed:
**Linux (Debian/Ubuntu):**
```bash
apt-get install fonts-freefont-ttf fonts-noto-cjk
```
**Docker:** The official RAGFlow Docker image includes these fonts. For custom images, add the font packages to your Dockerfile:
```dockerfile
RUN apt-get update && apt-get install -y fonts-freefont-ttf fonts-noto-cjk
```
:::tip NOTE
CID fonts (STSong-Light, HeiseiMin-W3, etc.) are built into ReportLab and do not require additional installation. They are used automatically when CJK content is detected.
:::
## Troubleshooting
### Characters appear as boxes or question marks
This indicates missing font support. Ensure:
1. The content contains supported Unicode characters.
2. For self-hosted deployments, Unicode fonts are installed on the server.
3. The document is being viewed in a PDF reader that supports embedded fonts.
### Download button not appearing
Ensure:
1. The **Message** component is connected after the **Docs Generator**.
2. The `download` variable is correctly referenced using `/` (which appears as `{Docs Generator_0@download}` when copied).
3. The document generation completed successfully (check `success` output).
### Large tables not rendering correctly
For tables with many columns or large cell content:
- The component automatically converts wide tables to a definition list format for better readability.
- Consider splitting large tables into multiple smaller tables.