我想在我的JSF页面上显示一个PDF文件,我已经检查了这个
how to display a pdf document in jsf page in iFrame,但我不想在iframe上显示它(因为它会生成滚动条).我只想将pdf显示在像图像这样的页面上,并能够为它提供宽度和高度.
编辑你好BalusC.我仍然无法显示pdf内联.这是我的代码.
@WebServlet(name = "pdfHandler",urlPatterns = {"/pdfHandler/*"}) public class pdfHandler extends HttpServlet { private static final int DEFAULT_BUFFER_SIZE = 10240; protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { String requestedFile = request.getPathInfo(); File file = new File("/Users/KingdomHeart/Downloads/Test/pdf/" + requestedFile); response.reset(); response.setContentType("application/pdf"); response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setHeader("Content-Length",String.valueOf(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,length); } }finally{ output.close(); input.close(); } } ... }