wood burning stoves
The moose likes Servlets and the fly likes write pdf files whith servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "write pdf files whith servlets " Watch "write pdf files whith servlets " New topic

write pdf files whith servlets

bruno martins

Joined: Oct 28, 2003
Posts: 8
hi, i can�t display my pdf file whith this code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.sql.*;
public class testepdf extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://sb/cmv?user=amd&&password=123";
String n1_ = "";

Connection con1;
Statement sta1;
String sql1 = "SELECT * FROM files";
PrintWriter out = response.getWriter();
try {
sta1 = con1.createStatement();
ResultSet rs = sta1.executeQuery(sql1);

"inline; filename=\"Acta.pdf\"");
Blob blob = rs.getBlob(3);
if (blob != null)
int iLen = (int)blob.length();
ByteArrayOutputStream output = new ByteArrayOutputStream(iLen);
output.write(blob.getBytes(1, iLen), 0, iLen);


catch(java.lang.ClassNotFoundException e) {
out.println("ERRO na ClassNotFound: " + e.getMessage());
catch(SQLException ex) {
out.println("ERRO na ligacao :" + ex.getMessage());
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
So what actually happens when you try? Exceptions? Errors in log file? Work with us here - my crystal ball is in the shop.
bruno martins

Joined: Oct 28, 2003
Posts: 8
no Exceptions,no Errors,but the pdf file that was create don�t show anything
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17280

There's a known problem with some browsers if you don't set the content-length header.
And you can't fake it - it has to be the true content-length.

An IDE is no substitute for an Intelligent Developer.
Timo Hahn

Joined: Jul 26, 2002
Posts: 10
don't use a printWriter. pdf normaly is binary data.
try something like tihs:
I agree. Here's the link: http://aspose.com/file-tools
subject: write pdf files whith servlets
It's not a secret anymore!