tcpdf on Lumen Class 'PDF' not found - tcpdf

I created a new project with Lumen 5.4.7 and I added the TCPDF library from elibyy/tcpdf-laravel version 5.4.2 (with Lumen support):
composer require elibyy/tcpdf-laravel "5.4.2"
I enabled the Facades and Service Provider in bootstrap/app.php with
$app->withFacades();
$app->register(Elibyy\TCPDF\ServiceProvider::class);
And I created a basic Controller:
<?php
namespace App\Http\Controllers;
use \PDF;
class PdfController extends Controller
{
/**
* Create a test PDF file.
*
* #return void
*/
public function createTestPdf()
{
PDF::SetTitle('Hello World');
PDF::AddPage();
PDF::Write(0, 'Hello World');
PDF::Output('hello_world.pdf');
echo "Fatto!";
}
}
with a basic route:
$app->get('pdf', 'PdfController#createTestPdf');
But when I try to access to /pdf I get the following error:
Fatal error: Class 'PDF' not found in /Users/m/Documents/Projects/lumen-pdf/app/Http/Controllers/PdfController.php on line 15
(1/1) FatalErrorException
Class 'PDF' not found
in PdfController.php (line 15)
at Application->handleShutdown()
in RegistersExceptionHandlers.php (line 54)
at Application->Laravel\Lumen\Concerns\{closure}()
Could you help me please?

I solved my problem.
One line was missing into bootstrap/app.php to add a new class_alias for Elibyy\TCPDF\Facades\TCPDF to PDF:
class_alias('Elibyy\TCPDF\Facades\TCPDF', 'PDF');
Thanks!

Related

Rails 7 + importmap + fullcalendar

I've manage to include bootstrap 5 without any issues, but when I try to include fullcalendar I get this error on browser console:
Failed to load module script: Expected a JavaScript module script but
the server responded with a MIME type of "text/css". Strict MIME type
checking is enforced for module scripts per HTML spec. (main.css:1)
So it looks like the library is imported correctly but the css isn't
my stimulus controller:
import { Controller } from "#hotwired/stimulus"
import moment from "moment"
import { Calendar } from '#fullcalendar/core';
import dayGridPlugin from '#fullcalendar/daygrid';
import timeGridPlugin from '#fullcalendar/timegrid';
import listPlugin from '#fullcalendar/list';
export default class extends Controller {
static targets = [ "calendar" ]
connect() {
console.log(this.calendarTarget)
let calendar = new Calendar(this.calendarTarget, {
plugins: [ dayGridPlugin, timeGridPlugin, listPlugin ],
initialView: 'dayGridMonth',
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,listWeek'
}
});
}
}
Any ideias what I'm doing it wrong?
EDIT: looks like is related to:
https://github.com/rails/rails/issues/44239
I have been fiddling with this problem for a while today. I too couldn't get past the issue with the JS trying to pull in the CSS and raising MIME type errors.
However, I have managed to get FullCalendar running with importmaps by vendoring the main.js file provided by the CDN (referenced here), and then manually editing the vendored file to export the FullCalendar function as the default.
main.js -> https://cdn.jsdelivr.net/npm/fullcalendar#5.11.0/main.min.js
Copy this into vendor/javascript/fullcalendar.js
Pin the file in importmap.rb:
pin "fullcalendar" # #5.11.0
At this point I have the following error:
Failed to register controller ... SyntaxError: The requested module 'fullcalendar' does not provide an export named 'default'
Edit your new vendor/javascript/fullcalendar.js file and append to the bottom:
export default FullCalendar;
And then in the stimulus controller:
import { Controller } from "#hotwired/stimulus"
import FullCalendar from 'fullcalendar';
export default class extends Controller {
connect() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth'
});
calendar.render();
}
}
Css is just brought in via application.scss as normal.

LARAVEL DOMPDF Wrapper for Laravel 5

