convert my report (html5 page + php) to PDF.

Hi!

Have made a html5 (php) page that display a report.

Need to make this report in PDF

Is there some great PDF-librarys out there ?
LVL 2
team2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
If you know PHP scripting , you can use dompdf library. ref. https://code.google.com/p/dompdf/

I have used in my project for generating reports in the past. It worked great than tcppdf
0
Ray PaseurCommented:
Using PHP and PDF extensions, these are good resources.
http://www.tcpdf.org/
http://www.fpdf.org/

Please learn about those and then tell us what additional assistance you might need.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
team2005Author Commented:
Hi!

This is not easy to know what to use here.

Have made a report system in html5 (mysql)

My question is :

Must be able to convert my html5+css3 to PDF.
And to use MYSQL
Like this code:

        <table width="100%" align="left" class="testtabell"> 
		<tr>
		  <th class="rapport2_header" height="40px" align="left">Kontroller</th>
		  <th class="rapport2_header" height="40px" align="left">Lokasjon</th>
		  <th class="rapport2_header" height="40px" align="left">Dato</th>
		  <th class="rapport2_header" height="40px" align="left">Spørsmål</th>
		  <th class="rapport2_header" height="40px" align="left">Svar</th>
		  
		  </tr>
		<?php }?>
		
         <tr>
		                                                 
	      <td class="rapport1_del8" bgcolor="#ccc" align="left"> <?php echo $kontrollernavn; ?></td> 
	      <td class="rapport1_del8" bgcolor="#ccc" align="left"><?php echo $lokasjonnr; ?></td>
		  <td class="rapport1_del8"  bgcolor="#ccc" align="left"><?php echo $transdato; ?></td>
		  <td class="rapport1_del8"  bgcolor="#ccc" align="left"><?php echo $sporsmal; ?></td>
</table>

Open in new window



Realy happy if there are some good examples using Converter -> html5 to PDF
using HTML5 + mysql + css3
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Ray PaseurCommented:
The Google search for terms like "convert my html5+css3 to PDF" turns up nothing that I would bet my enterprise application on!  The reason for this is pretty simple.

HTML is a semantic markup language.  It is meant to give the meaning to data elements, but it has nothing to do with layout (at least not in this millennium) which is now handled with CSS.  I'm sure you can find old web pages where tables were used to force layout, etc., but that's ancient history by now.

PDF is a document layout language.  It is meant to position data on the printed page, in much the same way that CSS is used to define layout within the browser viewport.

Semantics and layout are not quite as different as fish and bicycles, but that's close.  It explains in part why browser / mobile layouts are fluid and adaptive, whereas print layouts are precise to the millimeter within rigidly defined page areas.  Browser output and print output are just not the same thing.  So rather than trying to find a fish that can ride a bicycle, consider using the popular and mainstream tools.

Using PHP and PDF extensions, these are good resources.
http://www.tcpdf.org/
http://www.fpdf.org/
0
team2005Author Commented:
Hi!

Okey, so its not possible to use CSS and table and Mysql to make my PDF ?

My customer want me to make the same styling of tables like my code described abow..
0
Ray PaseurCommented:
Sometimes customers want a pink unicorn.  Because they're not knowledgeable about the details of semantics and layout, they look at the screen and think, "give me that in print."  It's a reasonable line of thinking, and it would seem to be easy, but if you think about it for a moment you'll realize that we are using different devices (screens and printers) to render the output. Different devices means different programming.  Different programming means another abstraction layer, another set of development and testing, and all of the cost and complexity that comes with it.  

If all the client needs is a one-shot screen capture, you might do this with "print screen" and Photoshop.

You might also consider using CSS for media=print.  It will be less precise than PDF conversion but it might work for "quick and dirty" solutions.

If you want professional quality printed documents, the industry standard is PDF.
0
team2005Author Commented:
Hi!

