-1

Whene I open a PDF on the browser I want to print it in a div not all the page. How can I do that? Here is my JSP source code:

<%@ page language="java" import="com.search.ts.*
                                ,java.io.*
                                ,java.net.*
                                ,javax.xml.namespace.QName
                                ,javax.jws.*
                                ,javax.xml.ws.* "
                                                   contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ebook reader</title>

<%@ page language="java" import="com.search.ts.CallSEI_CallSPort_Client,java.util.*,com.search.ts.Links,com.search.ts.LinksResponse"  %>

<link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>

            <div id="right_section">
              <div class="right_box">

<% 

        String filename= request.getParameter("err");
        //String filename =(String) request.getAttribute("linkbook");
        File file = new File("F:/fichiers/", filename+".pdf");

        response.setContentType(getServletContext().getMimeType(file.getName()));
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");

        BufferedInputStream input = null;
        BufferedOutputStream output = null;

        try {
            input = new BufferedInputStream(new FileInputStream(file));
            output = new BufferedOutputStream(response.getOutputStream());

            byte[] buffer = new byte[8192];
            int length;
            while ((length = input.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
        } finally {
            if (output != null) try { output.close(); } catch (IOException ignore) {}
            if (input != null) try { input.close(); } catch (IOException ignore) {}
        }


        %>


          </div>
 </div>


</body>
</html>
Radu Maris
  • 5,648
  • 4
  • 39
  • 54
Dilllllo
  • 448
  • 5
  • 10
  • 24

3 Answers3

0

there are simpler options with less code involved....have a look http://www.webdeveloper.com/forum/showthread.php?t=152923

Bulvak
  • 1,794
  • 8
  • 31
  • 63
  • Can you post the code here, just in case the linked site goes down in the future? Also, keep the link to the original. It's a good idea to back these things up so that if someone comes two years later and your linked page is gone, they'll still have the solution. – Richard Marskell - Drackir Jun 08 '11 at 19:33
  • You should copy the working solution from your link to this answer (at least the code), in case the link is dead in the future, so people can access the solution via SO. – Radu Maris Jun 08 '11 at 19:40
0

What you want is an object/embed tag.

Check this out

http://blogs.adobe.com/pdfdevjunkie/2007/08/using_the_html_embed_tag_to_di.html

The synopsis is, you want to source the pdf like you'd source an image:

<object type="application/pdf" data="myfile.pdf" width="500" height="650" ><embed src="myfile.pdf"/>
</object>
mrk
  • 4,999
  • 3
  • 27
  • 42
0

i was in the seem prbm you have to send from the 1st pdf page a link with the name of the pdf (myfile.pdf), like that:

<a href="pdfread.jsp?err=<%=filename %>"><%=bookName %> </a> 

to the page pdfread.jsp and in this page put that

<%
    String filename= request.getParameter("err");
%>
<embed src="${pageContext.request.contextPath}/pdfreader/<%=filename %>#toolbar=0&navpanes=0&scrollbar=0" width="500" height="375">
  </embed>

and this code you must put it in a servlet with a do get

    String filename= request.getParameter("err");
    //String filename =(String) request.getAttribute("linkbook");
    File file = new File("F:/fichiers/", filename+".pdf");

    response.setContentType(getServletContext().getMimeType(file.getName()));
    response.setContentLength((int) file.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");

    BufferedInputStream input = null;
    BufferedOutputStream output = null;

    try {
        input = new BufferedInputStream(new FileInputStream(file));
        output = new BufferedOutputStream(response.getOutputStream());

        byte[] buffer = new byte[8192];
        int length;
        while ((length = input.read(buffer)) > 0) {
            output.write(buffer, 0, length);
        }
    } finally {
        if (output != null) try { output.close(); } catch (IOException ignore) {}
        if (input != null) try { input.close(); } catch (IOException ignore) {}
    }

see this link to do it

How to use doGet in jsp with Servlet

Community
  • 1
  • 1
David
  • 47
  • 1
  • 3
  • 16