I performed the following steps and have an error
step 1
Insert en composer.json
"barryvdh/laravel-dompdf": "0.6.*"
step 2
install
php composer update
step 3
add config/app.php
'providers' => [....
Barryvdh\DomPDF\ServiceProvider::class,
'aliases' => [....
'PDF' => Barryvdh\DomPDF\Facade::class,
step 4
routes.php
Route::resource('pdf', 'PdfController');
step 5 create controller from php artisan make:controller PhpController
insert code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PdfController extends Controller
{
public function Index() {
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
}}
step 5 ERROR
call url localhost/public/pdf
FatalThrowableError in PdfController.php line 16:
Fatal error: Class 'App\Http\Controllers\App' not found
line 22 ....
$pdf = App::make('dompdf.wrapper');
Thank you! for your comments.
You'll have to use the App Facade
use Illuminate\Support\Facades\App;
Try to use this code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App;
You forgot to prefix the App namespace with \. The correct way to call that function would be as follows:
$pdf = \App::make('dompdf.wrapper');

Zend framework 2: class_exists('mPDF') returns true yet new mPDF() fails

I want to use mPDF in a controller as follows (test scenario):
function indexAction() {
require_once('libraries/mpdf/mpdf.php');
var_dump(class_exists('mPDF')); //prints true
$mpdf = new mPDF(); //fails with 'class not found in Application/Controller (current namespace)
}
The class mPDF is declared inside the mpdf.php file and i've checked if the file gets loaded and it does.
To solve this you have to add \ infront of the class name to reset namespace
function indexAction() {
require_once('libraries/mpdf/mpdf.php');
var_dump(class_exists('mPDF')); //prints true
$mpdf = new \mPDF(); //fails with 'class not found in Application/Controller (current namespace)
}
error message is the clue to this
//fails with 'class not found in Application/Controller (current namespace)
I however dont know why the class_exist returns true. It did not do that when i had my class in autoload_classmap.php but when i require_once i got the same problem.
also if you dont want to require_once the php file in the function you can add it to class mapp file at the root of the module
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'mPDF' => __DIR__ . 'path/to/file/mpdf.php',
);
I do this with PHPMailer

Vaadin 7 : How to import JS files from custom path?

I am using Vaadin-7 and this answer was not fix for me .
I am trying to import my js file under myproject/WebContent/js/test.js . I used #JavaScript in my UI class as below..
#Theme("myTheme")
#SuppressWarnings("serial")
#Title("VaadinTest")
#JavaScript("js/test.js")
public class VaadinTest extends UI {
#Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
}
}
But I got "NetworkError: 404 Not Found - http://localhost:8080/myproject/APP/PUBLISHED/js/test.js" error log in my firebug console.
So , how can I import js files from my custom directories ?
PS: Please don't be force me to create APP/PUBLISHED/ directory manually ! Thanks.
You can use app://:
#JavaScript({ "app://js/test.js" })
or use:
#JavaScript({ "vaadin://js/test.js" })
Generated url inside VAADIN folder:
http://localhost:8080/myproject/VAADIN/js/test.js
the file you refer to must be reachable by the classloader relative to the package you are using it in. according to your example, lets say your package of VaadinTest is com.example.app and you want to access it as js/test.js you have to put it in the directory com/example/app/js/test.js in a "root" for the classloader to find it (e.g. src/main/java,groovy or where resources are loaded from in your config).

How to use a Component with Admin Generator?

I know we can use components with the admin generator (thanks to ~ symbol).
However, in the components.class.php, how to call the auto-generated class ?
At this moment, I'm using this :
require_once dirname(__FILE__).'/../lib/commissionGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/commissionGeneratorHelper.class.php';
class commissionComponents extends autoCommissionComponents
{
}
But I obtain this error :
Fatal error: Class 'autoCommissionComponents' not found in /home/site/liguelorraine/apps/saSecureLigueLorraine/modules/commission/actions/components.class.php on line 7
There are no automatically generated component classes. Just extends sfComponents as usual.

Resources