Skip to main content

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

Verify installation:
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 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 functionality

Create a utility module in utils/docx_utils.py:

Step 7: Implement the PDF export functionality

Create a utility module in utils/pdf_utils.py:

Step 8: Create 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. 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 languages

Edit this page | Report an issue