Skip to main content

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

Time required

15 minutes

Prerequisites

Basic Python knowledge and familiarity with document manipulation libraries

Step 1: Set Up Your Environment

1

Install the Dify Plugin CLI

Verify installation:
2

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

1

Set up your debug environment

First, create your .env file from the template:
Configure it with your Dify environment details:
2

Install dependencies

3

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

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.
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.

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 languages
Last modified on July 2, 2026