Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/12/2009, 14:30
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Pasar HTML a PDF, no me conserva el CSS

Buenas,

Me gustaría pasar el código de una web a PDF, pero conservando su estilo. Lo se hacer sin conservar su estilo CSS, por eso quiero perfeccionarlo.
¿Sabéis como conseguir para que respete el CSS? lo he probado metiendo en el misma web el CSS pero no hace caso.

Utilizo la librería HTML2PDF
http://sourceforge.net/projects/html2fpdf/


HTML
Código html:
Ver original
  1. <title>Panel</title>
  2. table, th, td {
  3.     border: 1px solid #D4E0EE;
  4.     border-collapse: collapse;
  5.     font-family: "Trebuchet MS", Arial, sans-serif;
  6.     color: #555;
  7. }
  8.  
  9. h2 {
  10.     font-family: "Trebuchet MS", Arial, sans-serif;
  11.     color: #555;
  12. }
  13.  
  14. caption {
  15.     font-size: 150%;
  16.     font-weight: bold;
  17.     margin: 5px;
  18. }
  19.  
  20. td, th {
  21.     padding: 7px;
  22. }
  23.  
  24. thead th {
  25.     text-align: center;
  26.     background: #E6EDF5;
  27.     color: #4F76A3;
  28.     font-size: 100% !important;
  29. }
  30.  
  31. tbody th {
  32.     font-weight: bold;
  33. }
  34.  
  35. tbody tr { background: #FCFDFE; }
  36.  
  37. tbody tr.odd { background: #F7F9FC; }
  38.  
  39. table a:link {
  40.     color: #718ABE;
  41.     text-decoration: none;
  42. }
  43.  
  44. table a:visited {
  45.     color: #718ABE;
  46.     text-decoration: none;
  47. }
  48.  
  49. table a:hover {
  50.     color: #718ABE;
  51.     text-decoration: underline !important;
  52. }
  53.  
  54. tfoot th, tfoot td {
  55.     font-size: 85%;
  56. }
  57. </head>
  58.  
  59. <body bgcolor="FFFFFF">
  60. <h2>Tareas</h2>
  61.  
  62.     <th>Nombre</th>
  63.     <th>Estatado</th>
  64.     <th>Inicio</th>
  65.     <th>Final</th>
  66. <tr>
  67.     <td>SERVER1</td>
  68.     <td>False</td>
  69.     <td>04/12/2009 16:50:02</td>
  70.     <td>04/12/2009 16:50:05</td>
  71. </tr>
  72. <tr>
  73.     <td>SERVER2</td>
  74.     <td>False</td>
  75.     <td>04/12/2009 16:50:02</td>
  76.     <td>04/12/2009 16:50:05</td>
  77. </tr>
  78. <tr>
  79.     <td>SERVER3</td>
  80.     <td>False</td>
  81.     <td>04/12/2009 16:50:02</td>
  82.     <td>04/12/2009 16:50:05</td>
  83. </tr>
  84. <tr>
  85.     <td>SERVER4</td>
  86.     <td>False</td>
  87.     <td>04/12/2009 16:50:02</td>
  88.     <td>04/12/2009 16:50:05</td>
  89. </tr>
  90.  
  91.  
  92. </body>
  93. </html>

SCRIPT
Código PHP:
Ver original
  1. <?
  2. require('html2fpdf.php');
  3. $pdf=new HTML2FPDF();
  4. $pdf->AddPage();
  5. $fp = fopen("web.html","r");
  6. $strContent = fread($fp, filesize("web.html"));
  7. fclose($fp);
  8. $pdf->WriteHTML($strContent);
  9. $pdf->Output("sample.pdf");
  10. echo "PDF file is generated successfully!";
  11. ?>

Gracias de antemano!