Problem displaying PDF file in new window.

Using NetBeans 6.5, Internet Explorer 7.
I am using the code example from BalusC at the site:
http://balusc.blogspot.com/2006/05/pdf-handling.html
I am having no problem reading and displaying the PDF file, but it displays it in the same window,
not a new window and it overwrites the current page, so I can't use the back arrow to fetch the page that is overwritten.
I am using a commandLink to fetch the file.
Does anyone know why I am not getting a new window or tab for the display?
The jsp portion for the link is:
<h:commandLink action="#{MainPage.linkAction3_action}" id="linkAction3"
          style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 12px; font-weight: bold; left: 280px; top: 0px; position: absolute"
          target="_blank" value="Insurance Document"/>The "MainPage.linkAction_action" method just makes a call to the display function:
    public String linkAction3_action() {
        sb1.setMessage("");
        dsb.setFilePath("C:/");
        dsb.setFileName("Insurance_Summary.pdf");
        dsb.downloadPDF();
        return null;
    }And the downloadPDF() method is basically a cut and paste from the BalusC site;
    public void downloadPDF()
        // Reference:   http://balusc.blogspot.com/2006/05/pdf-handling.html
        // Prepare.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        File file = new File(getFilePath(), getFileName());
        BufferedInputStream input = null;
        BufferedOutputStream output = null;
        try {
            // Open file.
            input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
            // Init servlet response.
            response.reset();
            response.setContentType("application/pdf");
            response.setContentLength( (int)file.length());
            response.setHeader("Content-disposition", "inline; filename=\"" + fileName + "\"");
            output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
            // Write file contents to response.
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            int length;
            while ((length = input.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            // Finalize task.
            output.flush();
        catch( Exception e )
            System.out.println( "Error displaying file.");
        finally {
            // Gently close streams.
            close(output);
            close(input);
        // Inform JSF that it doesn't need to handle response.
        // This is very important, otherwise you will get the following exception in the logs:
        // java.lang.IllegalStateException: Cannot forward after response has been committed.
        facesContext.responseComplete();
    }

1) window.open will open a new window and call a servlet.
window.open ("http://path_to_yourservlet/PDFServlet", "newWindowName");
if you ant to pass some values from your web page to the servlet you can pass as
window.open ("http://path_to_yourservlet/PDFServlet?param1=value1&param2=value2", "newWindowName");
2) The servlet will fetch and display the pdf file.
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PDFServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
     private final static int DEFAULT_BUFFER_SIZE = 1000;
     public PDFServlet()
          super();
     public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
          String fileName = "Insurance_Summary.pdf";
          File file = new File("C:/"+fileName+"");
          response.setContentType("application/pdf");
     OutputStream output = response.getOutputStream();
     BufferedInputStream input = null;
     //BufferedOutputStream output = null;
     try {
     // Open file.
     input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
     response.setContentLength( (int)file.length());
     response.setHeader("Content-disposition", "inline; filename=\"" + fileName + "\"");
     output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
     // Write file contents to response.
     byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
     int length;
     while ((length = input.read(buffer)) > 0) {
     output.write(buffer, 0, length);
     output.flush();
     catch( Exception e )
     System.out.println( "Error displaying file.");
     finally {
     input.close();
Regards,
Milind Dhar

Similar Messages

  • Display pdf in a new window

    I need to display the pdf in a new window on click of a button in the iview. The pdf is fetched as an array of bytes from an RFC. It displays correctly, but in the same window. Pls see the extract of the code:
    To Write
    writeText(IPortalComponentRequest request, IPortalComponentResponse response, byte[] pdfResult)
    try{
    Document doc = new Document(PageSize.A4);
    javax.servlet.http.HttpServletResponse myResponse = request.getServletResponse(true);
    myResponse.setHeader ("ContentDisposition", "inline;filename=\"ShortCV.pdf\"");
    myResponse.setContentType("application/pdf");
    OutputStream os = myResponse.getOutputStream();
    os.write(pdfResult);
    PdfWriter.getInstance(doc,os);
    catch(Exception Ex){
    OnView(Event evt){
    JCO.Field Table1 = m_function.getExportParameterList().getField("PDF_STRING");
    client.execute(m_function);
    writeText(request, response, Table1.getByteArray());
    onView is called on
    Button myButton11 = new Button("myButton11");
    myButton11.setText("View");
    myButton11.setOnClick("View");
    myButton11.render(rendererContext);
    Pls advice

    See Display pdf in a new Window in a JSPDynPage

  • Problems opening .pdf files created in Windows in MAC

    My clients that are using Macs are having problems opening password protected PDFs that I created in Windows. Any suggestions?

    Are your clients using Adobe Reader on Mac, or the built-in Mac OS Preview?  Preview does NOT support the full PDF standard :(.
    From: Adobe Forums <[email protected]<mailto:[email protected]>>
    Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Date: Mon, 26 Sep 2011 15:04:18 -0700
    To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
    Subject: Problems opening .pdf files created in Windows in MAC
    Problems opening .pdf files created in Windows in MAC
    created by Hollcy<http://forums.adobe.com/people/Hollcy> in PDF Language and Specifications - View the full discussion<http://forums.adobe.com/message/3939175#3939175

  • Open a generated pdf file in new window

    Dear all,
    I'm using JDev ADF 11.1.1.4.0
    I use the command button method to generate pdf file with JasperReports and I store it into the public folder /reports/test5.pdf. To open this file I can use goLink or goButton with target frame _blank, but how can I open this file automatically after generation?
    I was reading about fileDownloadActionListener, but it's not what I need, I just want to open the file in new window browser.
    Any help will be appreciated.
    Regards,
    Wojtek.

    try this
    HttpServletResponse response = (HttpServletResponse) FacesContext
                                      .getCurrentInstance().getExternalContext().getResponse();
                       ServletOutputStream servletOutputStream;
                       servletOutputStream = response.getOutputStream();
                       byte[] bytes = null;
                       JasperDesign jasperDesign;
                                try {
                                        jasperDesign = JRXmlLoader.load(ios);
                                        jasperReport = JasperCompileManager.compileReport(jasperDesign);                
                                        JRPdfExporter exporter = new JRPdfExporter();
                                        JasperPrint jasperPrint;
                                        jasperPrint =
                                                JasperFillManager.fillReport( jasperReport, parameters, connection );
                                    } catch (JRException e) {
                                            e.printStackTrace();
                                bytes =
                                JasperRunManager.runReportToPdf(jasperReport,parameters, connection);
                       response.addHeader("Content-disposition", 
                       "attachment;filename=sale.pdf"); 
                       response.setContentType("application/pdf");
                       response.setContentLength(bytes.length);
                       servletOutputStream.write(bytes, 0, bytes.length);
                       servletOutputStream.flush();
                       servletOutputStream.close();
                       context.responseComplete();
                            } catch (IOException e) {
                        e.printStackTrace();
                    } catch (JRException e) {
                         e.printStackTrace();
                    }

  • How to make fileDownloadActionListener to open pdf file in new window

    Hi all ,
    i used the component [ fileDownloadActionListener ] to make download pdf file ,
    my question is
    How make this components to download and open file in new window ?
    Jdeveloper version 11.1.2.3

    Here is a sample http://technology.amis.nl/2011/07/28/adf-11g-show-pdf-in-a-popup/
    or http://mahmoudoracle.blogspot.de/2012/06/genius-adf-buttons.html#.UZygjrVM_Lk
    in General you can use the technique described here http://tompeez.wordpress.com/2011/12/16/jdev11-1-2-1-0-handling-imagesfiles-in-adf-part-3/ and configure hte browser to püen the doenloaded file using the configured application (pdf reader in your case).
    Timo

  • Display pdf in a new Window in a JSPDynPage

    I need to display the pdf in a new window on click of a button in the iview. The pdf is fetched as an array of bytes from an RFC. It displays correctly, but in the same window. Pls see the extract of the code:
    To Write
    writeText(IPortalComponentRequest request, IPortalComponentResponse response, byte[] pdfResult)
    try{
    Document doc = new Document(PageSize.A4);
    javax.servlet.http.HttpServletResponse myResponse = request.getServletResponse(true);
    myResponse.setHeader ("ContentDisposition", "inline;filename=\"ShortCV.pdf\"");
    myResponse.setContentType("application/pdf");
    OutputStream os = myResponse.getOutputStream();
    os.write(pdfResult);
    PdfWriter.getInstance(doc,os);
    catch(Exception Ex){
    OnView(Event evt){
    JCO.Field Table1 = m_function.getExportParameterList().getField("PDF_STRING");
    client.execute(m_function);
    writeText(request, response, Table1.getByteArray());
    onView is called on
    Button myButton11 = new Button("myButton11");
    myButton11.setText("View");
    myButton11.setOnClick("View");
    myButton11.render(rendererContext);
    Pls advice

    Detlev .....
    I am still not able to implement your suggested solution.
    If I call javascript written in JSP, will I be able to pass a bean to it. Pls see the code that I hv in addition to the one posted ...
    In ICellRenderer ....
    if ( column == 11 )
    Button myButton11 = new Button("myButton11");
    myButton11.setText("View");
    myButton11.setOnClientClick("Test("beantv2")");
    In JSP
    <script>
    function Test(zBean)
    popAssetWinSpecs = "left=250,top=250,width=300,height=300,scrollbars=no,toolbar=no,menubar=no,resizable=no,status=no,titlebar=no,location=no";
    htmlfile="/irj/servlet/prt/portal/prtroot/AIPLetters.HersheyTeamViewerAIPPDF?zBean="+zBean;
    window.open(htmlfile,"editWindow",popAssetWinSpecs);
    return false;
    </script>
    in the doInitialization of the second comp
    IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
    IPortalComponentContext compcontext = request.getComponentContext();
    AIPBean = new HersheyTeamViewerAIPBean();
    HttpServletRequest zHttpRequest = request.getServletRequest();
    AIPBean = (HersheyTeamViewerAIPBean)zHttpRequest.getAttribute("zBean");
    nothing gets executed ....
    I am not sure whether I am passing the bean correctly
    Thanks for your help,
    Devina

  • Problems displaying PDF files in browser - Help requested

    The scenario is that I visit a website that has information available via a link that normally would open a PDF document in a browser window.  The sort of document, that once open, if I clicked 'File-save as' in the browser would immediately save as a PDF file.  In the current situation I click on the link and all I get that opens is a screen full of random characters from top to bottom.  I have tried right click 'file save as' on the link that would open the PDF in the browser, but all it wants to save is a .PNG file, i.e. http://echa.europa.eu/echa-styled-theme/images/doc_lang/en.png - which is what I get from right click 'properties' on that link which should open the PDF in the brawser - normally I would see a .PDF file described. I therefore can't even download the file to open as a PDF direct from a stored location on my own PC - all it seems to see is the graphics format - this probably why when the browser goes to open the PDF file I get the random characters, i.e. the application is doing its best to translate what it does see.  I would be grateful for some advice.  Pertinant information follows:
    1.  It happens across more websites than just one example that I've quoted.
    2.  It happens on my desktop only - I don't have the problem on 4 other portable computers, including ones running the same O/S
    3.  Desktop is running Windows Home Pro, all updates executed, running the latest version of Acrobat reader with all updates executed - I tried yet another uninstall, reboot, new download, reinstall, reboot etc. yesterday.  Desktop is HP Pavillion with 12GB RAM
    4.  I get the random character display when running IE9 on the desktop, I have also replicated the problem with other versions of IE installed instead.  If I try using Chrome as a browser it goes away and tries and just fails to open the link entirely and reverts to the original page.
    5.  I've already checked online for similar problems and can confirm that all the Adobe plugins are installed per what seems standard advice I have also checked the internet settings in Adobe Acrobat preferences and all seems fine.
    6.  Thing like the browsers and Adobe arobat are running as per their standard set-ups with nothing else done to these.
    7.  Any other PDF files stored on the hard drive of the desktop open in Acrobat reader without problems
    8.  Acrobat reader version is 11.0.06.70
    Any assistance to open the PDF files in the browser and get it working particularly with IE would be great, I am quite IT literate and can try most things.  Many thanks

    Moderator
    I have no idea how to edit the above message, but apparently it has been rejected.  I cannot understand why, I am a regular contributor in many forums and have never suffered the indignity of having had a message rejected before.  The message contains an excellent example of the problems I am having in the following link Vacancies
    How on earth can I demonstrate the problems I am having without being to post an example - that example has both sorts of links on one page, ones I can open and ones I can't - if anyone with technical knowledge is trying to help me then that is just the sort of page that would be useful to help solve the problem.  Rather than the link to the ECHA website in the above posting (which I note was approved).  I struggle with your logic in accepting one message and rejecting the other.  It is difficult enough as a user to describe a problem in words let alone have the best example of the problem rejected without explanation and no right of appeal on the email that I got telling me.  Not happy here!   All I am trying to do is to solve the problem I have

  • .pdf file in new window and ...

    I've directed a link to go to a .pdf file.
    Everything is working, the links that is.
    But i have two minor problems:
    1 - is there a way to get a .pdf file to open in a new window?
    I don't see that option in the Inspector, like external pages, etc.
    has.
    2. when i open the .pdf file in the browser, at the very bottom of the page,
    in very small text, is listed the directory hiarchy of
    my computer,where I keep the .pdf file. Something like this:
    "Users/myname/folderrxxx/filexxx/file.pdf"
    All of this information about my computer and where i put the pdf file
    is showing at the bottom of each .pdf page when viewed in the browser.
    Is that normal? or is there a way to get rid of that?
    thanks!!

    You need to place the pdf file on the server/iDisk and link to it as an external page to have it open in a new window. The Inspector/Link window will provide the Open in new window option in that case.
    If you put the pdf file in your iDisk/Web/Sites folder the link to it would be:
    http://web.me.com/myname/file.pdf.
    I put most of those type of files in the iDisk/Pictures folder and the link to one there is:
    http://homepage.mac.com/myname/.Pictures/file.pdf. (note the period before Pictures)
    OT

  • Safari 3.0.3 won't open PDF files in new window & won't download to desktop

    When I click on a PDF file at a website Safari opens a new browser window but the window is always blank. The PDF file never appears. When I try to download the file to the desktop (right click) it doesn't download. I've read everything about the PDF problem posted at any relevant forum here. I've tried the Quicktime MIME approach. Didn't work. I've disabled the "open PDF in browser" option in Adobe Reader. Didn't work. I've looked for the Adobe plug-in to relocate. Didn't work. I downloaded Adobe Reader 8. Didn't work. When I make Adobe the default rather than Preview, Safari still doesn't open the PDF files or download them. Is there anyone in the computing world who actually can fix this problem? And why hasn't this recurring problem that has affected so many others been escalated to Apple for resolution???!!!

    Installing the newest version of Adobe Reader and restarting Safari fixed this issue for me.

  • How to open PDF file in new window as default

    I have .pdf documents into which I have inserted links to other .pdf documents using pdfEdit995
    (I am a 77-year-old pensioner recording monumental inscriptions, not very computer literate and not able to afford expensive applications !) 
    The links in the temp.ps file (which pdf995 creates first) look like :-
    [ /Rect [85 225 107 228]
    /Border [ 0 0 0 ]
    /Action /Launch /File (.\\Another Folder\\TARGET FILE.PDF)
    /Subtype /Link
    /ANN pdfmark
    The links work fine, but open in the same window, which is annoying as it is then neccessry to re-open the original document, scroll down to the required page and find the next link.
    pdf995 support say that perhaps Adobe reader can be set to open in a new window, but I want this to be the default when I circulate my file to interested people, so would prefer to modify the links.
    Can anyone help with a smple solution ? (I also believe in Santa Claus !)
    System: Vista; Reader X 10.1.0

    I don't know if you can change this in the PS file, but if you had Acrobat you could embed the following code into your file, that will make sure the links open in a new window. However, you should be aware that this code will change the preferences at the application level, which some people might not appreciate.
    The code is:
    app.openInPlace = false;

  • Problem opening excel file in new window

    Hi,
    I have a JSF application that sends an Excel file back to the user.
    My backing bean has a method that uses POI to generate the excel file and then write it to the servlet response.
    This works fine if I call the method from a command button, but this displays the file in the current browser window, whereas I want to open the file in a new window.
    I added an onclick javascript call to a command button which does a window.open() to open a jsp in a new window. The jsp contains an empty view, as I'm using an on-load phase listener to make the call to my backing bean method which should send the excel file when the file opens.
    However, when the window opens, I get an IE error message saying 'Could not open xxx.faces', and then an excel error message saying 'Could not open xxx.xls. This may be because the file does not exist, or the file is already open etc etc'
    However, I found that if the popup window goes through a servlet (which just forwards to the jsp page) instead of going to the jsp directly, it works like a charm.
    Any ideas or suggestions on how to fix this would be very much appreciated. If I can't fix it I'll just stick with the servlet approach, although it just seems a bit messy.
    (I'm using IE6 SP2, tomcat 5.5 btw)
    Cheers,
    Stuart

    I'm doing a similar thing, but I use commandLink to lauch the window. CommandLink has the "target" attribute that I set to _blank.  As you would expect, that opens up the page in the new window.                                                                                                                                                                                                                                                                                                                                                                                                       

  • Link to open pdf file in new window

    I want to create a link on a web page to open a pdf file in a
    new window. I used the "on click" "open brower window". Which does
    open the pdf file, but not in a new window. How do I open it in a
    new window?

    Your code is a mess:
    ** there is no apparent reason for the span:
    <td><span class="style1"
    onfocus="MM_openBrWindow('pdf/PR_launch.pdf','','')">Milford, OH
    So change that line to:
    <td>Milford, OH
    ** here you have two double quotes before This.
    <a title="”This" class="pdfFile"
    onclick="MM_openBrWindow('pdf/PR_Launch.pdf','','')"
    Change it to this, (with some other improvements):
    <a title="This" class="pdfFile"
    onclick="MM_openBrWindow(this.href,'','');return false"
    ** This is code salad:
    href="”PR_Launch.pdf”" link="" will="" open="" a=""
    .pdf=""
    file.”="">More (PR_Launch.pdf,
    230kb)</a></span></td>
    Change it to:
    href="pdf/PR_Launch.pdf">More (PR_Launch.pdf,
    230kb)</a></td>
    If you continue to have trouble, you might find my divaPOP
    Extension
    easier, and far more powerful. It automat6ically opens pdf
    files and
    links to all external files in a popup window without your
    needing to
    code each link:
    http://www.divahtml.com/products/divaPOP/open_popup_windows.php
    E. Michael Brandt
    www.divaHTML.com
    divaPOP : standards-compliant popup windows
    divaGPS : you-are-here menu highlighting
    divaFAQ : FAQ pages with pizazz
    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, et alia

  • Please help to open PDF file in new window

    Hi!
    I have a My.pdf file, and file Other.pdf located in subfolder Myfolder.
    For example, my.pdf located on c:\Mydocs\My.pdf and Other.pdf located in c:\mydoc\Myfolder\Other.pdf
    I try make plugin that open Other.pdf in subfolder Myfolder, no matter in where My.pdf is located on computer.
    I found in SDK API, that I need create a new window for open pdf file, using WinAPI function - CreateWindow:
    HWND externHWnd = CreateWindow ("ExternalWindow", "PDFViewer",WS_OVERLAPPEDWINDOW,50, 50, 500, 500, 0, 0, gHINSTANCE, NULL);
    I copy example into Visual Studio, but in example there no gHINSTANCE is undeclared.
    or plese provide working code for my task
    Please help

    In which part of the SDK did you look.
    Do you really mean a plugin (control Acobat from inside - can only be written using C#)
    oder do you mean control/work with Acrobat from an external application (like vb,..) via activeX (=IAC).
    br, Reinhard

  • Display .doc file in new window by url

    Hi all,
    I hope someone got a quick an easy solution for this one.
    I want to access and display (open/save) a .doc file in a new separate window by using createExternalWindow(docUrl, xxx, xxx), where docUrl is a path on the local webAS. Right now I access the file like this:
    File doc = new File("apps/local/filename.doc");
    wdComponentAPI.getWindowManager().createExternalWindow(doc.getURL(), "", false).open;
    This does not work though, since it gives me the absolute path from the hard drive letter and down, ie: c:/usr/sap/../filename.doc
    We havent installed Office Integration on our webAS.
    Anyone? All help help is appreciated. This doesn't feel like it should be a big issue?!
    Best regards,
    Andreas

    Andreas,
    Here is probably not the optimal and not the most intuitive way to perform this task, but anyway:
    1. In View controller context create attribute with type <b>binary</b>, let us name it <b>MyDoc</b>
    2. In View controller source define private variable
    private ISimpleType _msWordType
    3. In View controller wdDoInit method place the following:
    _msWordType = wdContext
      .getNodeInfo()
        .getAttribute("MyDoc")
          .getModifiableSimpleType();
    ((IWDModifiableBinaryType)_msWordType).setMimeType( WDWebResourceType.DOC );
    ((IWDModifiableBinaryType)_msWordType).setFileName( "MyMsWordDocument.doc" );
    4. Use the following docUrl when calling createExternalWindow
    /* Load document content first */
    final byte[] documentContent = loadDocumentBytes();
    /* And now the trick itself */
    final String docUrl = _msWordType.format( documentContent );
    We successfully apply this technique to display photo from employee profile loaded from database
    VS

  • A problem displaying PDF file in the Web Browser layout.

    I'm hoping someone can help me with this issue.  I need to display my PDF documents in the web-browser layout as part of my daily job.  I use JAWS 14, and many times, when my document is launched, it comes up blank, or at least that's what JAWS reports.  If I press the F5 key to refresh the page, then it displays properly.  I need the document to show up properly when it is initially loaded.  How can I accomplish this?    

    I'm hoping someone can help me with this issue.  I need to display my PDF documents in the web-browser layout as part of my daily job.  I use JAWS 14, and many times, when my document is launched, it comes up blank, or at least that's what JAWS reports.  If I press the F5 key to refresh the page, then it displays properly.  I need the document to show up properly when it is initially loaded.  How can I accomplish this?    

Maybe you are looking for