Laravel FPDI Package but Output Method is undefined - php

currently figured out how to implement the FPDI Class from https://manuals.setasign.com/fpdi-manual/v2/ into my laravel project.
Now I think I can execute some of the method, but currently getting undefined method for the most important one:
$pdf2 = new Fpdi();
$path2 = public_path() . '/storage/Template/testpdf3.pdf';
$pdf2->setSourceFile($path2);
$tplIdx = $pdf2->importPage(1);
$pdf2->useTemplate($tplIdx, 10, 10, 100);
$pdf2->Output(); -> this one getting undefined Method.
The other method are all okay. Do you have any Idea? Thanks!

Thanks Which plugin are you using on vscode? Also, can you install laravel-ide-helper (github.com/barryvdh/laravel-ide-helper) and running php artisan ide-helper:generate

Related

run File_PDF on php 8 (upgrade to Horde_Pdf)

I use the pear extension File_PDF in an old PHP app I maintain.
It seems like the last version by that module is version 0.3.3 from and it is not maintained anymore and has been superseded by the package Horde_Pdf from pear.horde.org.
Can I just change the codebase to the new package? Or do I need to change the function calls?
I started a repository where I convert the old code to the new code at https://github.com/rubo77/File_PDF
The old PDF.php was renamed to Writer.php and the fonts are now in another folder. and the class File_PDF was renamed to class Horde_Pdf_Writer.
I replaced the code in my scripts:
and changed
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
to
require_once('vendors/pear/Horde_Pdf_Writer/Writer.php');
$this->pdf = new Horde_Pdf_Writer();
now I get the error
Uncaught Error: Class 'Horde_String' not found in /var/www/app/vendors/pear/Horde_Pdf_Writer/Writer.php
A better solution would be to use a more actively maintained PDF generation library like TCPDF, which doesn't need much changes either, e.g. from file_PDF to TCPDF just:
replace newLine() with Ln()
replace getOutput() with Output()
SetFont('Arial', ... doesn't work, so just use SetFont('', ...
If you really need this old Library you need to also download those packages:
Horde_Exception
Horde_Util
Horde_Translation
To let it run in a local folder, edit some files:
instead of calling File_PDF with
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
now call
require_once('vendors/pear/Horde/Pdf/Writer.php');
require_once('vendors/pear/Horde/Pdf/Exception.php');
require_once('vendors/pear/Horde/String.php');
$this->pdf = new Horde_Pdf_Writer();
in Writer.php the function _getFontFile() needs these extra lines:
$fontname = Horde_String::ucfirst(Horde_String::lower($fontkey));
require_once('vendors/pear/Horde/Pdf/Font/'.$fontname.'.php');
$fontClass = 'Horde_Pdf_Font_' . $fontname;
in Exception.php you need to call
require_once('vendors/pear/Horde/Exception/Wrapped.php');
in Wrapped.php you need
require_once('vendors/pear/Horde/Exception.php');

Cannot declare class FPDF, because the name is already in use (Wordpress custom plugin)

I’m new to the forum and I have a problem that is probably super easy to resolve for someone with a little skills in WP developing :-).
I want to create a plugin that creates PDFs. I’m using FPDF since I have been using it before and I think it works great.
My problem is when I try to require the fpdf class I get the error:
Fatal error: Cannot declare class FPDF, because the name is already in use in /wp-content/plugins/tage-test/fpdf181/fpdf.php on line 12
Below is a simplified version where I just try to create a PDF file. If anyone could please help me or point me in the right direction I would really appreciate it!
add_shortcode(‘create_invoice’, ‘marathon_form’);
require_once(‘fpdf181/fpdf.php’);
function marathon_form(){
$pdf = new FPDF();
$pdf->SetDisplayMode(‘fullpage’);
$pdf->SetMargins(0, 15);
$pdf->AddFont(‘VerlagBook’,”,’HBGMv-Book.php’);
$pdf->AddFont(‘VerlagBold’,’B’,’HBGMv-Bold.php’);
$pdf->AddPage(‘P’, ‘A4’);
$pdf->SetFont(‘VerlagBold’,’B’,15);
$pdf->Cell(185,5,’Invoice’,0,1,’R’);
$outputName = ‘invoice.pdf’;
$pdf->Output($outputName, ‘F’);
}

