1. Go to this page and download the library: Download webstasolutions/laratex 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/ */
webstasolutions / laratex example snippets
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use webstasolutions\LaraTeX\LaraTeX;
class TestController extends Controller
{
/**
* Download PDF generated from latex
*
* @return Illuminate\Http\Response
*/
public function download(){
return (new LaraTeX)->dryRun();
}
}
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use webstasolutions\LaraTeX\LaraTeX;
class TestController extends Controller
{
/**
* Download PDF generated from LaTex
*
* @return Illuminate\Http\Response
*/
public function download(){
return (new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->download('test.pdf');
}
}
savePdf(string $location)
(new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->savePdf(storage_path('app/export/test.pdf'));
content(string $type = 'raw')
(new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->content();
(new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->content('base64');
inline(string $fileName = null)
(new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->inline('filename.pdf');
render()
$tex = new LaraTeX('latex.tex'))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->render();
use webstasolutions\LaraTeX\LaraTeX;
use webstasolutions\LaraTeX\RawTex;
...
$tex = new RawTex('your_raw_tex_content_string.....');
return (new LaraTeX($tex))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->download('test.pdf');
$latexCollection = (new LaratexCollection());
$users = User::limit(10)->get();
foreach ($users as $user) {
$pdfName = $user->first_name.'-'.$user->last_name.'-'.$user->id.'.pdf';
// Create LaraTeX instance
$laratex= (new LaraTeX('latex.report'))->with([
'user' => $user
])->setName($pdfName);
// Add it to latex collection
$latexCollection->add($laratex);
}
// Download the zip
return $latexCollection->downloadZip('Users.zip');
// OR you can also save it
$latexCollection->saveZip(storage_path('app/pdf/zips/Users.zip'));
$HTMLString = '<h1>Heading 1</h1> <p>Text</p> <h2>Heading 2</h2> <p>Text</p> <h3>Heading 3</h3> <p>Text</p> <p>Normal text here with some <strong>strong</strong> and <strong>bold</strong> text.</p> <p>There is also text that could be <u>underlined</u>.</p> <p>Or of course we could have <em>em-wrapped</em> or <em>i-wrapped</em> text</p> <p>A special test could be a <u><em><strong>bold, underlined and italic</strong></em></u> text at the same time!</p> <p>For the mathematicians we also have calculations x<sup>2</sup> and chemical stuff H<sub>2</sub>O</p> <p>We also have lists that needs to be shown. For example an unordered and an ordered list.</p> <p>If there is alot of text we might also want to use a line break <br> to continue on the next line.</p> <ul> <li>UL Item 1 <ul> <li>UL Item 1.1</li> <li>UL Item 1.2</li> </ul> </li> <li>UL Item 2</li> <li>UL Item 3</li> </ul> <ol> <li>UL Item 1</li> <li>UL Item 2</li> <li>UL Item 3</li> </ol> <p>Last but not least. We have images.</p> <img src="/images/testimages/image1.png" /> <img src="/images/testimages/image2.png" >';
$Override = array(
array('tag' => 'img', 'extract' => 'src', 'replace' => '\begin{center}\
// $user will be our metadata in this example
$user = Auth::user();
(new LaraTeX('latex.tex', $user))->with([
'Name' => 'John Doe',
'Dob' => '01/01/1990',
'SpecialCharacters' => '$ (a < b) $',
'languages' => [
'English',
'Spanish',
'Italian'
]
])->savePdf(storage_path('app/pdf/test.pdf'));
namespace App\Listeners;
use webstasolutions\LaraTeX\LaratexPdfWasGenerated;
class LaratexPdfWasGeneratedConfirmation
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param LatexPdfWasGenerated $event
* @return void
*/
public function handle(LaratexPdfWasGenerated$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
}
}
bash
php artisan vendor:publish --tag=config
echo $var;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.