how to display a pdf document in jsf page in iFrame

前端 未结 2 1768
耶瑟儿~
耶瑟儿~ 2021-02-09 23:46

Can anyone help me in displaying PDF document in JSF page in iframe only?

Thanks in advance,

Suresh

2条回答
  •  感情败类
    2021-02-10 00:24

    Just use

    If your problem is rather that the PDF is not located in the WebContent, but rather located somewhere else in disk file system or even in a database, then you basically need a Servlet which gets an InputStream of it and writes it to the OutputStream of the response:

    response.reset();
    response.setContentType("application/pdf");
    response.setContentLength(file.length());
    response.setHeader("Content-disposition", "inline; filename=\"" + file.getName() + "\"");
    BufferedInputStream input = null;
    BufferedOutputStream output = null;
    
    try {
        input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
        output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
    
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int length;
        while ((length = input.read(buffer)) > 0) {
            output.write(buffer, 0, length);
        }
    } finally {
        close(output);
        close(input);
    }
    

    This way you can just point to this servlet instead :) E.g.:

    
    

    You can find a complete example of a similar servlet in this article.

    The

提交回复
热议问题