WP Manifestindependent plugin directory
manifest / content / post-pdf-download

Post PDF Download

A lightweight WordPress plugin that adds a “Download as PDF” button to posts. Generates PDFs in real-time using mPDF, built with Dependency Injection and a modular provider-based architecture.

★ 0stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/mojtaba2021/post-pdf-download/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

A lightweight WordPress plugin that adds a “Download as PDF” button to your posts. When users click the button, a PDF is generated in real-time using domPDF and downloaded instantly.


🚀 Features

  • 🖨️ Generate PDF files dynamically from post content
  • ⚙️ Enable or disable button visibility via admin settings
  • 🧩 Choose which post types display the download button
  • 🧱 Clean, modular structure using Service Providers & Dependency Injection
  • 🧠 Built with Composer autoload (PSR-4) for professional extensibility

🗂️ Folder Structure

post-pdf-download/
├── post-pdf-download.php          # Main plugin file
├── composer.json                  # Composer autoload and dependencies
├── vendor/                        # Composer dependencies (mPDF)
└── src/
    ├── Core/
    │   ├── Plugin.php
    │   └── DependencyInjection/
    │       └── DependencyInjection.php
    ├── Admin/
    │   └── AdminServiceProvider.php
    ├── Block/
    │   └── BlockServiceProvider.php
    ├── Pdf/
    │   └── PdfServiceProvider.php
    └── Frontend/
        └── FrontendServiceProvider.php

⚡ Installation

  1. Clone or download this repository:

    git clone https://github.com/mojtaba2021/post-pdf-download.git
    cd post-pdf-download
  2. Install dependencies via Composer:

    composer install
  3. Zip the folder or upload directly into your WordPress /wp-content/plugins/ directory.

  4. Activate Post PDF Download from your WordPress admin panel.


🧩 Usage

Once activated:

  • Go to Dashboard → Post PDF Download Settings
  • Enable or disable the download button
  • Specify which post types should have the button
  • Visit any single post — a “Download PDF” button will appear under the content
  • Clicking the button generates and downloads the post as a PDF in real-time

🧱 Technical Overview

The plugin uses a Provider-based architecture with Dependency Injection:

  • DependencyInjection – Manages all plugin services
  • Service Providers – Each module (Admin, Frontend, PDF, Block) registers itself via a register() method
  • domPDF – Converts HTML post content to downloadable PDF
  • Autoload – All classes are PSR-4 autoloaded via Composer

This design keeps your code modular, testable, and extendable. You can easily add new Service Providers for additional features, e.g., custom templates or branding.


⚙️ Example Flow

  1. FrontendServiceProvider adds a Download PDF button under each post
  2. Button triggers an AJAX request → PdfServiceProvider generates PDF
  3. PdfServiceProvider uses mPDF to convert content into a PDF
  4. Browser downloads the PDF instantly

🧑‍💻 Extending the Plugin

Create a custom Service Provider:

namespace PostPDFDownload\Custom;

use PostPDFDownload\Core\DependencyInjection\DependencyInjection;
use PostPDFDownload\Core\ServiceProviderInterface;

class CustomServiceProvider implements ServiceProviderInterface {
    public function register(DependencyInjection $di) {
        // your custom logic here
    }
}

Register it in Core/Plugin.php:

$this->di->addServiceProvider( new \PostPDFDownload\Custom\CustomServiceProvider() );

🧾 Requirements

  • PHP >= 8.1
  • WordPress >= 6.0
  • Composer
  • domPDF library (composer install)

📜 License

This plugin is open-source software licensed under GPL-2.0+.


💡 Credits

Developed by Mojtaba Mohammadi Inspired by modern dependency injection patterns and clean WordPress architecture.