What You’ll Build#
You’ll build a practical Dify plugin that exports conversations into popular document formats. By the end, your plugin will:
- Convert markdown text to Word documents (.docx)
- Export conversations as PDF files
- Handle file creation with proper formatting
- Provide a clean user experience for document exports
15 minutes
Basic Python knowledge and familiarity with document manipulation libraries
Step 1: Set Up Your Environment#
Install the Dify Plugin CLI
Create the plugin project
Initialize a new plugin project:
Follow the prompts:
- Name:
md_exporter - Type:
tool - Complete the remaining details as prompted.
Step 2: Define the Plugin Manifest#
Create the manifest.yaml file to define your plugin’s metadata:
Step 3: Define the Word Export Tool#
Create a word_export.yaml file to define the Word document export tool:
Step 4: Define the PDF Export Tool#
Create a pdf_export.yaml file for PDF exports:
Step 5: Install Required Dependencies#
Create or update requirements.txt with the necessary libraries:
Step 6: Implement the Word Export#
Create a utility module in utils/docx_utils.py:
Step 7: Implement the PDF Export#
Create a utility module in utils/pdf_utils.py:
Step 8: Create the Tool Implementations#
First, create the Word export tool in tools/word_export.py:
Next, create the PDF export tool in tools/pdf_export.py:
Step 9: Create the Entrypoint#
Create a main.py file at the root of your project:
Step 10: Test Your Plugin#
Set up your debug environment
First, create your .env file from the template:
Configure it with your Dify environment details:
Install dependencies
Start the plugin in debug mode
Step 11: Package for Distribution#
When you’re ready to share your plugin:
This creates a plugin.difypkg file for distribution.
Creative Use Cases#
Use this plugin to convert analysis summaries into professional reports for clients
Export coaching or consulting session notes as formatted documents
Beyond the Basics#
Here are some interesting ways to extend this plugin:
- Custom templates: Add company branding or personalized styles.
- Multi-format support: Expand to export as HTML, Markdown, or other formats.
- Image handling: Process and include images from conversations.
- Table support: Implement proper formatting for data tables.
- Collaborative editing: Add integration with Google Docs or similar platforms.
Technical Insights
The core challenge in document conversion is maintaining formatting and structure. This plugin first converts markdown to HTML as an intermediate format, then processes that HTML into the target format.
The two-step process provides flexibility: you can support additional formats by adding new output modules that work with the HTML representation.
For PDF generation, the plugin uses WeasyPrint because it offers high-quality PDF rendering with CSS support. For Word documents, python-docx provides granular control over document structure.
Summary#
You’ve built a practical plugin that lets users export conversations in professional document formats, bridging the gap between AI conversations and traditional document workflows.
Write your README.md in English (en_US) describing functionality, setup, and usage examples
Create additional README files like readme/README_zh_Hans.md for other languages