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.
by Mojtaba Mohammadi · github.com/mojtaba2021/post-pdf-download
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mojtaba2021/post-pdf-download/archive/refs/heads/main.zipA 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
-
Clone or download this repository:
git clone https://github.com/mojtaba2021/post-pdf-download.git cd post-pdf-download -
Install dependencies via Composer:
composer install -
Zip the folder or upload directly into your WordPress
/wp-content/plugins/directory. -
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 servicesService Providers– Each module (Admin, Frontend, PDF, Block) registers itself via aregister()methoddomPDF– 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
FrontendServiceProvideradds a Download PDF button under each post- Button triggers an AJAX request →
PdfServiceProvidergenerates PDF PdfServiceProviderusesmPDFto convert content into a PDF- 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.