Printing PDF in jsp in iframe contents -


i have researched several options printing pdf inside iframe , none seem working.

simple details:

  1. i search parameters user.
  2. i database search , use apachi fop generate pdf of results.
  3. they directed webpage has print , cancel button.
  4. when user clicks print button, open window displaying pdf.
  5. a print dialog open user print pdf.
  6. the pdf file deleted server.
  7. the windows close

advanced details:

  • this needs work on ie8.
  • the fop integration not use xslt translations. uses stringreader of inputted fop xml formatted string
  • the window displaying pdf 2 jsp pages.
  • the first page:
    • has iframe second jsp page source
    • runs printpdf() function on load prints pdf in iframe
  • the second page:
  • uses java bufferedoutputstream , servletoutputstream
    • will delete file after outputting
    • uses out = pagecontent.pushbody();

here part of first jsp page (the run calls print function):

<body onload='printpdf()'> <table>     <tr>         <td class="content">             <%             // myfilename myfile parameter on url             string myfile = request.getparameter("myfile");             out.print("<iframe src='fc_view_letter.jsp?myfile="+ myfile + "' id='pdfframe'></iframe>");             %>         </td>     </tr> </table> <script>     function printpdf()     {         var id = 'pdfframe';         var iframe = document.frames ? document.frames[0] : document.getelementbyid(id);         var ifwin = iframe.contentwindow || iframe;          ifwin.focus();         ifwin.printpage();         //ifwin.print();     } </script> </body> 

here of second jsp page (the 1 shows pdf):

<%@ page session="false" %> <%@ page import="java.io.*" %> <%@ page import="java.net.urldecoder" %> <html> <head> </head> <body> <% string myfile = request.getparameter("myfile"); string myfiledecoded = ""; myfiledecoded = urldecoder.decode(myfile, "utf8"); string myfilename = myfiledecoded; string extension; int dotpos = myfilename.lastindexof(".")+1; extension = myfilename.substring(dotpos); int slashpos = myfilename.lastindexof("/")+1; string secondparam = "filename=" + myfiledecoded.substring(slashpos); response.setcontenttype("application/pdf"); response.setheader("content-disposition", secondparam); try {         servletoutputstream sout = response.getoutputstream();         response.setheader("content-disposition", secondparam);          file  file  = new file(myfilename);         fileinputstream fstream = new fileinputstream(file);          bufferedinputstream bis = null;         bis = new bufferedinputstream(fstream);           bufferedoutputstream bos = null;         bos = new bufferedoutputstream(sout);          byte[] buff = new byte[1024];         int bytesread;          while(-1 != (bytesread = bis.read(buff, 0, buff.length))) {              bos.write(buff, 0, bytesread);         }           bis.close();          bos.close();           sout.flush();          sout.close();           //file.delete();  } catch (exception e)  {      system.out.println("exception occured...................." ); }    out.clear();     out = pagecontext.pushbody(); %> </body> </html> 

what think issue: i'm thinking buffer eliminates of html , displays pdf. or @ least in ie. when looked in firefox embedded pdf file. maybe cannot grab contents of iframe because no longer html.

here sources far:

javascript print iframe contents only

how open print dialog after pdf generated?

http://www.ehow.com/how_7352227_use-javascript-print-pdf.html

http://www.webmasterworld.com/forum91/4086.htm

how print pdf inside embed/iframe using javascript

printing contents of dynamically created iframe parent window

what ended doing generating pdf using itext added print javascript ran when pdf loaded


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

mysqli - Php Mysqli_fetch_assoc Error : "Warning: Illegal string offset 'name' in" -