HI,

i am new at this programming stuff. so, i really dont know much about programming especially when it come to converting pages to pdf. so, i need to understand one thing, this..fpdf,mpdf,wkhtmltopdf and others..do they convert php page..because they said "convert HTML to PDF"..so i am confuse..i did try using .php page but it cannot work, but when i try using my .html page it works. so..what is wrong with it??or may be i get the wrong concept of it or my codes are wrong??i cant seem to understand it..sorry to ask such question.. :/

please advise..

Dani AI

Generated

Brief answer for (and following on ): those libraries convert HTML — the rendered output your PHP script produces — not the raw .php source file. If your static .html worked but the .php “didn’t”, the converter was likely given a file that wasn’t executed by PHP. Convert a PHP page by either (A) calling its URL so the server runs the PHP and returns HTML, or (B) have PHP render the page to a string and pass that HTML to the PDF library. (mpdf.github.io)

Quick guide to the tools mentioned:

  • FPDF: a PHP class to build PDFs programmatically (you call methods to place text, images, pages). Good for simple, data-driven PDFs. (fpdf.org)
  • mPDF / dompdf: PHP libraries that accept HTML/CSS (as a string) and render it to PDF. Use these when you want to write a template in HTML. (github.com)
  • wkhtmltopdf: a command-line tool that renders a full page with a WebKit engine; it can take an HTTP URL or an HTML file and produces a very faithful PDF (better for complex CSS). (wkhtmltopdf.org)

Practical pattern (common, reliable):

<?php
// capture the HTML output of a PHP template
ob_start();
include 'invoice_template.php'; // this runs PHP and echoes HTML
$html = ob_get_clean();

// feed HTML to a library (example: mPDF)
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output('invoice.pdf','D');
?>

The PHP output-buffering approach above is standard; see PHP's ob_start()/ob_get_clean() docs and mPDF's WriteHTML usage. (php.net)

Troubleshooting tips: use absolute URLs for CSS/images or enable remote fetching (dompdf requires isRemoteEnabled for remote resources). If images/CSS don’t appear, that’s usually the cause. For pixel-perfect rendering use wkhtmltopdf or headless Chrome; for simple templates use mPDF/dompdf. Watch server limits (mPDF notes some caveats fetching external resources on simple PHP servers). (github.com)

Recommended Answers

All 4 Replies

Member Avatar for Member #949455

i need to understand one thing, this..fpdf,mpdf,wkhtmltopdf and others..do they convert php page..

You don't convert php files you can create a php by texteditor or notepad.

convert HTML to PDF.

It means that you it's has to have a html file and convert it to PDF:

For example you convert this webpage called pdf.html and you convert it to pdf.pdf

This is a link about converting html to pdf

http://pdfcrowd.com/

or this:

http://www.html-to-pdf.net/free-online-pdf-converter.aspx

Portable Document Format (PDF) files are adobe files

It's this:

http://www.adobe.com/products/acrobat.html?promoid=JOPBV

To open a pdf file you need to download this:

http://get.adobe.com/reader/

Thank you so much..i appriciate it..
But i dont think i still fully understand it..sorry i am a bit slow..

but my page needs to be in php where as i need to output my data from database to the web page and into pdf..if i use html..how do i call my outputs??..i did find codes like : $html='//inside here=should be php code is it??from start to end'..and you save it as .html...does it work like that??i really need some help..i dont understand it..

Member Avatar for Member #949455

but my page needs to be in php where as i need to output my data from database to the web page and into pdf..if i use html..how do i call my outputs??..i did find codes like : $html='//inside here=should be php code is it??from start to end'..and you save it as .html...does it work like that??i really need some help..i dont understand it..

I think you are confused about converting files. PHP files can't be converted, you need to write out the code. Regardin about the database you also need a mysql query to get the data from the database. There's no software that can convert or write php & mysql codes.

I feel you need to touch up on these 2 subject which is php and mysql.

Here is couple of links that you can take a look and understand what I just mention:

This is php:

http://www.w3schools.com/php/default.asp

http://www.tizag.com/phpT/

and this mysql:

http://www.w3schools.com/sql/default.asp

http://www.tizag.com/mysqlTutorial/

Once you figure out the code then you can fetch the data from the database.

commented: To Rectify what some retard did to LastMitch +0

thank you so much.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.