tutoreduardo
asked on
I need to save, from a query in JSP, to PDF format
I create the query successfully from JSP but I don't have a code that will create me a PDF file, I can create a bad formatted XML file with the java.io library and the createFile command (in which I cannot insert line breaks!). Could you help me with these 2 problems?
Here is the code that I have:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*" %>
<%@ include file="Connections/BD.jsp" %>
<%
// Identify a carriage return character for each output line
int iLf = 10;
char cLf = (char)iLf;
// Create a new empty binary file, which will content XML output
File outputFile = new File("test.pdf");
outputFile.createNewFile() ;
FileWriter outfile = new FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+c Lf);
try {
Driver Driverrs = (Driver)Class.forName(MM_B D_DRIVER). newInstanc e();
Connection Connrs = DriverManager.getConnectio n(MM_BD_ST RING,MM_BD _USERNAME, MM_BD_PASS WORD);
PreparedStatement Statementrs = Connrs.prepareStatement("S ELECT msg_cliente.idmsg_cliente, cliente.nempresa, cliente.contacto, status.descripcion, tipo_msg.descripcion, ingenieros.nombre, msg_cliente.problema FROM ingenieros INNER JOIN (tipo_msg INNER JOIN (status INNER JOIN (cliente INNER JOIN msg_cliente ON cliente.idcliente=msg_clie nte.idclie nte) ON status.idstatus=msg_client e.idstatus ) ON tipo_msg.idtipo_msg=msg_cl iente.idti po_msg) ON ingenieros.iding=msg_clien te.iding") ;
ResultSet rs = Statementrs.executeQuery() ;
// Expecting at least one record
if( !rs.next() ) {
throw new IllegalArgumentException(" No se encontraron datos"); }
outfile.write("<Documento> "+cLf);
// Parse our recordset
while(rs.next()) {
outfile.write("<Reporte>"+ cLf);
outfile.write("<ID>" + rs.getString("idmsg_client e") +"</ID>"+cLf);
outfile.write("</Reporte>" +cLf);
}
outfile.write("</Documento >"+cLf);
%>
<html>
<head><title>Convertir a XML</title></head>
Archivo convertido.
</html>
<%
rs.close();
Statementrs.close();
Connrs.close();
outfile.close();
}
catch( Exception er ){
%>
<exception><%= er.getMessage()%></excepti on>
<%outfile.close();}%>
Thank you !!
Here is the code that I have:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*" %>
<%@ include file="Connections/BD.jsp" %>
<%
// Identify a carriage return character for each output line
int iLf = 10;
char cLf = (char)iLf;
// Create a new empty binary file, which will content XML output
File outputFile = new File("test.pdf");
outputFile.createNewFile()
FileWriter outfile = new FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+c
try {
Driver Driverrs = (Driver)Class.forName(MM_B
Connection Connrs = DriverManager.getConnectio
PreparedStatement Statementrs = Connrs.prepareStatement("S
ResultSet rs = Statementrs.executeQuery()
// Expecting at least one record
if( !rs.next() ) {
throw new IllegalArgumentException("
outfile.write("<Documento>
// Parse our recordset
while(rs.next()) {
outfile.write("<Reporte>"+
outfile.write("<ID>" + rs.getString("idmsg_client
outfile.write("</Reporte>"
}
outfile.write("</Documento
%>
<html>
<head><title>Convertir a XML</title></head>
Archivo convertido.
</html>
<%
rs.close();
Statementrs.close();
Connrs.close();
outfile.close();
}
catch( Exception er ){
%>
<exception><%= er.getMessage()%></excepti
<%outfile.close();}%>
Thank you !!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.