Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.AppModel.Reportes; import java.io.FileOutputStream; import java.io.StringReader; import com.lowagie.text.Document; import com.lowagie.text.PageSize; import com.lowagie.text.html.simpleparser.HTMLWorker; import com.lowagie.text.pdf.PdfWriter; /** * * @author adrcoria */ public class GeneraPdf { public GeneraPdf() { } public void generarArchivoPdf(String xml) { try { Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("plantillaa.pdf")); document.open(); document.addAuthor("Persona creadora"); document.addCreator("Software generador"); document.addCreationDate(); document.addTitle("Titulo del documento"); HTMLWorker htmlWorker = new HTMLWorker(document); // String str = "<table>\n" // + " <tr>\n" // + " <td>Boleta</td>\n" // + " <td>Fecha</td>\n" // + " <th>Operacion</th>\n" // + " <td>Abono</td>\n" // + " <td>Interes generado </td>\n" // + " <td>Cargo</td>\n" // + " <td>Usuario que realizo el movimiento</td> \n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 15:53:37.0</td>\n" // + " <td align=center>Nuevo empeo</td>\n" // + " <td align=center></td>\n" // + " <td align=center></td>\n" // + " <td align=center>$533.00</td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 15:56:04.0</td>\n" // + " <td align=center>Extension de contrato</td>\n" // + " <td align=center></td><td align=center>$1.44</td>\n" // + " <td align=center></td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 16:00:51.0</td>\n" // + " <td align=center>Desempeo</td>\n" // + " <td align=center>$554.64 </td>\n" // + " <td align=center>$21.64 </td>\n" // + " <td align=center></td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005818</td>\n" // + " <td align=center>2015-04-19 16:37:24.0</td>\n" // + " <td align=center>Refrendo</td>\n" // + " <td align=center>$533.00 </td>\n" // + " <td align=center>$21.64 </td>\n" // + " <td align=center>$533.00 </td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td align=center><b>$1,087.64 pesos</b> </td>\n" // + " <td align=center><b>$44.72 pesos</b> </td>\n" // + " <td align=center><b>$1,066.00 pesos</b> </td>\n" // + " </tr>\n" // + " <tr style=height:50px;>\n" // + " <td align=right colspan=7> </td>\n" // + " <td align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n" // + " <td align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n" // + " </tr>\n" // + " </table>"; String str = "<table>\n" + " <tr>\n" + " <td>Boleta</td>\n" + " <td>Fecha</td>\n" + " <th>Operacion</th>\n" + " <td>Abono</td>\n" + " <td>Interes generado </td>\n" + " <td>Cargo</td>\n" + " <td>Usuario que realizo el movimiento</td> \n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 15:53:37.0</td>\n" + " <td align=center>Nuevo empeo</td>\n" + " <td align=center></td>\n" + " <td align=center></td>\n" + " <td align=center>$533.00</td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 15:56:04.0</td>\n" + " <td align=center>Extension de contrato</td>\n" + " <td align=center></td><td align=center>$1.44</td>\n" + " <td align=center></td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 16:00:51.0</td>\n" + " <td align=center>Desempeo</td>\n" + " <td align=center>$554.64 </td>\n" + " <td align=center>$21.64 </td>\n" + " <td align=center></td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005818</td>\n" + " <td align=center>2015-04-19 16:37:24.0</td>\n" + " <td align=center>Refrendo</td>\n" + " <td align=center>$533.00 </td>\n" + " <td align=center>$21.64 </td>\n" + " <td align=center>$533.00 </td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td></td>\n" + " <td></td>\n" + " <td></td>\n" + " <td align=center><b>$1,087.64 pesos</b> </td>\n" + " <td align=center><b>$44.72 pesos</b> </td>\n" + " <td align=center><b>$1,066.00 pesos</b> </td>\n" + " </tr>\n" + " <tr style=height:50px;>\n" + " <td align=right colspan=7> </td>\n" + " </tr><tr>\n" + " <td align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n" + " </tr><tr>\n" + " <td align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n" + " </tr>\n" + " </table>"; htmlWorker.parse(new StringReader(str)); document.close(); } catch (Exception e) { System.out.println("" + e.getMessage()); } } public static void main(String[] args) { new GeneraPdf().generarArchivoPdf(""); } }