So its not possible to use Mysql and styled tables ?
0
Ray PaseurCommented:
MySQL has nothing to do with it.  The issue is in the presentation layer where the output data is formatted for web or print.  HTML is used for web.  PDF is used for print.  You might experiment with CSS media=print and see if that offers a satisfactory shortcut.  It will take longer to get the document right with PDF (trust me, I've been there) but the results will be very fast and highly accurate.
0
team2005Author Commented:
Hi!

Found a very god html to PDF converter

Its called MPDF -> http://www.mpdf1.com/mpdf/index.php

Have setup a test for this, but have problem to use PHP variabel
lock at this code, this is building a html string to be renderd to PDF

$test1="ssss";

$html = '
<html>
<head>
<style>
table.testtabell
{
    border:1px solid #cccccc;
	border-collapse: collapse;
	font-family: Verdana;
	font-size: 20px;
	margin-right: 15px;
}
.rapport2_header
{
    background-color: #efefef;
    border:1px solid #cccccc;
	color:#cccccc;
	font-size: 15px;
	font-family: Verdana;
	border-collapse: collapse;
    box-shadow: none ! important;
	padding-left:10px;
}
.rapport1_del8
{
   background-color: #ffffff;
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   font-size:12px;
   color:#b2b3c3;
}
</style>

</head>

<body>
';
$html .= '<table width="100%" align="left" class="testtabell">'; 
$html .= '<tr>';
$html .= '<th class="rapport2_header" height="40px" align="left">';
$html .= $html + echo $test1;
$html .='</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Lokasjon</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Dato</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Spørsmål</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Svar</th>';
		  
$html .= '</tr>';
		
		
$html .= '<tr>';
		                                                 
$html .= '<td class="rapport1_del8" bgcolor="#ccc" align="left">Test 1</td>'; 
$html .= '<td class="rapport1_del8" bgcolor="#ccc" align="left">Test 2</td>';
$html .= '<td class="rapport1_del8"  bgcolor="#ccc" align="left">Test 3</td>';
$html .= '<td class="rapport1_del8"  bgcolor="#ccc" align="left">Test 4</td>'; 
$html .= '<td class="rapport1_del9"  bgcolor="#ccc" align="left">Test 5<img src="images/jasvar.png" alt="Smiley face" align="right"></td>';
		    
		  
$html .= '</tr>';		 
		 
$html .= '<tr>';
		                                                 
$html .= '<td class="rapport1_del8" bgcolor="#ccc" align="left">Test 1</td>'; 
$html .= '<td class="rapport1_del8" bgcolor="#ccc" align="left">Test 2</td>';
$html .= '<td class="rapport1_del8"  bgcolor="#ccc" align="left">Test 3</td>';
$html .= '<td class="rapport1_del8"  bgcolor="#ccc" align="left">Test 4</td>';   
$html .= '<td class="rapport1_del9"  bgcolor="#ccc" align="left">Test 5<img src="images/jasvar.png" alt="Smiley face" align="right"></td>';
		    
		  
$html .= '</tr>';		 
$html .= '</table>';
$html .= '</body>';
$html .= '</html>';

Open in new window


The problem is on this line:
$html .= $html + echo $test1;

Have tryed many different ways, but no luck

How can i fix this ?
0
Ray PaseurCommented:
Yes, that would probably cause a PHP parse error.  I don't know exactly what you want there.   Why not remove that line and try it without the parse error?  You may also find that you want to use echo to send the HTML document to the browser.

Good luck with MPDF.  I don't know why you didn't want to use my suggestions of FPDF or TCPDF, but it's your application so you have to be responsible for the choices.  You might want to read the recent posts in the MPDF forum before you bet the ranch on MPDF.
0
team2005Author Commented:
Hi!

I dident use FPDF -> dident give me the css styling i wanted...
Same problem for TCDF

I find ou of my problem:

$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $kontrollernavn . '</td>';
0
team2005Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.