![]() |
I am using CI 4.1.5, installed from composer. On fedora 35 x86_54.
Code: $ composer create-project codeigniter4/appstarter ci4-mpdf I installed mpdf from composer as well, the code I use in the invocation is: Code: $ composer require mpdf/mpdf PHP Code: <?php And I also modified it as follows: PHP Code: <?php and the error show this: Code: Error Checking the composer autoload file, I found that it does not include the mpdf installation path, I tried to regenerate it with composer dump-autoload and it still does not work. I tried to add it manually, and it doesn't work either. Is it necessary to modify some other composer path or add the mpdf installation manually? Thanks!
if what your trying to do is so surfers can download a pdf version of your web page , then i can tell you i have had success with : https://packagist.org/packages/tecnickcom/tcpdf
Now i installed that via entry in composer.json file but it didn't work Now in that particular case, the tcpdf.php main file had no namespace , so i had to load it in app/Config/Autoload.php using : Code: public $classmap = [ 'TCPDF'=>ROOTPATH.'tecnickcom/tcpdf/tcpdf.php' if mpdf files have a namespace then you can try running : Code: composer dump-autoload have a look inside class files to see if they have a namespace or not.
Thank you for your response.
I need mpdf or tcpdf, to generate sales reports, tickets, inventory, or reports cash dynamically.
11-19-2021, 11:03 AM
(This post was last modified: 11-19-2021, 11:04 AM by captain-sensible. Edit Reason: forgot something )
yeah i've got it working for blog postings - basically using output from database and links in view , whaterver blog is posted its possible to download a pdf of it.
i can't show you live since waiting for daughter to come up with one. I'll have a look maybe over week end at mpdf . if its not considered shameless promotion of my CMS by mods you can download : https://sourceforge.net/projects/codeigniter4cms/ unzip go into controllers Code: and look at ProducePDF.php in controllers. if you want the thing to run, go into route of unzip and run from cli (depending on how you have composer set up , better still if your on linux ) : composer install thats because to cut down on download i didn't upload vendor. that should give you a clue of basics how i did it (11-19-2021, 11:03 AM)captain-sensible Wrote: yeah i've got it working for blog postings - basically using output from database and links in view , whaterver blog is posted its possible to download a pdf of it. thanks, i try it.
II found the error:
On my local lo server, I found that a php library was missing for gd. And this was causing mpdf version 6.1.3 to be installed, the current version is 8.0.10, however composer was not installing it. So I installed the missing library, updated composer and everything worked perfectly, now I can use the mpdf library.
11-28-2021, 03:43 AM
(This post was last modified: 11-28-2021, 03:50 AM by captain-sensible. Edit Reason: spelling )
Recently i had trouble with html 2 pdf on the fly on my live server hosting. While getting help from web support, I had a play with Dompdf. I also had a quick look at mpdf and then back to the original library tcpdf.
if your requirement is just getting text from html then , mpdf ( https://packagist.org/packages/mpdf/mpdf ) is really easy. Composer should not be run as root, so that can pose some problems running composer from inside your web app on live server , i've found particularly if web app is a sub domain or directory within your main hosting. Maybe its my hosting ? A hack around running composer live, i've found, is simply to get things working on local dev , running composer on local dev, zipping up the whole vendor directory and then over writing the vendor directory on the live server. Its worked for me ! So on local dev say to get mpdf , from a linux command line ( you are using linux i hope ) cd to web root and run : Code: composer require mpdf/mpdf Doing that should put mpdf library in your CI vendor directory, and you should also see it updates your composer.json file eg : Code: "require": { Now the autoloader should take care of your CI app finding the library. The way I use it is on the html page for a blog, is to present a link which includes the slug of the blog title. So basically when someone clicks on a get page as pdf link , it goes to a route ,which then invokes a controller class and its method to do the work. IN my case the link( for a blog entry ) is in the form : Domain.com/linkPdf/slug This will invoke route : Code: $routes->get('linkPdf/(:segment)','ProducePDF::getPdf/$1'); The controller class is ProducePDF and the class method is : getPdf() Basically it will retrieve from the database the blog title, article and image name, Anyway, let me give a simple example of using mpdf in a controller. At the beginning of the controller : Code: use Dompdf\Dompdf; the above means use namespace called Dompdf and use the class also called Dompdf Now the basics of using mpdf in a controller are : Code: $mystring ="<h1> some html text </h1>"; How do you evoke controller in the first place. Well its easy if the html is stored in a database with say field for say title, main article , slug, image, then all you have to do is get the strings for the text , containing html then you can use a link on a view, which uses a route so that it goes t o a controller to do all the work Since my daughter has now got around to doing her first blog post , you can see html 2 pdf, being produced on the fly by clicking "cms in action " below my post then on menu blogs -> click on the single listing -> bottom of page -> pdf link. You should get a pdf file that has the blog image inserted. Now I played with mdpf to insert image and it was a bit of a pain conversion to base64 being needed, so i just used tcpdf instead. getting html2pdf is more complicated with tcpdf
I get every thing working on my local system using vhosts, then I upload ftping every thing to the root.
Only change I have to make is change public to public_html because my live server uses that. I change it on my local server ftp to root and it just runs right off. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |