Solved

convert xhtml to pdf !

Posted on 2013-06-11
2
1,877 Views
Last Modified: 2013-06-20
Hi Experts,

In my website i'm using html2pdf convertor of http://sourceforge.net/projects/html2fpdf/?source=dlp.

This is working good html tags  convert to pdf format.. but most inline css and styles elements not converting to pdf, so unable to got a absolute result and styles..
what is the problem? or xhtml not supporting convert of html2pdf format? Plz guide me.

Example css code :
<style type="text/css">
<!--
tr.form-tab-outer td
{
border-bottom: 1px solid #cccccc;
}
tr.form-tab-outer td tr td
{
border-bottom:0px;
}
-->
</style>

Open in new window


HMTL CODE
...
...
<tr class="form-tab-outer">
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><b>ORDER NO:</b> '.$row['order_no'].'</td>
        </tr>
      </table></td>
  </tr>
...
...

Open in new window

0
Comment
Question by:codeoxygen
2 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39237383
The central issue here is that HTML, and/or XHTML, are semantic markup languages.  They are meant to attach meaning to data elements, but they have nothing whatsoever to do with the positioning and appearance of these data elements.  That part of markup is handled via CSS.  Historically, many web developers have used HTML to position data (think tables) but that has been, and remains, a misuse of the markup language.  Unfortunately, there have been no strict standards in browser implementation of the rules, so the online world is full of polluted documents.

PDF is a document layout language.  It is for paper, meant to provide detailed positioning and appearance information for data elements on the printed page.

HTML and PDF are not quite as different as fish and bicycles, but they're almost that different since they're used for totally different things. If there is any similarity to be drawn between online layout and paper layout, it would be some kind of analogy between CSS and PDF.  But as far as I know, no such software exists today.

The only workable solution I have found is to use two separate presentation layers.  For online display, HTML and CSS makes sense.  For paper presentation, PDF makes sense.  This is why the Model-View-Controller design pattern is so valuable.  It allows you to separate the View and extend the View with the correct code set, depending on whether the script is expected to produce HTML or PDF.

FPDF and TCPDF are free and open-source classes that will build PDF documents for you.  Either one can probably do what you want.  Initial document layout is a meticulous and painstaking exercise, since these programs can position to 1mm.  But once the View is set up, they are both lightning fast and accurate.  Here is the Hello World exercise in FPDF.

<?php // RAY_fpdf_hello_world.php
error_reporting(E_ALL);


// DEMONSTRATE SOME OF THE BASICS OF FPDF


// SOME VARIABLES FOR OUR TESTS (COULD COME FROM DATA BASE, ETC)
$font = 'Arial';
$text = 'Hello World!';

// BRING IN THE PDF THING
require_once('fpdf16/fpdf.php');

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= DIRECTORY_SEPARATOR
. 'RAY_junk'
. DIRECTORY_SEPARATOR
. 'temp_pdf_blue'
. '.pdf'
;
$pdf_file_name
= getcwd()
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 16);
$pdf->SetFillColor(  0,   0, 255);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Blue PDF</a>';



// START OVER FOR A NEW PDF
unset($pdf);
echo PHP_EOL . "<br/>";

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= DIRECTORY_SEPARATOR
. 'RAY_junk'
. DIRECTORY_SEPARATOR
. 'temp_pdf_red'
. '.pdf'
;
$pdf_file_name
= getcwd()
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A RED BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 16);
$pdf->SetFillColor(255,   0,   0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Red PDF</a>';

Open in new window

Best of luck with your project, ~Ray
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 250 total points
ID: 39240384
There are several products ou there to help you in that. The most reliable one is prince, although the most costly one.

Then there is html2pdf, dompdf, wkhtmltopdf, etc.


Resources:
http://www.princexml.com/
http://www.tufat.com/s_html2ps_html2pdf.htm
https://code.google.com/p/dompdf/
http://www.dancrintea.ro/html-to-pdf/
https://code.google.com/p/wkhtmltopdf/
http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question