Ich kann nicht öffnen Sie eine .pdf-Datei in meinem browser durch Java

Im Versuch zum öffnen einer pdf-Datei, die ich erstellt habe, mithilfe der iText-Bibliothek in meinem browser, aber es funktioniert nicht.
Dies ist der code Im Einsatz, um zu senden browser

    File file = new File(path);

    try{
        //InputStream stream=blob.getBinaryStream();
        InputStream streamEntrada = new FileInputStream(file);
        //ServletOutputStream fileOutputStream = response.getOutputStream();
        PrintWriter print = response.getWriter();

        int ibit = 256;
        while ((ibit) >= 0)
        {
            ibit = streamEntrada.read();
            print.write(ibit);
         }

        response.setContentType("application/text");
        response.setHeader("Content-Disposition",  "attachment;filename="+name);
        response.setHeader("Pragma", "cache");
        response.setHeader("Cache-control", "private, max-age=0");
        streamEntrada.close();
        print.close();

        return null;
    }
    catch(Exception e){

        return null;
    }
}

Habe ich versucht mit FileOutputStream aber nicht funktioniert. Im verzweifelten.

Danke.

Nun, Im Versuch, auf diese Weise, aber es funktioniert nicht:

public class MovilInfoAction erstreckt DownloadAction{

protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    //Here the creation of the PDF

    //Storing data
    PdfData dPdf = pdf.drawPDF(terminal);

    String path = dPdf.getPath();//Path
    String name = dPdf.getName()+".pdf";//Pdf´s name
    String contentType = "application/pdf";//ContentType

    response.setContentType(contentType);
    response.setHeader("Content-Disposition","attachment; filename="+name);
    response.setHeader("Cache-control", "private, max-age=0");
    response.setHeader("Content-Disposition",  "inline"); 

    File file = new File(path);
    byte[] pdfBytes = es.vodafone.framework.utils.Utils.getBytesFromFile(file);

    return new ByteArrayStreamInfo(contentType, pdfBytes);
}

protected class ByteArrayStreamInfo implements StreamInfo {

    protected String contentType;
    protected byte[] bytes;

    public ByteArrayStreamInfo(String contentType, byte[] bytes) {
        this.contentType = contentType;
        this.bytes = bytes;
    }

    public String getContentType() {
        return contentType;
    }

    public InputStream getInputStream() throws IOException {
        return new ByteArrayInputStream(bytes);
    }
}

}

InformationsquelleAutor user623020 | 2011-02-18
Schreibe einen Kommentar