Solved

I need to save, from a query in JSP, to PDF format

Posted on 2003-11-18
4
194 Views
Last Modified: 2010-04-17
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'?>"+cLf);

try {
Driver Driverrs = (Driver)Class.forName(MM_BD_DRIVER).newInstance();
Connection Connrs = DriverManager.getConnection(MM_BD_STRING,MM_BD_USERNAME,MM_BD_PASSWORD);
PreparedStatement Statementrs = Connrs.prepareStatement("SELECT 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_cliente.idcliente) ON status.idstatus=msg_cliente.idstatus) ON tipo_msg.idtipo_msg=msg_cliente.idtipo_msg) ON ingenieros.iding=msg_cliente.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_cliente") +"</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()%></exception>
<%outfile.close();}%>

Thank you !!
0
Comment
Question by:tutoreduardo
4 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
Comment Utility
Have a look here:

http://www.lowagie.com/iText/
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
parentbit challenge 3 50
mapShare challenge 13 66
python sqlite question 11 42
Help to convert powershell script into a gui 9 66
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now