Skip to main content

Step 1: Prerequisites & Installation

Open your terminal in your Laravel project root and run these commands.
  1. Install PHP Packages:
  1. Install System Dependencies: You must install the WeasyPrint command-line tool on your server.
  • On Debian/Ubuntu:
  • For other systems (macOS, Windows, Docker), follow the official WeasyPrint installation guide.

Step 2: Configuration

1. Environment Variables (.env) Add the credentials for your MinIO (or other S3-compatible) storage.
2. Filesystem Configuration (config/filesystems.php) Add the minio disk to the disks array.
3. Custom Document Conversion Configuration (config/documents.php) Create this new file to map file extensions to your driver classes.

Step 3: Core Architecture (Interfaces & Service)

Create the necessary directories: mkdir -p app/Services/DocumentConversion/Contracts mkdir -p app/Services/DocumentConversion/Drivers/Input mkdir -p app/Services/DocumentConversion/Drivers/Output 1. InputDriverInterface.php
2. OutputDriverInterface.php
3. DocumentConverter.php (The Orchestrator)

Step 4: The Driver Implementations

1. MarkdownInputDriver.php
2. WeasyPrintOutputDriver.php
3. DocxOutputDriver.php

Step 5: Templates (Input & Layout)

1. Blade Layout (resources/views/layouts/document.blade.php) Create the base layout that will be used for all documents.
2. Sample Markdown Template (storage/app/templates/invoice.md) Create this sample input file.

Step 6: The Artisan Command

Run php artisan make:command ConvertDocumentCommand and replace its content with this:

Step 7: How to Use

You can now run the command from your terminal. Example 1: Convert Markdown to PDF and save to MinIO
Example 2: Convert Markdown to DOCX and save to the local public disk