PHP code example of open-administration / php-latex-renderer

1. Go to this page and download the library: Download open-administration/php-latex-renderer 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/ */

    

open-administration / php-latex-renderer example snippets




$tex = new LatexRenderer('./templates/'); // <- dir where to search the templates
$tex->setTmpDir('./runtime/'); // <- where to build the latex files
$pdf = $tex->renderPdf('simple-report', [ // <- which template to use (file ending .tex.twig)
    'title' => 'My Custom Title', // <- variables to set 
    'author' => 'Me!',
]);
// output / save the pdf with
file_put_contents('main.pdf', $pdf);
// or echo with fitting header 
header("Content-type:application/pdf");
echo $pdf;

$options = [
    'tag_block' => ['(%', '%)'],
    'tag_comment' => ['(!', '!)'],
    'tag_variable' => ['((', '))'],
];
 
$tex->setTwigLexer($options)
 
$this->twig->addGlobal('_tex', [
    'files' => $fileNames, // with name.pdf => files/name.pdf (local path in dir) 
    'dir' => $tmpDir . "tex/$templateName/$uid/",
    'template' => $twigTemplateName,
]);

composer 

php -f samples/simple-report.php