PDF file downloading from server to client

Hello,
I am a newbie to Oralce UCM. Writing a component to merge some PDF files and allow user to save/open it on client side.
The file downloaded is of 0 bytes and when opened it says -
Adobe Reader could not open the the file because it is either not a suppported file type or because the file is damaged(It was sent as an email attachment and was not correctly decoded)
this.m_binder.m_contentType = "application/pdf";
this.m_binder.m_clientEncoding = "utf-8";
DataStreamWrapper dataStreamWrapper = this.createNewDownloadStream();
dataStreamWrapper.m_clientFileName = "MergedPDF";
dataStreamWrapper.m_inStream = mergedPDF.getDocumentInputStream();
dataStreamWrapper.m_inStreamActive = true;
dataStreamWrapper.m_dataType = "application/pdf";
try {
this.m_httpImplementor.sendStreamResponse(this.m_binder, dataStreamWrapper);
} catch (ServiceException e) {
e.printStackTrace();
Some clue would really help :)
Thanks,
Fauzia

Hi Jiri,
I have created and HCSP page where data is being populated dynamically. User may select some of the files from this page through checkbox. Page also has a download button which when clicked will merge all the selected documents and let the user open/save it.
Information like Native URL, docName is passed on to the content server when the component is called (download button-click).
Merging the PDFs, I have used a custom utility which takes url as a parameter and returns back the inputstream of merged PDF.
And last, I have used DataStreamWrapper to send this inputstream back to the client as an attachment which can be read by IE.
Also, I thought at first to use HTTPHeader where parameters like content-disposition, content-type can be set. But UCM already provides a better way to achieve this i.e. through DataStreamWrapper.
public class MergePDF extends Service {
     public List<PdfDocumentSource> createPdfDocumentSourceList(
               String... urlStrings) throws MalformedURLException {
          List<PdfDocumentSource> sourceList = new ArrayList<PdfDocumentSource>(
                    urlStrings.length);
          for (String url : urlStrings) {
               URL urlDoc = new URL(url);
               PdfDocumentSource pdfSource = new UrlPdfDocumentSource(urlDoc);
               try {
                    System.out.println("URL in create method - "+urlDoc);
                    System.out.println("PDFSource input stream - "+pdfSource.getDocumentInputStream().available());
               } catch (IOException e) {
                    e.printStackTrace();
               sourceList.add(pdfSource);
          return sourceList;
     public void mergeAll() throws DataException, ServiceException {
          Properties property = this.m_binder.getLocalData();
          String urlStrings = "";
          List<PdfDocumentSource> sourceList;
          PdfDocumentSource mergedPDF = null;
          urlStrings = property.getProperty("webURL");
          String[] urls = urlStrings.split(";");
          try {
               sourceList = createPdfDocumentSourceList(urls);
               PdfMerge merge = new PdfMerge(sourceList, true);
               try {
                    mergedPDF = merge.createMergedPdf();
                    transferToClient(mergedPDF);
               } catch (PdfProcessingException e) {
                    e.printStackTrace();
          } catch (MalformedURLException e) {
               e.printStackTrace();
          System.out.println("hello123");
          System.out.println("URLS - "+urlStrings);
     public void transferToClient(PdfDocumentSource mergedPDF){
          this.m_binder.m_contentType = "application/pdf";
          this.m_binder.m_clientEncoding = "utf-8";
          DataStreamWrapper dataStreamWrapper = this.createNewDownloadStream();
          dataStreamWrapper.m_clientFileName = "MergedPDF.pdf";
          dataStreamWrapper.m_inStream = mergedPDF.getDocumentInputStream();
          //dataStreamWrapper.m_inStreamActive = true;
          dataStreamWrapper.m_dataType = "application/pdf";
          try {
               this.m_httpImplementor.sendStreamResponse(this.m_binder, dataStreamWrapper);
          } catch (ServiceException e) {
               e.printStackTrace();
          * StringBuffer sb = this.createHttpResponseHeader();
          sb.append("Content-Type: application/pdf");
          sb.append("Content-Disposition: attachment; filename=fname.ext");
          //m_headerStr
          this.m_headerStr = sb.toString();
}

Similar Messages

  • File Download from server to client

    Please review the following code. I am attempting to download a file , whether PDF, DOC, TXT, etc.., from the server to client(in this case a DOC file). The f.exist() method returns true so the file exists but the f.length() returns 1. The file is considerably larger than 1 byte. The download occurs but the file contains 1 byte of code.
    Also, please review all the code and suggest any code changes needed to complete the download. I am new to Java programming so be kind.
    File f = new File(filePath + fileName);
    System.out.println("file " + f);
    System.out.println(f.exists());
    System.out.println("file length " + f.length());
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    response.setContentLength(fis.available());
    System.out.println("bytes " + fis.available());
    response.setContentType("application/msword");
    response.setHeader("Content-disposition","attachment; filename=" + fileName );
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    byte[] buff = new byte[1024];
    int bytesRead;
    // Simple read/write loop.
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
    bos.write(buff, 0, bytesRead);
    bos.flush();
    bos.close();
    bis.close();
    response.flushBuffer();
    fis.close();
    } catch(Exception e){
    System.out.print("\n svtFileDownload.processRequestFileDownload Exception=" + e);

    the following is a nippet from a servlet I wrote that does what you want and I've had no problems with it, even with large file 200+ megs.
                String filename = bundle.getFileLocation();
                response.setContentType("application/stream");
                response.setHeader("Content-Disposition","attachment; filename="+filename+";");
                ServletOutputStream out = response.getOutputStream();
                BufferedInputStream fif= new BufferedInputStream(new FileInputStream(FILE_LOCATION+filename));
                int data;
                while((data = fif.read())!=-1)
                    out.write(data);
                fif.close();
                out.close();

  • File download from server

    Hi All,
    I have written a code that downloads a file from server using the following link given by Frank,
    File download from server
    I am able to get a open/save/cancel dialog with help of this. But issue is that applications of kind .doc/.xls/.ppt gets opened (If user clicks open) right in the internet explorer window instead of getting opened in a new office application....
    However .pdf runs fine.
    Can any thing be done for this???
    Any help....
    Regards,
    Amitt

    Hi,
    what do you have for the content disposition header?
    Try this:
             response.setHeader("Cache-Control", "max-age=0");
             response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + "\"");
             response.setContentType("application/x-download");Brenden

  • Just upgraded to Lion, can't open any pdf file downloaded from internet that was fine with Leopard. How can I overcome this obstacle ?

    Just upgraded to Lion, can't open any pdf file downloaded from the internet that was fine with Leopard before. I just got a black screen when I clicked on a pdf icon on a given internet site, and same happened with several sites that I visited. How can I overcome this obstacle ?

    Try two things with Safari not running:
    1) Launch Adobe Reader, open its preferences, select the Internet category, and check the values under "Display PDF in browser using".  If it's checked, try unchecking it.
    2) Look in /Library/Internet Plug-Ins (at the top-level of your boot volume) for something names AdobePDFViewer.plugin.  If you see such a file, try moving it to a folder named "Disabled Plug-Ins" (if such a folder exists) or onto the Desktop.
    Then see how things work.

  • Error while opening PDF file downloaded  from database Blob column

    Hi All,
    I am working on jdev 11.1.1.4.0.
    In my use-case I am using filedownload Actionlistner on a link to get the PDF file stored in the database in blob field. These files are being uploaded from other use-case in adf only.
    After getting the dialog box to open/save/cancel for the PDF file when i click on open then i am getting an error *'Adobe Reader could not open 'abc.pdf' because it is either not a supported file type*
    or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly docoded)' for some files , and to my surprise I am able to open some files.
    When I open these PDF files separately from desktop I am able to view the content of each and every file in adobe reader.
    I dont know where the problem exactly lies , while uploading/downloading the file . Any ideas/thoughts to resolve this issue?
    Thanks
    Kanika

    Thanks a lot Timo...!!!
    I checked the PDF file downloaded directly from the blob column in DB, there only it is corrupted so must be the problem in uploading the file. I am checking the code line by line,, but no problem in setting the file content type,size etc.
    Here is the code snippet ..
    byte[] buff;
    buff = new byte[(int)length]; -- Length is the file size
    int bytesRead = is.read(buff);
    for (int i = 0; bytesRead < buff.length; i++) {
    // int b = is.read();
    int b = is.read();
    if (b == -1)
    break;
    buff[i] = (byte)b;
    BlobDomain blobDomian = new BlobDomain((buff));
    TestVORow = (TestVORow Impl)TestVO.createRow();
    if(blobDomian != null) {
    TestVORow.setAttachment(blobDomian);
    am.getTransaction().commit();
    This seems to be Ok to me..the same issue, file is still corrupting.
    Any thoughts from your side ???
    Thanks
    Kanika
    The problem is resolved.
    Changes made are instead of
    InputStream is;
    used ... BufferedInputStream bis ;
    and after
    for (int i = 0; bytesRead < buff.length; i++) {
    // int b = bis.read();
    int b = bis.read();
    if (b == -1)
    break;
    buff[i] = (byte)b;
    bis.close(); // use this close bufferedInput Stream.
    Able to open each and every file now..Thanks for your suggestions Timo and Frank.
    Edited by: Kanika on Mar 6, 2012 3:15 AM

  • Reg: Html file download from server

    My requirement is download file from server. Am using jsp and servlet this. While downloading the file a dialog box with open, save and cancel option. When try to open html file it, open in the same window .
    Req: it should be open in seperate window (ie)
    Please advise me how to open a html file in seperate explorer
    Am using below Code for download a file:
    private void downloadFile( HttpServletResponse response, String strFileType, File file ) throws Exception
    logger.trace(Util_Client.INFO, Util_Client.getInfo(), "File download Started.");
    BufferedInputStream bufferedInputStream = null;
    try {
    String strContentType = fileExtnContentTypeMapping.get(strFileType);
    if(strContentType == null)
    strContentType = fileExtnContentTypeMapping.get(CLConstants.FILE_EXTN_OTHERS);
    response.setContentType(strContentType);
    String strHeader = "Attachment;Filename=" + file.getName();
    response.setHeader("Content-Disposition", strHeader);
    byte data[] = new byte[CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER];
    bufferedInputStream = new BufferedInputStream( new FileInputStream( file ), CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER );
    int count;
    while((count = bufferedInputStream.read(data, 0, CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER)) != -1 ) {
    response.getOutputStream().write( data, 0, count );
    response.getOutputStream().close();
    }catch (ClientAbortException clientAbortException) {
    clientAbortException.printStackTrace();
    }finally{
    try {
    if( bufferedInputStream != null )
    bufferedInputStream.close();
    } catch (Exception exceptionFinally) {
    exceptionFinally.printStackTrace();
    logger.trace(Util_Client.INFO, Util_Client.getInfo(), "File download Ends.");
    Thanks in advance
    Edited by: sunRP on Oct 11, 2009 9:47 AM

    The best you can do is set the correct content type.
    Once the file reaches the client's browser it's up to the client and their browser settings to decide what to do with it.
    You can't control the client's browser from your servlet.

  • PDF File Download from a JSP

    I want to have a JSP that will be used to download/display files. I created
              a test.jsp page that tries to return a test.pdf page. Whenever I run it,
              the browser displays some characters and then hangs, but never displays the
              pdf file. If I browse directly to the pdf file it displays fine in the
              browser. What am I doing wrong in this JSP page:
              <%@ page import="java.io.*" %>
              <%
              String mimeType = "application/pdf";
              response.setContentType(mimeType);
              try
              FileInputStream fis = new
              FileInputStream("d:\\work\\internet\\appserver\\presentation\\rdoc\\test.pdf
              ServletOutputStream sos = response.getOutputStream();
              System.out.println("Begin...");
              int i = fis.read();
              while(i != -1)
              sos.write(i);
              i = fis.read();
              sos.flush();
              sos.close();
              fis.close();
              System.out.println("End...");
              catch(Exception e)
              System.out.println(e);
              %>
              

    The JSP will send new lines etc. to the output stream because you have new
              lines in your JSP.
              All right, since you asked, I will have to post my secret source:
              ----- Original Message -----
              From: "Erik Lindquist" <[email protected]>
              Newsgroups: weblogic.developer.interest.jsp
              Sent: Wednesday, June 28, 2000 6:20 PM
              Subject: How to dynamically display images in JSPs
              >
              > This took a little while to figure out so I thought I'd share. After
              > doing some research I was led to the following approach on how to load
              > images from an Oracle database into a JSP:
              >
              > The "main" JSP:
              >
              > <HTML>
              > <head>
              > <title>Image Test</title>
              > </head>
              > <body>
              > <center>
              > hello
              > <P>
              > <img border=0 src="getImage.jsp?filename=2cents.GIF">
              > <P>
              > <img border=0 src="getImage.jsp?filename=dollar.gif">
              > <P>
              > world
              > </body>
              > </HTML>
              >
              >
              > And this is the image getter:
              >
              > <% try {
              > response.setContentType("image/gif");
              > String filename = (String) request.getParameter("filename");
              > java.sql.Connection conn =
              > java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
              > connect to db
              > java.sql.Statement stmt = conn.createStatement();
              > String sql = "select image from testimage where filename = '" +
              > filename + "'";
              > java.sql.ResultSet rs = stmt.executeQuery(sql);
              > if (rs.next()) {
              > byte [] image = rs.getBytes(1);
              > java.io.OutputStream os = response.getOutputStream();
              > os.write(image);
              > os.flush();
              > os.close();
              > }
              > conn.close();
              > }
              > catch (Exception x) { System.out.println(x); }
              > %>
              >
              >
              > The thing to note is that there are no <%@ page import="..." %> or <%@
              > page contentType="..." %> tags - just the single scriptlet. It
              > seems that for every "<%@" the weblogic compiler sees it puts
              > out.print("\r\n"); statements in the generated java source.(???) I
              > don't know much about how browsers work but I think that once it sees
              > flat ascii come at it it treats everything that follows as text/plain
              > which is incorrect for the binary stream that's being sent. Another
              > work around was to set out = null; but that's kind of ugly and might
              > produce server errors. The real fix is to write a bean to handle images
              > which I'll work on next (does anybody have any hints on how to do
              > that?)
              Peace.
              Cameron Purdy
              http://www.tangosol.com
              "Jesse E Tilly" <[email protected]> wrote in message
              news:[email protected]...
              > [email protected] (Cameron Purdy) wrote in
              > <[email protected]>:
              >
              > >Your import will always cause junk to be sent before the PDF. You
              > >should do this as a servlet, not a .jsp.
              >
              > Really? What's the difference between JSP and Servlet as far as writing
              to
              > the response object is concerned?
              >
              > Btw, I forgot to mention that the setContentType should be done as late as
              > possible. It begins the response.
              >
              > Jesse
              

  • Acrobat Reader can't open PDF file downloaded from the internet

    I downloaded the following pdf file from the internet and saved it to the desktop. When I tried to open the file I got a message saying Acrobat couldn't open it. I do not have trouble opening other PDF files. There is something about opening certain PDF files from the internet that is causing this. Is there a setting in the PDF preferences that is causing this or some security setting.
    http://www.porteverglades.net/include/content/docs/media/Port-map-2009.pdf

    It seems that Safari is unable to export the document as a PDF because the exported file was zero bytes. That's why I couldn't open it. I tried Firefox and did a File>Save. It saved the file as a PDF which I was able to open. So proglem solved.

  • ERROR OPENING PDF FILES DOWNLOADED FROM INTERNET

    I have a problem when I download a pdf file from Internet and I try to open in throughout Acrobat Reader. It appeared one error saying "The file path is not valid". What can I do?.

    Hi there,
    I found this can happen if the file does not download correctly. When this happens, simply try redownloading the file and wait until it has fully downloaded before doing anything else with the browser.
    Does that work now?
    If you want to thank someone for their comment, do so by clicking the Thumbs Up icon.
    If your issue is resolved, don't forget to click the Solution button on the resolution!

  • Opening PDF files downloaded from IE 7

    Whenever a new PDF file is downloaded via IE 7 my Adobe Reader will not open it and I receive an error msg. indicating that a version of Adobe Reader is alaready running with directions to close the app.

    You downloaded the PDF documents to your local disk?  Or you open them directly in IE7?  Did you try to close the app (AcroRd32.exe) from Task Manager?
    [topic moved to Adobe Reader forum]

  • I have a problem with opening PDF files downloaded from anywhere!

    I can view them ok in Safari, but when I save and download them, they are displayed with the Preview image and will not open.
    When I click them, a message says that 'the file may be damaged or not recognised by Preview'.
    I have cleaned up my computer (apple help ) but still, the problem remains. I downloaded the same file to my MacBook pro, and it saved it in the usual PDF format, (completely different image from above), and opened perfectly well.
    I have checked the settings in Preview and they seem to be set correctly so that Preview will open PDF files.
    What next?
    I am desperate!
    Jennifer

    See if you can delete any Adobe PDF plugins from /Library/Internet Plug-Ins/. Then quit and re-open your web browser and try again.

  • Can't save pdf files downloaded from some databases

    When I download some pdf files from databases (e.g. SpringerLink) I can download to READ only (there is NO toolbar for printing/saving/etc). I am accessing them through a University library which gives access. Is there some setting I need to change? OR are some files restricted to read only??? If so - how can I tell that is the case before I download?

    Graffiti - I did have Adobe Reader 9 - and I use Google Chrome.
    Inspired by your questions, I downloaded Adobe Reader X 10 - the pdf files still don't go through the 'normal' process of requesting to be saved and being open. They appear immediately but with no toolbar.
    SO I tried right clicking on the pdf file which could just be viewed, saving it, and THEN - YES THAT starts the 'normal' process of appearing as a file with the possibility of opening it (with toolbar).
    Is this 'normal'? I've opened large numbers of pdf files - and I never remember having to right click in order to start the process.
      Thanks very much for all your help,
      Drwhoish

  • Adobe Reader 9 doesn't "stream" pdf files downloaded from web

    Recently I uploaded a large PDF file to my website. When I link to this file with Adobe Reader 7 I see the first pages of the file shortly after the download begins. With Adobe Reader 9 the whole file downloads before the first page appears on the monitor. This happens with both IE and Firefox.

    Did you optimize the file before uploading the pdf?
    Mike

  • Pdf File download from a message board

    I can open pdf attachment on my favorite message board, but how can I store it on my iPad for viewing when I am not in WiFi range (at the race track)?

    Albert1956-
    I know a round-about way to do this using the GoodReader App.  In Safari, press and hold on the link to the PDF.  Select Copy from the menu that appears.
    Then go to the GoodReader App, select Web Downloads in the right side of the screen and then select Enter URL.  The window where you would enter the URL should contain the just-copied URL.
    Once downloaded into GoodReader, you can read it there.  You also have the option to E-Mail the file, which can then be opened in iBooks.
    Fred

  • File Download from Server location - JSP

    Hi SDN,
    I have a txt file in a folder created in server location under the path /usr/sap/EPD/JC00/j2ee/cluster/server0. On click of the link correspondin to the file name in JSP, i have to open the file with the pop up to save, open or cancel. I have to achieve this in the JSP. I am currently
    <td> <a href="/usr/sap/EPD/JC00/j2ee/cluster/server0/XXX/yyy.txt"> <%=fileName%></a ></td>
    I am not able to achieve the intended functionality. How to achieve it. Expecting your valuable replies
    Thanks & Regards,
    p188071

    hi,
    I am using the following snippet
    String filePath ="/usr/sap/EPD/JC00/j2ee/cluster/server0/xxx/yyy.txt"; // path of your excel file
         HttpServletResponse resp = componentRequest.getServletResponse(true);
         resp.setContentType("text/html; charset=UTF-8");
           // set the exact content type
         resp.setHeader("Content-Disposition","attachment; filename=\""+ filePath + "\"");
    It is creating downloading a txt file with the name usr_sap_EPD_xxx_yyy.txt without actual contents inside the file. It is just generating a file without writing the contents into that file.
    What should I do?
    p188071

Maybe you are looking for