![]() |
Generating a PHP and HTML page to PDF using mPDF - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Generating a PHP and HTML page to PDF using mPDF (/showthread.php?tid=58162) Pages:
1
2
|
Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]haris244808[/eluser] I have transfered all mPDF directory to Codeigniter helpers directory and i have created a helper page (pdfexport_helper.php) Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); i created a controller (pdf.php) where i am calling the page that should be generated to pdf Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); but it doesnt generate the page i want, instead it generates the very first page (login page). what am i missing here?? Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]TheFuzzy0ne[/eluser] First of all, you shouldn't need to make an HTTP request to get the profile information. You should be able to do that by querying your model, and using a view (the code you need should already be written in the show_profile() method of your Profile controller. By making that HTTP request, you are essentially doubling your server's load, because CodeIgniter is loaded twice in a single request. Your problem is caused by the fact your HTTP request doesn't send any cookies, and therefore is not logged into your Web site. Hope this helps. Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]haris244808[/eluser] [quote author="TheFuzzy0ne" date="1369162028"]First of all, you shouldn't need to make an HTTP request to get the profile information. You should be able to do that by querying your model, and using a view (the code you need should already be written in the show_profile() method of your Profile controller. By making that HTTP request, you are essentially doubling your server's load, because CodeIgniter is loaded twice in a single request. Your problem is caused by the fact your HTTP request doesn't send any cookies, and therefore is not logged into your Web site. Hope this helps.[/quote] Thnx for the fast reply. Can you make ur answer a little bit clear pls. here is a show_profile function: Code: function show_profile($user_id){ Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]TheFuzzy0ne[/eluser] Instead of: Code: public function pdf_report($user_id){ Do something like: Code: public function pdf_report($user_id){ Now you aren't making an extra HTTP request to get the profile markup (as you were with file_get_contents() ![]() Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]haris244808[/eluser] [quote author="TheFuzzy0ne" date="1369165564"]Instead of: Code: public function pdf_report($user_id){ Do something like: Code: public function pdf_report($user_id){ Now you aren't making an extra HTTP request to get the profile markup (as you were with file_get_contents()). Instead you're just loading a view and passing the output from that into create_pdf().[/quote] Yes i understood the logic and thank you very much for that. but i need to generate pdf when a href is clicked.. show_profile function is for loading the profile. With what u did, means that when the profile is loaded a pdf also will be generated... The show profile function sends to the profile where a href link for generating the pdf is included.. which will be the best solution in this case? Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-21-2013 [eluser]haris244808[/eluser] I did smth like this...however it prits me a blank page Code: public function pdf_report($user_id){ Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-22-2013 [eluser]TheFuzzy0ne[/eluser] No, what I did does NOT generate a PDF everytime the profile is viewed. It will generate a PDF when you go to http://yoursite.com/pdf/pdf_report/<user_id>, which is exactly what you're trying to do, is it not? You need to pass TRUE as the third parameter to $this->load->view() in order to return the contents. What you're doing will just send the view to the browser. Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-22-2013 [eluser]haris244808[/eluser] [quote author="TheFuzzy0ne" date="1369217732"]No, what I did does NOT generate a PDF everytime the profile is viewed. It will generate a PDF when you go to http://yoursite.com/pdf/pdf_report/<user_id>, which is exactly what you're trying to do, is it not? You need to pass TRUE as the third parameter to $this->load->view() in order to return the contents. What you're doing will just send the view to the browser.[/quote] Ok thnx for that.. and what if i want to create a costum PDF page...to generate one with info from db and costumize the html + css ? From where i should start? which will be the best method?? because when i generate the page it has some floating problems where it doesn not generate the page correctly as it is? Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-22-2013 [eluser]haris244808[/eluser] OK i started using FPDF and it works fine...however i have problem now with HTML tags... when i display conetent from MYSQL db (which holds content from Text Editor together with HTML tags)... id generates the PDF showing contetn together with HTML tags... How can i hide HTML tags when generating PDF. i tried strip_tags...htmlspecialchars()....dont work any suggesstion??? Generating a PHP and HTML page to PDF using mPDF - El Forum - 05-23-2013 [eluser]TheFuzzy0ne[/eluser] Whilst mPDF has been designed to specifically parse HTML and make it into a PDF, it doesn't support all HTML tags and CSS attributes. You need to design your HTML so it's as simple as possible, and try to avoid floating elements wherever possible. Instead, you can use absolute positioning, which should work much better. Also, your CSS should be inline CSS, meaning you should use the style attribute. Correct: Code: <body> Wrong: Code: <head> Using the code I posted, you should be able to apply that to get the results you want. It works just like loading a view in the sense that you pass the variables into the view, but the difference being that instead of outputting the view, you're passing the output into your create_pdf() function. Hope this helps. |