5 Replies Latest reply on Sep 15, 2008 12:33 PM by JimBrychka

    How to open pdf files in browser using flex

    yerra hemanth
      hi,
      my project is having a Document explorer wchich contains pdf files,iwant to open it in the browser.can any one tell me how to open pdf documents using flex programming(i tried with different thing like swf's but my client wants only pdf formatt).
        • 1. Re: How to open pdf files in browser using flex
          Level 7

          "yerra hemanth" <webforumsuser@macromedia.com> wrote in message
          news:gajees$rvp$1@forums.macromedia.com...
          > hi,
          > my project is having a Document explorer wchich contains pdf files,iwant
          > to
          > open it in the browser.can any one tell me how to open pdf documents using
          > flex
          > programming(i tried with different thing like swf's but my client wants
          > only
          > pdf formatt).

          http://www.jeffryhouser.com/index.cfm/2008/4/22/Using-AIR-to-launch-other-applications


          • 2. Re: How to open pdf files in browser using flex
            atta707 Level 2
            FileReference.download(....)
            • 3. Re: How to open pdf files in browser using flex
              JimBrychka
              Another option is by calling a JSP page. This example will open a pdf file into a new browser without displaying the download "save" prompt.

              Function to call the JSP:
              private function downloadFlyer(event:Event):void {
              var jspLink:URLRequest = new URLRequest("jsp/downloadpdf.jsp?fileName=Fundraiser_flyer_2008.pdf");
              navigateToURL( jspLink, "_blank" );
              }

              JSP code:
              <%@ page errorPage="error.jsp" %>
              <%@ page import="java.io.*" %>

              <%
              //Get the parameters
              String downloadFileName=request.getParameter("fileName");

              String fileName = application.getRealPath("/downloads/" + downloadFileName);
              File file = new File(fileName);
              if (!file.exists()) {
              throw new IOException("File does not exist.");
              }

              // Get the size of the file
              long length = file.length();

              // You cannot create an array using a long type.
              // It needs to be an int type.
              // Before converting to an int type, check
              // to ensure that file is not larger than Integer.MAX_VALUE.
              if (length > Integer.MAX_VALUE) {
              throw new IOException("File too big.");
              }

              response.reset();
              response.resetBuffer();
              response.setContentType( "application/pdf" );
              response.setHeader ("Content-Disposition", "filename=" + downloadFileName);

              //Prevent the Java error: "getOutputStream() has already been called for this response"
              out.clear();
              out = pageContext.pushBody();

              InputStream in = new FileInputStream(file);
              OutputStream output = response.getOutputStream();

              try {

              int curByte=-1;
              while( (curByte=in.read()) !=-1){
              output.write(curByte);

              }

              } catch (IOException ioe) {
              ioe.printStackTrace(System.out);
              } finally{
              output.flush();
              in.close();
              response.flushBuffer();
              }
              %>

              • 4. Re: How to open pdf files in browser using flex
                thephantom6969 Level 1
                Is there a way to load the pdf from a hard drive?
                • 5. Re: How to open pdf files in browser using flex
                  JimBrychka Level 1
                  You can open it from a hard drive using the jsp example that I posted. You can also download it from a hard drive per atta707's post.

                  I have read that you might have more options with the new Flash Player 10.

                  You could also look at AIR.