PHP code example of techsemicolon / laravel-php-latex

1. Go to this page and download the library: Download techsemicolon/laravel-php-latex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

techsemicolon / laravel-php-latex example snippets



namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Techsemicolon\Latex;

class TestController extends Controller
{
    /**
     * Download PDF generated from latex
     * 
     * @return Illuminate\Http\Response
     */
    public function download(){

        return (new Latex)->dryRun();
    }


namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Techsemicolon\Latex;

class TestController extends Controller
{
    /**
     * Download PDF generated from LaTex
     * 
     * @return Illuminate\Http\Response
     */
    public function download(){

        return (new Latex('latex.tex'))->with([
            'name' => 'John Doe',
            'dob' => '01/01/1994',
            'addresses' => [
                '20 Pumpkin Hill Drive Satellite Beach, FL 32937',
                '7408 South San Juan Ave. Beaver Falls, PA 15010'
            ]
        ])->download('test.pdf');
    }


namespace App\Listeners;

use Techsemicolon\LatexPdfWasGenerated;

class LatexPdfWasGeneratedConfirmation
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  LatexPdfWasGenerated  $event
     * @return void
     */
    public function handle(LatexPdfWasGenerated $event)
    {
        // Path  of pdf in case in was saved 
        // OR 
        // Downloaded name of pdf file in case it was downloaded in response directly
        $pdf = $event->pdf;

        // download OR savepdf
        $action = $event->action;

        // metadata $user in this example
        $user = $event->metadata;

        // Perform desired actions
    }