I have a code to display a pdf file:
@WebServlet(urlPatterns = {"/teste"})
public class abrirPDF extends HttpServlet {
byte[] arquivo = null;
File file = new File("C:\testes\teste.pdf");
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
arquivo = fileToByte(file);
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/pdf");
response.setContentLength(arquivo.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(arquivo, 0, arquivo.length);
ouputStream.flush();
ouputStream.close();
}
public static InputStream byteToInputStream(byte[] bytes) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
return bais;
}
public static byte[] fileToByte(File imagem) throws Exception {
FileInputStream fis = new FileInputStream(imagem);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
}
I need to open this pdf on a specific page. That is, I want the browser to open the PDF directly on a particular page and not on the first page of the file. How can I do this?