I have a PHP program and i would like to add fucntion to create a PDF file of my invoice page so that user can download their invoice. I did google search and found some extension. However, they can's read CSS and very hard to create any format. If you used any program that work with CSS, please let me know. Thx in advance
CSS is client side. You need to create the pdf document server side and output it to the browser as a pdf document. http://www.fpdf.org/ is the best way to do this on an apache server. Its free as well.
Yes, as Mad4 says I think you're talking about two different things there. If you are generating an HTML invoice that completely uses CSS, you can generate a separate CSS file for printing so the browser will automatically format it correctly for the page. A good tutorial for that can be found here: http://www.alistapart.com/articles/goingtoprint/ Alternatively you can use server-side software to generate a PDF file, which is then downloadable by the client. I use html2pdf for my invoicing - it works very well and reads in HTML/CSS pages (is that what you meant?) for conversion to PDF. It can be found here: http://html2pdf.seven49.net/
Thx Mad4, you are always helpful i tried http://www.fpdf.org/ but it doesn't work with CSS let me try html2pdf Xig, may be the worst i have to go back to HTML...
Its not supposed to work with CSS. Trying to use CSS in a pdf document is like using javascript in a Word document. CSS is a language for use in your internet browser rather than Adobe Acrobat Reader. If you are creating the invoice using php then you need to use fpdf to generate the output as a pdf document rather than a html document.
*laughs* Good analogy ... AFAIK the html2pdf software parses HTML and CSS to create a PDF document. It's only using HTML and CSS to read in formatting, layout, colours etc and then it generates the PDF document from scratch. I guess its an HTML/CSS -> PDF converter. Or did I misunderstand your post?
http://www.fpdf.org/ is a sound extension just extend the class to include the css properties that you want, i say css properites in the basics term meaning setting a basic formatted layout. The just add the invoice data on top.
I know I'm joining this thread late, and to add to that, I'm a complete doofus with coding ... but I have to learn this, so my question is ... What can I use to lay out and plan a page for conversion to PDF with the use of fpdf? How do I figure out what goes where and send that to fpdf? Thanks in advance. Kirk Ward
I would like to use this method to print out an ebook with the email of the buyer on it. Is that possible? It would be good to avoid people selling the book on the internet or giving it away.
I'm having some problems with the FPDF class. I'm hoping you can help me. I'm using FPDF to write some text on a PDF. I'm displaying 8 different cells of text. The Cells are being displayed, but after two cells, it puts the next cell onto a new page as If I had asked for a new PDF page to be made, but I did not. I'm guessing it is somehow pushing them down and pushing it onto the next page. How can I get rid of these annoying spaces and make it all fit on only the one PDF page? Here's the code: <?php // Get required files. require 'fpdf/fpdf.php'; // Set some document variables $author = "Me McMe"; $company_name = "APPLIED MATERIALS"; $name = "Liang Y. Chen, Ph.D."; $title = "Corporate Vice President & General Manager"; $title_2 = "Alternative Energy Products Group"; $dept_div = "Energy & Environmental Solutions"; $phone = "T 408.563.6330"; $fax = "F 408.235.6989"; $email = "Liang_Chen@amat.com"; $address2 = '3535 Garrett Drive, M/S 10071fdsfsdf'; // Create fpdf object $pdf = new FPDF('L', 'mm', array(51,87)); //fpdf(orientation(L for Landscape), unit of measurement(mm for millimeters), // Add a new page to the document $pdf->addPage('L', array(51,87)); $pdf->SetDisplayMode(real,'two'); $pdf->SetFont('Arial','B',5); $pdf->SetTextColor(0,0,0); $pdf->SetXY(0, 0); $pdf->SetMargins(0,0,0); $pdf->Cell(0,11, "$company_name", '1', 2, 'L', false); $pdf->Cell(0,11, "$name", '1', 2, 'L', false); $pdf->Cell(0,11, "$title", '1', 2, 'L', false); $pdf->Cell(0,11, "$title_2", '1', 2, 'L', false); $pdf->Cell(0,11, "$dept_div", '1', 2, 'L', false); $pdf->Cell(0,11, "$phone", '1', 2, 'L', false); $pdf->Cell(0,11, "$fax", '1', 2, 'L', false); $pdf->Cell(0,11, "$email", '1', 2, 'L', false); $pdf->Cell(0,11, "$address2", '1', 2, 'L', false); $pdf->Image('amatlogo.gif', 0, 0, 23.28, 21.52, 'GIF'); $pdf->Output('simple.pdf','I'); ?> Code (markup): You can view the outputted pdf here: http://idea-palette.com/pdf/
I haven't tried, but it looks great: http://www.tcpdf.org/examples.php (example 61, XHTML + CSS) I have worked with fpdf. Here is example: http://demo.dalibor-sojic.info/_testpdf/test.php (fill in first 3 fields) and submit the form. Here is t.php: <?php require_once('fpdf16/fpdf.php'); require_once('fpdi/fpdi.php'); require_once('fields.php'); // field properties $pdf =& new FPDI(); $pagecount = $pdf->setSourceFile('template.pdf'); $tplidx = $pdf->importPage(1); $pdf->SetTitle('Test pdf'); $pdf->SetAuthor("Me"); $pdf->SetSubject("Light Savings"); $pdf->addPage(); $pdf->useTemplate($tplidx, 0, 0); $pdf->SetFont('Courier', 'B', 10); // Show Data $pdf->SetXY(150, 10); $pdf->Cell(35, 5, date('m/d/Y'), 0, 0, 'R'); foreach($fields as $field=>$position) { $pdf->SetXY($position['x'], $position['y']); $pdf->Cell($position['width'], 4, $_POST[$field], 0, 0, $position['aligment']); } $pdf->Output('result.pdf', 'I'); PHP:
Mpdf is the best one and much better than tcpdf or fpdf in terms of parsing html+css. Check out this tutorial for creating invoices : http://www.binarytides.com/blog/create-pdf-documents-from-html-using-mpdf-in-php/