Una librería muy fácil de usar y con mucha info por todos lados es iText.
De acá la podes descargar:
http://sourceforge.net/projects/itext/
Acá tenes un ejemplo de como usarla:
http://www.ibm.com/developerworks/op...ry/os-javapdf/
Tambien podes hacerlo directamente sin libreria de esta forma:
Código Java:
Ver originalimport java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestPdfServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
private static final long serialVersionUID = 1L;
protected void doGet
(HttpServletRequest request, HttpServletResponse response
) throws ServletException,
IOException { performTask(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
performTask(request, response);
}
private void performTask(HttpServletRequest request, HttpServletResponse response) throws ServletException,
String pdfFileName
= "pdf-test.pdf"; String contextPath
= getServletContext
().
getRealPath(File.
separator); File pdfFile
= new File(contextPath
+ pdfFileName
);
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=" + pdfFileName);
response.setContentLength((int) pdfFile.length());
OutputStream responseOutputStream
= response.
getOutputStream(); int bytes;
while ((bytes = fileInputStream.read()) != -1) {
responseOutputStream.write(bytes);
}
}
}