dompdf not work in zend framework 2

I get this error, when using Zend Framework v2.4: Call to undefined method Zend\Mvc\View\Http\ViewManager::getResolver() in /../../../demo/vendor/dino/dompdf-module/src/DOMPDFModule/Mvc/Service/ViewPdfRendererFactory.php on line 39 But there is no getResolver method in viewmanager. I am using zend framework 2.4/
Can you help me to solve this?
This is included in vender.
<?php
use DOMPDFModule\View\Model\PdfModel;
This is controller action
public function generatepdfAction(){
// $pdf1 = new Zendpdf\PdfDocument();
echo "bbb";
$pdf = new PdfModel();
$pdf->setOption('filename', 'monthly-report'); // Triggers PDF download, automatically appends ".pdf"
$pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
$pdf->setOption('paperOrientation', 'landscape'); // Defaults to "portrait"
// To set view variables
$pdf->setVariables(array(
'message' => 'Hello'
));
return $pdf;
}
It's not a error in your code. This is a known issue as you can see on https://github.com/raykolbe/DOMPDFModule/issues/37
There is also a pull request for that issue. I solved this with creating my own DOMPDFModule with the changes of this commit, because it seems that there won't be an update of DOMPDFModule soon.
Another possibility would be using an older version of zend-mvc, because the issue appears since zend-mvc 2.7. Just use
"zendframework/zend-mvc": "~2.6.3"
in your composer.json and the the DOMPDFModule will work again. But this should be only a temporarily solution if you want to use new features of the Zend Framework and its modules in the future.

Integrating HTML2PDF in laravel 5.1

I am trying to integrate html2pdf library in laravel 5.1. But it is showing error like as follows Class 'App\Http\Controllers\HTML2PDF' not found
and my controller code is as follows
require_once(dirname(__FILE__).'/libs/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($html22);
my folder path is app/Http/Controllers/libs/html2pdf/html2pdf.class.php
i had given the correct path but still it is showing error like HTML2PDF not found. Please anyone let me know how to integrate html2pdf ? or should i do any changes in compose.json file ?
and even i included the line App\Http\Controllers\HTML2PDF at the top of the Controller page but no use.
please help me out .
Thanks
I just downloaded the latest and it would seem there is no namespace.
Remove the use App\Http\Controllers\HTML2PDF and try instantiating html2pdf like $html2pdf = new \HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));
You can use this Package: https://packagist.org/packages/ensepar/html2pdf
add this to your composer.json
"ensepar/html2pdf": "4.0.6"
and run composer update
after that, you can use it in your controller like so
// add this to the beginning of your controller under the namespace declaration
use HTML2PDF;
// after that, you can use the class like so
$html2pdf = new HTML2PDF('P','A4','de',false,'UTF-8');
$doc = "<page><h1>Hello World</h1></page>";
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($doc,false);
$html2pdf->Output(base_path().'/storage/app/helloworld.pdf','F');

Laravel 5 add nusoap

I am unable to install nusoap to my existing laravel 5 application. Ive done the following:
Created a new Folder in App/Http/Controllers/ - namend "Soap" - and copied the libary into it.
use
composer dump-autoload
So i am able to use
use nusoap_client;
But i am always getting an error:
Class 'App\Http\Controllers\nusoap_client' not found
I thought that laravel automatically load all classes from the "app" directory, but how can i use it here?
Tried with:
$wsdl = "test.xx/_vti_bin/lists.asmx?wsdl";
$client = new nusoap_client($wsdl, true);
Thanks for any help!
Just add these lines to your controller:
include 'nusoap.php';
use nusoap_client;
As a simple way, you can add a backslash in front of nusoap_client, like this:
$client = new \nusoap_client($wsdl, true);

Categories