sivarajankumar / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

issue with saving pdf with java #131

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. generate pdf document
2. try to save it (please see java & as code bellow)

When I try to open pdf - file my pdf wiewer say me that my file is 
incorrect, but when I do the same with air I haven't any problem.

I use AlivePdf 0.1.4.8, flex builder 3.0, 10 version of flash player.

Java code

public class CreatePDFServlet extends HttpServlet {

    protected final Log logger = LogFactory.getLog(getClass());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doGet(req, resp);
    }

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        int i = 0;
        int k = 0;
        int maxLength = req.getContentLength();
        byte[] bytes = new byte[maxLength];
        String method = req.getParameter("method");
        String name = req.getParameter("name");
        ServletInputStream si = req.getInputStream();
        while (true) {
            k = si.read(bytes, i, maxLength);
            i += k;
            if (k <=0)
            break;
        }
        if (bytes != null) {
            ServletOutputStream stream = resp.getOutputStream();
            resp.setContentType("application/pdf");
            resp.setContentLength(bytes.length);
            resp.setHeader("Content-Disposition", method + ";filename=" + 
name);
            stream.write(bytes);
            stream.flush();
            stream.close();
        } else {
            resp.setContentType("text");
            resp.getWriter().write("bytes is null");
        }
    }

flex code

var bytes:ByteArray = pdf.save(Method.REMOTE,"http://localhost:8082/
pdfGenerate",Download.INLINE,"report.pdf");

Original issue reported on code.google.com by vkozhaev@gmail.com on 9 Jun 2009 at 3:34

GoogleCodeExporter commented 8 years ago
Probably it's not a bug because on windows platform it works fine, but on 
ubuntu I
have problem witm mime - type of document

Original comment by vkozhaev@gmail.com on 12 Jun 2009 at 9:24

GoogleCodeExporter commented 8 years ago
Change  if (k <=0) to   if(k == -1)  - otherwise your PDFs will not show up on 
windows platforms because of that 
little old byte missing!

Original comment by johnmar...@gmail.com on 15 Jul 2009 at 5:48