What you’ll build
In this guide, you’ll learn how to 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
Time required
15 minutes
Prerequisites
Basic Python knowledge and familiarity with document manipulation libraries
Step 1: Set up your environment
1
Install the Dify CLI
- Mac
- Linux
2
Create the plugin project
Initialize a new plugin project:Follow the prompts:
- Name: “md_exporter”
- Type: “tool”
- Complete other details as prompted
Step 2: Define plugin manifest
Create themanifest.yaml file to define your plugin’s metadata:
Step 3: Define the Word export tool
Create aword_export.yaml file to define the Word document export tool:
Step 4: Define the PDF export tool
Create apdf_export.yaml file for PDF exports:
Step 5: Install required dependencies
Create or updaterequirements.txt with the necessary libraries:
Step 6: Implement the Word export functionality
Create a utility module inutils/docx_utils.py:
Step 7: Implement the PDF export functionality
Create a utility module inutils/pdf_utils.py:
Step 8: Create tool implementations
First, create the Word export tool intools/word_export.py:
tools/pdf_export.py:
Step 9: Create the entrypoint
Create amain.py file at the root of your project:
Step 10: Test your plugin
1
Set up your debug environment
First, create your Configure it with your Dify environment details:
.env file from the template:2
Install dependencies
3
Start the plugin in debug mode
Step 11: Package for distribution
When you’re ready to share your plugin:plugin.difypkg file for distribution.
Creative use cases
Report generation
Use this plugin to convert analysis summaries into professional reports for clients
Session documentation
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
Technical insights
The core challenge in document conversion is maintaining formatting and structure. The approach used in this plugin first converts markdown to HTML (an intermediate format), then processes that HTML into the target format.This two-step process provides flexibility—you could extend it to support additional formats by simply adding new output modules that work with the HTML representation.For PDF generation, WeasyPrint was chosen 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 adds real value to the Dify platform by enabling users to export conversations in professional document formats. This functionality bridges the gap between AI conversations and traditional document workflows.Documentation
Write your README.md in English (en_US) describing functionality, setup, and usage examples
Localization
Create additional README files like
readme/README_zh_Hans.md for other languagesEdit this page | Report an issue