Problem with opening PDF files from JSF page using SDO

Hi all,
I'm new with JSF and was attempting to read a PDF file from a Database using SDO and JSF. The code below throws an exception when casting from DataObject to Blob. The getLcDoc() method was created by WSAD when I dragged an SDO relational record onto the JSF page. This method returns an DataObject type which I tried casting to a Blob type before using it further. However, an exception is thrown.
Any feedback is appreciated.
Arv
try {
               FacesContext faces = FacesContext.getCurrentInstance();
               HttpServletResponse response =(HttpServletResponse) faces.getExternalContext().getResponse();
               Blob file= (Blob)getLcDoc().get("ATTACH");
               int iLength = (int)(file.length());
               response.setHeader("Content-type", "application/pdf");
               response.setHeader("Content-Disposition", "inline; filename=Attachment");
               response.setHeader("Expires","0");
               response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
               response.setHeader("Pragma","public");
               response.setContentLength(iLength);
               ServletOutputStream os = response.getOutputStream();
               InputStream in = null;
               in = file.getBinaryStream();
               byte buff[] = new byte[1024];
               while (true) {
               int i = in.read(buff);
               if (i<0) break;
               os.write(buff,0,i);
               os.flush();
               os.close();
     } catch(Exception ex){
          System.out.println("Error while reading file : " + ex.getMessage());
     }

Hi...I found out that there is actually no need to use a Blob object at all. You can simply call the OutputStreams write() method and pass the DataObject.getBytes() method that returns a byte[] array. The revised code is shown at the end of this posting.
However, a few other teething problems exist:
1. This works well only if I specify the content type in response.setHeader() method. What if my users upload different types of files, is there a way that the browser opens according to the file type without setting the content type?
2. I still have a problem opening PDF files, even if I specify - response.setHeader("Content-type", "application/pdf");
I get the message - The file is damaged and could not be repaired
3. I would also like this to open the attachment in a new window and using target="_blank" doesn't seem to work as seen below:
<h:commandLink
                                             styleClass="commandLink" id="link1" action="#{pc_DocumentDetailsRead.doLink1Action}" target="_blank">
                                             <h:outputText id="text5" styleClass="outputText"
                                                  value="Click Here"></h:outputText>
                                        </h:commandLink>
------------------------Revised code-----------------------------------------
FacesContext faces = FacesContext.getCurrentInstance();
               HttpServletResponse response =(HttpServletResponse) faces.getExternalContext().getResponse();
               response.setHeader("Content-type", "application/msword");
               response.setHeader("Content-Disposition", "inline; filename=Attachment");
               response.setHeader("Expires","0");
               response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
               response.setHeader("Pragma","public");
               ServletOutputStream os = response.getOutputStream();
               os.write(getLcDoc().getBytes("ATTACH"));
               os.flush();
               os.close();

Similar Messages

  • HT1338 I have a problem with opening downloaded files from the internet; zip types. Can you tell me an app to open these types of formats of files?

    I have a problem with opening downloaded files from the internet; zip types. Can you tell me an app to open these types of formats of files?

    It should unzip if you double-cick.
    What are you seeing happen when you do that?
    Select a .zip file in the Finder and Get Info (cmd-i). What is set for it to Open With. It should be Archive Utility.

  • Adobe Reader 10 problem with opening pdf files

    Ever since I downloaded and installed Adobe Reader 10, I have been unable to open .pdf files from the Internet.  When
    I try to download them, I only the get the option of saving the file, not opening it.  Any help would be appreciated.  Thanks!

    We had similar problems with both the upgrade to 9.4.2 and 10.0.1. We would either get the download/save screen or a black screen would appear and eventually error out and freeze up the machine when we tried to hit pages that loaded pdfs stored in Oracle.  We found the pdfs would load when using Chrome or Firefox.
    We're running winXP SP3 and mainly have users using IE 7 and IE 8.  We were eventually able to solve the problem by doing the following:
    Implementing the code fix outlined in this thread (Response.charset = null;) in the page that pulled pdfs from Oracle: http://forums.adobe.com/message/3476821
    Uninstalling and reinstalling the base version of Reader (9.4.0 or X.0) from users' machines that had gone through the update from 9.x to X.x
    Rebooting the machine after each uninstall or install
    Updating the Reader to either 9.4.2 or 10.0.1
    Now we have users who can successfully load the pdfs from Oracle who are running either 9.4.2 or 10.0.1.
    Hope this helps!

  • Can't open pdf files from web pages

    I recently upgraded to Adobe Reader 8.1. Now I cannot open pdf files from email attachments. Advises to set Adobe Reader as default in folder options. When I try to do so, it appears to be OK, but still will not open files from emails.

    [email protected] wrote:
    > I recently upgraded to Adobe Reader 8.1. Now I cannot open pdf
    > files from email attachments. Advises to set Adobe Reader as
    > default in folder options. When I try to do so, it appears to be
    > OK, but still will not open files from emails.
    Did you check the settings of your mail client for handling attachments?
    Rainald

  • 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.

  • Problem with opening PDF files in Google Chrome browser

    We have a web page displaying links to dynamically generated PDF files located on the internal repository. This files are not just text PDF files but PDF forms created using XFA technology. This means that they must be opened and filled only in Adobe Reader and not in Foxit Reader or browser's built-in PDF viewer.
    Now, the problem is that a Google Chrome browser opens any PDF file using its own PDF viewer. And I want to force this browser to open PDF files in Adobe Reader.
    How can I achieve this without disabling 'Chrome PDF Viewer' plugin since I can't do this for all users of our web site?
    Any help or advice would be greatly appreciated.
    P.S. We use LiveCycle ES3.

    Each user would have to set each browser individually.
    Note: I don't think it's possible to set the default PDF viewer with code for every user who visits the site.
    See the following link to enable Adobe Reader as the default PDF viewer in different browsers:
    http://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html
    Note: Not all PDF viewer browser plug-ins support PDF submissions, and most 3rd party viewers may not support forms created with LiveCycle or forms with Extended Reader Rights enabled.

  • Does anyone have a problem with opening PDF files in iBook after updating the program recently

    I need to try to open the pdf file a few times before it goes in iBook.
    It is making me look like a fool cos I use iBook for my presentation to my clients

    I'm presumably having a similar problem with pdf's in ibook.  It seemed to work fine until about two updates ago.  We're using ipad II's with ibook (latest version as of today) for our board of director's reports.  These are sometimes several hundred pages and password protected pdf's.  Now the more whiney members of the board are *******' at me, so I need to find a solution relatively quickly.  Is there a way to back off the updates?
    What it does.
    When a PDF is chosen to open from the library, ibook open a "blank" file -- showing only the ibook background.
    One can try closing and re-opening the PDF and after three or four times it'll open -- seems to be random.
    These PDFs are created in Adobe Acrobat 9.

  • HT5568 problems with opening PDF files on safari

    in Safari i am not able to view pdf pages when i open link through wed pages, i have to first save it to my desktop and then open to see the pdf files. I have another macbook where i do not have this problem. any solution to this would be great help

    If you want to open a PDF file within Safari, you have two choices. You need to place either item 1 or items 2 in your /Library/Internet Plug-Ins folder.
    Apple Quartz Composer.webplugin
    Adobe Acrobat Reader 11 PDFViewer.plugin and AdobePDFViwerNPAPI.plugin
    Your actions are, again either item 1 or item 2:
    Get a copy of the Apple Quartz Composer webplugin from someone else with the same exact OS X version as you (or reinstall OS X).
    Place in /Library/Internet Plug-Ins
    Permission: 755 root:wheel
    Download and install the latest Adobe Acrobat Reader 11 version for OS XThe installation will place the above Adobe PDF plugins in /Library/Internet Plug-Ins
    If the Apple and Adobe plug-ins co-reside, the Adobe PDF plug-in will overide the Apple Quartz Composer plugin.
    The Adobe PDF viewer has more functionality and is compatible with the latest Safari 6 releases.

  • Problem with opening pdf files in Explorer

    I'm trying to use a button to open a pdf file. It's always
    worked in the past, but now I'm receiving an "object error" and the
    pdf is not loading. Does anyone know if this is a problem with the
    new version of Internet Explorer? Any work arounds?
    Here's my code:
    on (release) {
    getURL("NameofDoc.pdf", "_blank");
    }

    Hi,
    1. It's Adobe Reader XI, ver 11.0.08
    I guess the version of the plug-in corresponds with the version of the reader itself?
    2. "Page cannot be displayed", mostly
    Some say it takes a while for the (small) pdf to open, but we could no recreate this behavior yet.

  • Problem with open PDF files

    update I did, as you've mentioned, and now it works - let's say in 95%  When I receive an e-mail with PDF, I hit "save", and right away I cannot open the file. However, when I will go back to e-mails list, and wiev once again the same e-mail, I can see the PDF directly from the level of mail. Bit strange, however big improvement comparing to the former situation. Perhaps there is some kind of bug in stock e-mail app?

    Hi, I have following problem with my Xperia Z3:- when I receive the e-mail with PDF as attachement, I can just save it, but cannot open it. It says: "you have no application installed, please install one.."- when I save the file, and open it from File Manager, I can easily open it with Acrobat, Foxit or any other. There's no problem- when I try to do the same directly from "Downloaded" apps, again I cannot open it As I receive some part of e-mails with PDF's, the best way would be to open them directly after saving from e-mail client. Saving them, and then going to File Manager to open makes it more complicated.  Do you know, what can be the problem here? It concern stock e-mail client, Android 5.0 Hope you may know some solution

  • Issue with opening pdf file from web browser

    I have Acrobat Pro ver 6 and Adobe Reader 9.1 on a computer.  when my user tries to open up a pdf from the web he is getting the following error message:
    "The Adobe Acrobat/Reader that is running can not be used to view PDF files in a WEb Browser.  Adbe Acrobat/Reader version 8 or 9 is required.  Please exit and try again."
    What also happens is that Acrobat Pro ver 6 opens up and nothing is there.
    I am not sure why he is getting that message since Reader 9.1 is installed.
    Can any one shed some light on this for me.
    This user needs to have Acrobat and Reader on his system.  I understand that there are issues with having both.
    Also he has it set up so that any PDF is opening using the Reader 9.1.
    Thanks,

    Your PC's default reader configuration for embedded PDFs has become confused, due to multiple Adobe PDF document solutions installed on one PC.
    Solution 1:
    Go to Start > Run
    Type regedit and click OK.
    Browse to the following key: HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe
    Make sure that the correct Default data value is set for the path where Adobe Reader or Acrobat are installed.
    The default installation values are:
    "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
    or
    "C:\Program Files\adobe\acrobat 6.0\acrobat\Acrobat.exe" (not sure about this path.  Check on your PC to be sure)
    depending on whether Adobe Reader or Adobe Acrobat is installed.
    Solution 2:
    Configure the browser to use Acrobat or Adobe Reader as a helper application.
    If you are using Firefox to browse the web, you can change this setting in Firefox by going to:
    Tools > Options
    Click on the "Applications" Tab.
    The first item in the list should be "Adobe Acrobat Document".  Under the Action list, click the drop down arrow and select the application you want to read PDFs within the web browser.  Click OK, and you should be done.
    If you're using Internet Explorer to view PDFs, try the below steps.
    After you configure Acrobat or Adobe Reader as a helper application, the browser starts the helper application in a separate window and displays PDF files within that window. Acrobat and Adobe Reader both include a preference that lets you specify Acrobat or Adobe Reader as the helper application.
    To configure Acrobat or Adobe Reader as a helper application:
    Start Acrobat or Adobe Reader.
    Choose Edit > Preferences.
    Select Internet on the left.
    Deselect Display PDF In Browser Using [Acrobat application], and then click OK.
    Quit Acrobat or Adobe Reader.
    The next time you select a link to a PDF file in the browser, a dialog box asks what you would like to do with the file. If you select Open It, the browser opens the PDF file in Acrobat or Adobe Reader (the helper application); if you select Save It To Disk, the browser saves the PDF file to your hard drive.

  • Problem with opening project file from my friend

    My friend save his project and gave me it on CD. Of course he gave me all needed files like source videos. It's videos from the same type of DSLR clips which I also have. So I making my own movies also with clips in this codes or similar. My DSLR is Canon 600D but DSLR of my friend is Canon 550D - clips from his DSLR are of course also written form my system. So everything seems to be OK.
    Now i try to open this project in my PC but it doesn't work at all. I can see only this message:
    My friend work on CS 5 but I work on CS 6. I don't believe that Adobe Premiere Pro can't open a older type of his project files. Please help.

    Mark Mapes wrote:
    What do you know about the sequence preset your friend used?
    Sequence preset? I don't know anything. But I think that is unneceserry even to know. Because why sequence preset can be important? Preset is only a preset. So I can't see any reason preset was a main problem with it.

  • Problem with opening a file in its application using Runtime

    Dear experts,
    excuse me for my ignorance, but I am facing a problem and I would really
    appreciate some help. I am working on a java program in which I want the user
    to have the ability to save the contents of a JTable into a file of his preference (the file could be of any type i.e xls, txt, doc...) and then open this file in its
    default application (i.e the txt file through notepad, the xls file through excel etc..).
    Everything works fine with the code below, if the filePath does not contain blank spaces. I did some search on the forun and the web, and also tried to
    find a solution through the great link
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html but I still
    cannot solve the problem. Below I quote the part of the code (actually the actionPerformed dunction of the equivallent button) which is responsible for the opening of the file.
        excelButton.addActionListener(new ActionListener()
           public void actionPerformed(ActionEvent e)
             //saveFileName is the File that I want to open
             String filePath = "\""+saveFileName.toString()+"\"";
             System.out.println(""+filePath);
             try
              String cmd="cmd.exe /C start "+filePath;
              String cmd="cmd.exe /C start C:\\Documents and Settings\\test.xls";
              Process p = Runtime.getRuntime().exec(cmd);
             }catch(IOException ec){}
         });Thank you in advance for your help!
    Sincerely yours,
    JIM

    Dear BillBlalock ,
    thank you for answer!! You are very kind and helpful!! I would like to inform everybody that I have finally find another way of soilving my problem and I announce it to the forum in case somebody else encounters the same problem. Well, I soved the nproblem by using the following code:
        excelButton.addActionListener(new ActionListener()
           public void actionPerformed(ActionEvent e)
             String filePath = "\""+saveFileName.toString()+"\"";
             System.out.println(""+filePath);
             try
               String cmd="explorer "+filePath;
               Process p = Runtime.getRuntime().exec(cmd);
             }catch(IOException ec){}
         });I hope it can be useful to somebody!! By this code, I can make a button (in my case the excelButton) to open any file in its default application. Keep up the great work you are doing guys!!

  • Issue with opening PDF files from the web Acrobat 8.1.4

    Hello everyone
    I just found out about this problem today, and it manifests in such a manner that when you try to open a PDF document on the web, it hangs for a while, and then the standard message about Adobe Acrobat not being able to open the document comes up, and after you OK away that you get the message that the program shuts down.
    If I download the PDF itself and open it locally it works. Is there any known issue with updates recently that creates this problem?
    The system is running on Windows 7 32-bits, and Adobe Acrobat is a part of the CS3 Master Collection.
    Greetings from Alexander

    Not supported file type can (but not always) mean the PDF was created with an old enough version of Acrobat, that it isn't comaptible with reader X or XI.
    Might have been damaged is pretty cut and dried in its meaning and interpretation.
    There's a known issue with Mac OS and Safari Browser "breaking" PDFs as they download, but it's not so common for Windows. Since these are files you already had, it would be even less applicable.
    You can try downloading an older version of Reader to check if it's a compatibility issue, but you'd have to uninstall the latest to do it and it'd be a lot of bother if they still don't open. It would also mean they are "broken" and cannot be repaired, that I know of.

  • Issue with opening PDF file link from Safari

    Hi Everyone,
    I got a problem with opening PDF file link from Safari 4.04. Instead of getting a normal pdf content, it shows some weird characters. Not sure it is something wrong with Adobe Reader Plugin or Safari?
    I have uploaded a screenshot of the issue in the adobe forum (http://forums.adobe.com/thread/531870). Please help!
    Many Thanks,
    John

    There's nothing wrong, except the fact that you have Adobe Reader installed. You don't need it, so get rid of it; it will only cause problems with Safari. What you're seeing is the contents of the PDF file, rather than having it displayed.
    If you want to download a PDF file, you can either Control-click on the link and choose "Download Linked File As…", or you can Option-click on the link for the file and it will be downloaded to your Download folder (usually your Desktop).
    If you want to view a PDF file in Safari, you don't need Adobe Reader; Safari is perfectly capable of doing this by itself and has been for years. Adobe Reader will only get in the way and slow everything down.

Maybe you are looking for