Solved

convert xhtml to pdf !

Posted on 2013-06-11
2
2,000 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to display get_the_terms within a function 3 38
phpmyadmin memory error 55 88
Which is best Image Resizing Web service 11 33
Jquery syntax 12 26
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 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