This project aims to create an intuitive way for laravel users to create PDF documents through LaTeX with minimal pain.
I leverage the blade
template to write the actual LaTeX code and compile with pdflatex
. This allows for the use of {{ }}
to drop in variables and use all of the normal blade
commands.
Available through composer:
composer require fvhockney/latexcompiler
Publish the configuration file:
php artisan vendor:publish --tag=fvlatex-config
This publishes the default configuration file to config/fvlatex.php
where you can modify your default preferences.
NB: logging automatically merges from the vendor file fvlatexlogchannel.php
to the default config/logging.php
file on boot
.
This packages is compatible with injection. You can use the fluent interface to pass in required and optional parameters.
->with($data)
: (object|array) passes to the template to fill->in($view)
: (string) name of the view you wish to use to create the .tex
document->complie($name)
: (string) the name of the file you want to use without any extensions->runs($runs)
: (integer) number of times you want pdflatex
to run, defaults to config which is initially set at 2->storagePath($path)
: (string path) overrides the default storage path in config...useful for multi user systems->deletePdf()
: beta deletes the pdf from the storage path->run()
: compiles the document in a build directory and moves it to the storage path. It then tears down the build directory->fillTemplate()
: fills in the tempplate but doesn't run the shell commands to compile the PDF.->pdfUrl
: called after ->run()
to get the storage location with the filename of the PDF.->template
: called after ->run()
or ->fillTemplate
to get the tex
stringThere is an example controller, tex template view, and form view included for you to try this out in your setup without having to waste time writing the form and tex files. Just copy the controller to your app/Http/Controllers
, set up at GET
route for the form and POST
to the controller to get started.
Make sure you have tex installed on your system and that you provide the fully qualified path to where pdflatex
is located.
LaTeX can be pretty finicky, so I highly recommend that you test your templates extensively on a local system before deploying. Also, there is currently no escaping of user inputs, so if your users input a reserved character in Tex, it will not be escaped automatically and could break the compilation sequence.
I would love to hear your thoughts and ideas about how to make this package better! Feel free to contact me, fork, or submit a pull request!