Mostrando las entradas con la etiqueta PDF. Mostrar todas las entradas
Mostrando las entradas con la etiqueta PDF. Mostrar todas las entradas

lunes, 17 de junio de 2013

Crear un PDF con PeopleCode desde un HTML

Aquí les dejo un ejemplo de cómo crear un PDF en línea, con PeopleCode a partir de una plantilla HTML

Local JavaObject &Document = CreateJavaObject("com.lowagie.text.Document");
Local JavaObject &pdfWriter = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Document, CreateJavaObject("java.io.FileOutputStream", "/tmp/test.pdf", True));

&Document.open();

Local JavaObject &htmlWorker = CreateJavaObject("com.lowagie.text.html.simpleparser.HTMLWorker", &Document);

Local string &str;

&str = " <html> ";
&str = &str | " <head> ";
&str = &str | " <title></title> ";
&str = &str | " </head> ";
&str = &str | " <body> ";
&str = &str | " <p><b><font size='7'>Título</font></b></p> ";
&str = &str | " <p><b><font size='5'>Subtítulo</font></b></p> ";
&str = &str | " <p><b><font size='4'>Párrafo</font></b></p> ";
&str = &str | " <p>Texto de párrafo, texto de párrafo, texto de párrafo, texto de párrafo, texto  ";
&str = &str | " de párrafo, texto de párrafo, texto de párrafo, texto de párrafo, texto de  ";
&str = &str | " párrafo, texto de párrafo, texto de párrafo.</p> ";
&str = &str | " <table border='1' cellspacing='1' bgcolor='#FFFFCC' bordercolor='#0000FF' width='100%'> ";
&str = &str | " <tbody> ";
&str = &str | " <tr> ";
&str = &str | " <td width='10%'><b>Tabla</b></td> ";
&str = &str | " <td width='20%'><b>Head 1</b></td> ";
&str = &str | " <td width='50%'><b>Head 2</b></td> ";
&str = &str | " <td width='20%'><b>Head 3</b></td> ";
&str = &str | " </tr> ";
&str = &str | " <tr> ";
&str = &str | " <td width='10%'>&nbsp;</td> ";
&str = &str | " <td width='20%'>&nbsp;</td> ";
&str = &str | " <td width='50%'>&nbsp;</td> ";
&str = &str | " <td width='20%'>&nbsp;</td> ";
&str = &str | " </tr> ";
&str = &str | " </tbody> ";
&str = &str | " </table> ";
&str = &str | " <ul> ";
&str = &str | " <li>Elemnto 1</li> ";
&str = &str | " <li>Elemento 2</li> ";
&str = &str | " <li>Elemento 3</li> ";
&str = &str | " </ul> ";
&str = &str | " </body> ";
&str = &str | " </html> ";

Local JavaObject &SR = CreateJavaObject("java.io.StringReader", &str);

&htmlWorker.parse(&SR);

&Document.close();

&salida = PutAttachment(URL.MI_SITIO_FTP, "/midirectorio/test.pdf", "/tmp/test.pdf");

/* eliminamos el archivo en el AppSrv, del subdirectorio temporal */
Local JavaObject &f = CreateJavaObject("java.io.File", "/tmp/test.pdf");
&f.delete();

/* Muestra el archivo desde la ubicación de FTP */
&salida = ViewAttachment(URL.MI_SITIO_FTP, "/midirectorio/test.pdf", "test.pdf", True);

/* Eliminamos el archivo copiado después de haberlo mostrado*/
&salida = DeleteAttachment(URL.MI_SITIO_FTP, "/midirectorio/test.pdf");

NOTA:
Este tema esta relacionado con un tema previo que publiqué, con referencia al uso de las librerías iText.

Translate