PHPackages                             spirit-of-wars/docmvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. spirit-of-wars/docmvc

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

spirit-of-wars/docmvc
=====================

DocMVC, MVC-library for generating files (excel, doc, pdf)

v1.0.3(4y ago)19LGPL-2.1-or-laterPHPPHP ^7.2 || ^8.0

Since Dec 25Pushed 4y agoCompare

[ Source](https://github.com/spirit-of-wars/docmvc)[ Packagist](https://packagist.org/packages/spirit-of-wars/docmvc)[ RSS](/packages/spirit-of-wars-docmvc/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

The library is designed to work with files PDF, Excel, Word. This one is micro framework about mvc-model

**General provisions:**

- To get started you need create instance DocumentManager then download class-cartridge for him
- Working with data, customizing paths and required parameters must be done only in class-cartridge
- There are two ways to generate a document: render document from scratch (using view), render document from existed document (template)
- Document rendering logic must be written only in the view file (view)
- External dependencies are used to generate view-logic. The processors object of these libraries is available in view file via a variable $driver
    - Doc/Docx - phpoffice/phpword
    - Excel - phpoffice/phpspreadsheet
    - Pdf - dompdf/dompdf
- Template is a blank document that does not yet contain the necessary data, but they will be substituted by the generation process. Such data is defined only in the model. (Example: To generate an excel document, we created a template.xlsx blank then inside in curly brackets we specify variables from where to take values)

**To get started you need:**

1. Create a shared directory where everything will be stored. I am using a directory called 'document'
2. Inside this one you need create one more directory (arbitrary name). Now each such directory will be responsible for its own document.
3. In this directory you need to create classes-cartridges. For example, I need to make a financial report document in doc and pdf formats. For this i will create directory Report/ in the directory Document/ In the Document/ directory i will create two files: Doc.php (extended from SpiritOfWars\\DocMVC\\Cartridge\\DocCartridge) and Pdf.php (SpiritOfWars\\DocMVC\\Cartridge\\PdfCartridge)
4. Each cartridge have 1 abstract method, that must be defined:
    - setupView - must be return string, that contains name and path from view-file. *CANNOT BE EMPTY!* View file required must be created and the path to it must be specified Also each cartridge have 3 optional methods:
    - setupModel - must be return array data. This data will be use in view-file or filling template variables
    - setupTemplate - must be return string, that contains name and path from template-file. (To pdf-cartridge is not available)
    - setupRequiredParams - must be return array of required params, that you want to pass to constructor. We specify only those parameters, without which the generation of the document is impossible. If there are none, do not touch this method
5. Create directory view/ (in my example: Document/Report/view/)
6. Create view-file with any name (in my example: i created Document/Report/view/view-pdf.php to pdf document)
7. Set path to view-file in the cartridges method setupView (in my example: return 'view-pdf.php';). Caution! Path must be relative.
8. If you need generating by template, just repeat steps 6,7,8 for template names. Directory for created must be named template/. Set path to template-document in the cartridges method setupTemplate. Caution! Path must be relative.
9. The view file is intended for html layout, or its generation by $driver variable. Available by default two variables $driver - an object to work with the generation of document content, $model - an array with the data you specified in method setupModel
10. In the right place in your code, we create an instance of our created cartridge, pass an array of parameters to the constructor, which will be available through the property $this-&gt;params (in my example $docObj = new(\\Document\\Report\\Doc(\['testKey' =&gt; 'testValue'\])))
11. Create instance of DocumentManager: new SpiritOfWars\\DocMVC\\DocumentManager($docObj) . Optional: logger object can be passed as second parameter
12. Build document $docObj-&gt;build();
13. Now the generated document available for download or saving to directory. Methods: saveAs(), download()

**A few important notes:**

- Templates are not available for pdf documents
- While downloading the document, make sure that nothing extra is displayed on the page. Because all this will also be generated document. Which can even lead to its unreadability
- By default, the name of the downloaded document will be of the form timestamp().{extension}. You need override method setupDocName() to change name. The name must not contain a file extension.
- Each class has its own default document extension. You can change it by overriding method setupFileExt. However, the extension you specify in it must be on the list of allowed (method allowedExt)
- The /sample/ folder contains examples of working with documents
- If you need to pass data from a method to a method, you can use the $this-&gt;commonData property

**Code Examples:**Generating docx-document for download

Class-cartridge Doc.php, is in the directory document/test/Doc.php

```
 use SpiritOfWars\DocMVC\Cartridge\DocCartridge;

 class Doc extends DocCartridge
 {

     public function setupView()
     {
         return 'doc/view.php';
     }

     public function setupModel()
     {
         $test = $this->params['test']; // required param
         $randParam = $this->params['test2'];
         return [
             'test' => $test,
             'randParam' => $randParam
         ];
     }

     public function setupRequiredParams()
     {
         return ['test'];
     }

     public function setupDocName()
     {
         return 'test-name';
     }
 }
```

View-file view.php is in the directory document/test/view/view.php

```
 $PHPWord = $driver;
 $data = $model;

 $PHPWord->addFontStyle('nStyle', array('size'=>10,'name'=>'Arial CYR'));
 $PHPWord->addParagraphStyle('pRight', array('align'=>'right','spaceAfter'=>0));
 $PHPWord->addParagraphStyle('pRightT', array('align'=>'right','spaceBefore'=>400,'spaceAfter'=>0));
 $PHPWord->addParagraphStyle('pRightB', array('align'=>'right','spaceAfter'=>400,'spaceAfter'=>0));
 $PHPWord->addParagraphStyle('pCenter', array('align'=>'center','spaceAfter'=>0));
 $PHPWord->addParagraphStyle('pLeft', array('align'=>'left','spaceAfter'=>0));
 $PHPWord->addParagraphStyle('pLeftT', array('align'=>'left','spaceBefore'=>400,'spaceAfter'=>0));

 $PHPWord->setDefaultFontName('Arial CYR');
 $PHPWord->setDefaultFontSize(10);

 $section = $PHPWord->createSection(array('marginLeft'=>1100, 'marginRight'=>1100, 'marginTop'=>1100, 'marginBottom'=>1100));
 $section->addText('Test text', 'nStyle', 'pRight');
 $section->addText('Test text №2', 'nStyle', 'pRight');

 $textrun = $section->createTextRun('pRight');
 $textrun->addText($data['test']);
 $textrun->addText($data['randParam']);
```

Creating instance of class, passing params for it then download result document

```
$testDoc = new Doc([
   'test' => 'test content',
   'randParam' => 'random param'
]);

$documentManager = new DocumentManager($testDoc);

$documentManager->build()->download();
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~149 days

Recently: every ~297 days

Total

9

Last Release

1503d ago

Major Versions

v0.1.4 → v1.0.02021-11-22

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v1.0.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c589746936c483256122c7e6dbc4bf9b0e6df9651cee898d5b1c380fd4627dc4?d=identicon)[spirit-of-wars](/maintainers/spirit-of-wars)

---

Top Contributors

[![spirit-of-wars](https://avatars.githubusercontent.com/u/25096871?v=4)](https://github.com/spirit-of-wars "spirit-of-wars (29 commits)")

---

Tags

pdfdocexcelfilesdownload

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spirit-of-wars-docmvc/health.svg)

```
[![Health](https://phpackages.com/badges/spirit-of-wars-docmvc/health.svg)](https://phpackages.com/packages/spirit-of-wars-docmvc)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k77.1M493](/packages/mpdf-mpdf)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3685.2M19](/packages/gotenberg-gotenberg-php)[jimmyjs/laravel-report-generator

Rapidly Generate Simple Pdf &amp; Excel Report on Laravel 5 (Using Barryvdh/DomPdf or Barryvdh/laravel-snappy &amp; maatwebsite/excel)

580157.4k1](/packages/jimmyjs-laravel-report-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
