Integrating HTML2PDF in laravel 5.1 - php

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');

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');

How to fix 'Missing argument 1 for Pdf_label::__construct()' when using fpdf label script in codeigniter

Im getting error :
Message: Missing argument 1 for Pdf_label::__construct(), called in
C:\xampp\htdocs\project1b\system\core\Loader.php on line 1285 and
defined
Filename: libraries/PDF_Label.php
what I'm trying to do is, I tried to using fpdf label script (Documentation Here) in codeigniter, I already tried a simple pdf generate in codeigniter using this code :
public function cetakLabelfpdf()
{
$this->load->library('fpdf');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, 'Hello World!');
$pdf->Output();
}
and it worked, but when I tried to add script (in this case label script) I put the label script in the same directory like fpdf file does (application/libraries) and generate pdf using this example code
public function cetakLabelfpdf()
{
$this->load->library('PDF_Label');
// Standard format
$pdf = new PDF_Label('L7163');
$pdf->AddPage();
// Print labels
for ($i = 1; $i <= 20; $i++) {
$text = sprintf("%s\n%s\n%s\n%s %s, %s", "Laurent $i", 'Immeuble Toto', 'av. Fragonard', '06000', 'NICE', 'FRANCE');
$pdf->Add_Label($text);
}
$pdf->Output();
}
I'm getting like on the first message, I really appreciate it if someone can show what I did wrong on this case.
To add to my comment, essentially $this->load is meant to work with CodeIgniter compatible libraries/models/helpers .etc. When you have something completely unrelated to CodeIgniter (not built around its ecosystem) you can either create a library to "adapt" the class to be compatible with CodeIgniter or you can just use it like a regular class with either composer autoloading or requiring the necessary files at the top of the controller/model class that needs it (won't work for namespaced classes - you'd then need composer or something that can autoload).
In your specific case, when you called $this->load->library() on the label class, CI created a new label class (behind the scene) and didn't pass anything to its __construct where there is a required param. Hence the error. You can pass variables to a libraries constructor via $this->load->library('some_lib', ['arg1'=>'foo', 'arg2'=>'bar'] however that is only if the library is built for CI (receives all constructor arguments in an array rather than a comma separated parameter list).
See more here: https://www.codeigniter.com/user_guide/general/creating_libraries.html#passing-parameters-when-initializing-your-class

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.

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