Skip to content

laravel 5.7 docx template manipulation class, based on mustache templating language

License

Notifications You must be signed in to change notification settings

maffmeier/docxmustache

 
 

Repository files navigation

DocxMutache Logo

DocxMustache for Laravel 6.0.

Software License Quality Score Build Status StyleCI

Docx template manipulation class for Laravel 6.0, based on mustache templating language. This class is still under heavy development and works more like proof of concept at the moment. Things will change quickly and might break things.

Template Example in Word This package helps you to use docx files with mustache syntax as templates to merge richly styled documents with information from any data source. It can replace text and images and supports basic html styling (bold, itallic, underline).

Installation

composer require wrklst/docxmustache

Please check depencies down below and examples folder for configuration and usage.

HTML conversion

Current HTML conversion is basic and only supports singular runs of bold, italic and underlined text and no combination of these. It requires all values non html to be escaped with htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); and a prefix of *[[DONOTESCAPE]]* so the class knows not to escape the html before it is converted to openXML.

Replacing images

The image needs to be a reachable URL with a image in a supported format. The url value needs to be placed into the alt text description field of the image. Images will be resampled to the constraints of the placeholder image. The Image value needs to be formated the with pseudo tags around, such as: [IMG-REPLACE]http://placehold.it/350x150[/IMG-REPLACE]

Example

Please also checkout the example in the example folder to get a basic understand of how to use this class.

DOCX to PDF conversion

Conversion to PDF requires libreoffice-common to be installed on the server (used for conversion). Use sudo apt install libreoffice-common on your ubuntu/debian based server. Also install ttf-mscorefonts if you need support for Arial font when converting docx documents to pdf sudo apt-get install ttf-mscorefonts-installer

Other Dependencies

The package is dependent on several Laravel specific functions. It could easily be ported to other frameworks or be ported to be framework agnostic. In addition to the Laravel dependency, the page uses the following packages:

Laravel specific dependencies (only relevant if ported into non Laravel environment):

Contributions

If you would like to contribute something to this package, please feel free to make a pull request and a corresponding issue and we will be happy to review and discuss.

Why another openXML / docx template solution?

There are some classes out there that help with writing and or changing the content of word documents, some with commercial licenses and some free. For our particular purpose we did not need most of the features many of the libraries out there have – we needed a simple solution that would allow to replace values and images and traverse through data in a easy and straightforward manner.

Many of the other libraries use cloning to repeat a block with some custom templating syntax instead of using a existing template syntax. We use the usual mustache syntax, also to achieve repeating content in as many dimensions as needed.

Other PHP Classes to manipulate openXML word documents:

About

laravel 5.7 docx template manipulation class, based on mustache templating language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%