Open PDF file in a new browser window

I have a PDF file on the harddrive and I call a function from BalusC :
public static void downloadPDF(FacesContext facesContext, String path, String fileName)
util.Logger.append("Path = " + path );
util.Logger.append("file name = " + fileName);
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
File file = new File(path, fileName);
BufferedInputStream input = null;
BufferedOutputStream output = null;
try
//open file
util.Logger.append("1");
input = new BufferedInputStream(new FileInputStream(file), 10240);
//Init servlet response
util.Logger.append("2");
response.reset();
util.Logger.append("3");
response.setContentType("application/pdf");
util.Logger.append("4");
response.setContentLength((int)file.length());
util.Logger.append("5");
response.setHeader("Content-disposition", "inline; filename=\"" + fileName + "\"");
util.Logger.append("6");
output = new BufferedOutputStream(response.getOutputStream(), 10240);
util.Logger.append("7");
//write file contents to response
byte[] buffer = new byte[10240];
int length;
util.Logger.append("8");
while ((length = input.read(buffer)) > 0)
output.write(buffer, 0, length);
util.Logger.append("9");
//finalize task
output.flush();
util.Logger.append("10");
catch (IOException e)
util.Logger.append("reporting.Utilities :: downloadPDF :: " + e.getMessage());
finally
util.Logger.append("finally");
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 logs:
//java.lang.IllegalStateException: cannot forward after response has been comitted
facesContext.responseComplete();
private static void close(Closeable resource)
if (resource != null)
try
resource.close();
catch (IOException e)
e.printStackTrace();
This works like a charm, but the problem is that the PDF is opened in current window instead of a new one. I checked posts on this problem on this forum but i haven't found any answer to my problem. As you can see i added some 'idiot' logs just to make sure i have no errors. I see them all in my log file and there is absolutely no error. I simply see the PDF in the same window.
Can anyone help me, please?
Thank you.
(Pls tell me if you need any other information)

My problem is that the parent form has 4 buttons and a grid.
3 buttons are Add/Edit/Delete for records in the grid. Only the 4th button is the Print report and this is the only one i need to open in another page.
Even if I create another page and I navigate to it, setting target of newly created page to open a new window will bring me the problem of having 2 windows to close once users wants to close the PDF which is kind of awkward.
What is your advice?
Thank you
Marius

Similar Messages

  • Open pdf's, documents in new browser window SharePoint 2010

    Hi all,
    when a user clicks on pdf's, documents, html pages etc in a document library I need them to open in a new browser window. I've found lots of articles on how to do it in 2007 but none work in 2010. I know its not an out of the box function but people
    have done it with Java script or adding code to the document library allitems.aspx web part, I just can't replicate those steps in 2010.
    I'm not a developer or anything but can put code in the right place using SharePoint designer 2010.
    Pulling my hair out at the mo,
    please help
    thanks in advance

    Create a Document Library called ScriptLibrary.
    Download the Jquery library here: http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js
    Create a new file called: OpenPDF.js
    Paste the following Code in the file:
    $("A[href$=.pdf]").click(function() {
          window.open(this.href);
    Upload both files to your newly created ScriptLibrary.
    The ScriptLibrary should have 2 files: jquery-1.4.4.min.js and OpenPDF.js
    Navigate to the List Page that has the PDF's that you need opened in a new window.
    Click Site Actions: Edit Page,
    Insert > Content Editor WebPart
    Click to Edit the HTML Source of the HTML WebPart, then paste in the following to reference the two files you uploaded to your Script Library:
    <script type="text/javascript" src="/ScriptLibrary/jquery-1.4.4.min.js" ></script>
    <script type="text/javascript" src="/ScriptLibrary/OpenPDF.js" ></script>
    *The src needs to point to the files you uploaded
    Save the page then click on a PDF, it should open in a new window.
    You can then export that ContentEditorWebPart to your webpart gallery, and just insert the webpart on any page that needs the same functionality.

  • Open another website in a new browser window

    I can't seem to create links to external websites that open
    as intended in a new browser window while leaving the main browser
    window unchanged. Except in Safari on a Mac. See sample code.
    In Safari on a Mac this opens the new window and behaves as I
    want. In Safari on a PC it opens a new window, but in back. In
    Firefox on Mac I get an error message in which, when the "OK"
    button is cliked on, a new window opens in back of the main window.
    Same thing on a PC. Internet Explorer on a PC opens a new window
    but displays an error message forcing you to clik the back button
    to return to the main page.
    If I specify the main page url in the link field, then the
    main page gets reset to the top, which I don't want.
    How can I get FireFox and IE to accomplish this gracefully?
    To observe behavior go to
    http://www.digifon.com/framesetal_id.htm

    Don't use Frames. However, the issue of opening a new window
    is still
    hotly debated. My own approach is to mark the link with an
    icon and
    then to open a new window (or tab if the user prefers). If
    done
    properly with javascript, this will not spawn a myriad of
    windows and
    Standards-compliant. (And further, if javascript is off, the
    new page
    will simply open in the current window.)
    Based on this philosophy, I offer a DW Extension that makes
    adding this
    behavior dead simple. Here is an example of a page that uses
    it to good
    advantage. Despite all the external links and pdf links on
    the page,
    the Extension only needed to be added once to the page,
    rather than
    adding it to each and every link. Links added to the page
    AFTER the
    Extension is applied are ALSO acted on, a great time saver in
    my
    opinion, and easy on the user:
    http://squamscott.org/scc_green.asp
    The DW Extension is available here:
    http://divahtml.com/products/divaPOPgold/open_popup_windows.php
    E. Michael Brandt
    www.divahtml.com
    www.divahtml.com/products/scripts_dreamweaver_extensions.php
    Standards-compliant scripts and Dreamweaver Extensions
    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, et alia

  • Dreamweaver - Chrome open a video in a new browser window not working

    Hi guys, i'm pretty novice to dreamweaver and i've putting a site together recently...
    One thing i am trying to do is open a video in a new browser window when the button is clicked upon.
    I have done what i thought i needed to do this, and in safari and other browsers this works fine. In Google Chrome however this doesn't seem to want to work and rather then opening and playing the video it just automatically starts to download it.
    I'm sure it is a simple fix and i apologise for the thread all about it but any help would be appreciated.
    http://hauntingskateboards.co.uk/media.html
    if you click on Joe or Dean button you should see what I mean... anyway thanks in advance!

    Create Pop-Up Window in DW Behaviors Panel
    http://alt-web.blogspot.com/2012/03/create-pop-up-window-in-dreamweaver.html
    Nancy O.

  • I cannot open PDF files on my new MacAir

    My new MacAir does not let me open PDF files.  What do I need to do to allow downloads

    By default, the Safari browser is enabled to view remote PDF documents by left-clicking the associated document link. The alternative, would be to right click on the remote PDF link, and choose, Download Linked File As… which pops a Save As… dialog. Each of these approaches is exactly how my new MBA worked right out of the box. Your MBA should work this way by default, too.
    In Safari Preferences > Security, uncheck Internet plug-ins, Allow Plug-ins. Close preferences. Choose Safari > Reset Safari with the following selected:
    Press Reset, and exit Safari. Relaunch Safari, go to Apple’s Manual site, and pick any of these PDF. If PDF viewing is restored, then something that you added as an Internet Plug-in is compromising normal Safari PDF viewing.
    Local PDF viewing is accomplished through /Applications/Preview.

  • Open sso enabled app in new browser window

    I have a java app deployed to OAS and secured with Single Sign on. I would like my app to open a report and display it in a new browser window. When the new window opens I am getting an error stating that user is not authorized to access the report. This is due to the session information (successful login) being stored with the cookie in the original browser window (where the session started and where the user originally logged in). Is there a way to pass that cookie information to the 2nd browser window...or some way to re-authenticate without having the user log on again...possibly some mod_osso set-up...or some additional code? TIA.

    Hi Durairaj,
    The thing is that I did not get the desired answer to my query and the thread was posted in a wrong forum thus I have the query again inthe correct forum.
    Regards,
    Sweta.

  • Opening a URL in a new browser window

    Hello Experts,
    I am trying to open a dynamic url in a new browser window from a Portal application (travel and expenses). Basically, when a user clicks on the submit button, Badi IF_EX_TRIP_WEB_CHECK~USER_CHECK_CHANGES is called. In the BaDI, we have added code to concatenate a parameter to a url and then open a new browser window with that url. This works perfectly in r/3 using a tcode (pr_web_1200) but when I use the portal application under ESS, the window does not open and no error message is issued. We are using METHOD cl_gui_html_viewer->detach_url_in_browser. Any idea why this is not working through ESS in Portal? Is there some other method that we need to use? Any help is appreciated.
    Regards,
    Sal

    check....
    Re: Open Portal Transaction iView in new window *without* Browser window
    for iView (page) you probably set the property 'Launch in New Window' to value Display in Separate Window. To tune up the other otions you have the possibility to set the property Window Features, value should contain toolbar=no. These features will be used when Javascript opens up your window - you can apply any option coomonly documented. IMHO for your demands the best option is fullscreen=yes,toolbar=no - you get really the maximum possible size.

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

  • Opening a state in a new browser window?

    How to open a link button..(the link button actually changes the state of the page) but i want to open that in a new browser window....
    Any help....

    check....
    Re: Open Portal Transaction iView in new window *without* Browser window
    for iView (page) you probably set the property 'Launch in New Window' to value Display in Separate Window. To tune up the other otions you have the possibility to set the property Window Features, value should contain toolbar=no. These features will be used when Javascript opens up your window - you can apply any option coomonly documented. IMHO for your demands the best option is fullscreen=yes,toolbar=no - you get really the maximum possible size.

  • Problem opening pdf files with Adobe Reader in Windows 7

    I bought a new Dell (Inspiron 5110) with pre-installed Windows 7 Home Premium (Version 6.1 SP1, 64 bit) and pre-installed Adobe Reader X (10.1.1). I cannot open ANY of my old pdf files with the Adobe reader (even after I re-installed the Adobe Reader). On another computer with Windows 7 I get the same error message. When I installed several other pdf-readers (Sumatra, Foxit, ..) I can still not open the pdf's -- but all the pdf's still open under Windows XP on my old computer and they also open on all my colleagues' non-Windows 7 computers. So it appears to be a Windows 7 problem. The Adobe error message says 'Adobe Reader could not open _.pdf because it is either not a supported file type or because the file has been damaged (…..).
    N.B.: I can download pdf files from the internet and can then open these 'new' pdf files with Adobe Reader X.
    N.B.2.: Most of the 'old' pdf files are scientific articles downloaded from various journal websites 2002-2011, so their quality should be out of question.
    N.B.3.:I've transfered the files via memory stick and portable HD.
    N.B.4.: If I try to open the pdf's via 'Open with' the problem remains the same.
    N.B.5.: When, on my Win7 Dell, I've uploaded/attached one of these old pdf files to an email the rtecipient could not tead it. But he could read it when I'd sent the same file from my old Win XP computer.
    N.B.6.: I have repeated this last observation: When I upload an old pdf file on my Win7 Dell to my email account and then send it to myself, I cannot open/read it on my Win XP (nor on the Dell, of course). Although the file size is precisely the same.
    N.B.7.: When I download a new pdf on my Dell, then upload/attach it to an email also on the Dell and send it to myself, I can download and read the attached pdf on both computers.
    Would be grateful for any suggestions.

    This is really strange.
    Please correct me if I am wrong, but from what I can understand, any PDF which is launched on your Win 7 OS fails to open, even though the same file works perfectly fine on your Win XP machine?
    Could you please run a full system anti virus scan on the said PDFs that are present on your local system. It could be a case of infected PDFs.
    Also, it would be great if you could try and download some of the erroneous PDFs from the web again, and see if you experience the same behavior.
    Thanks
    Ankit

  • Open the HTML attachment in new browser window

    Hi all,
    There is a Bsp application in which the table view has list of all attachmnets.
    When I click on a cell a popup opens asking whether the file is to be opened , saved or cancel.
    When I click on open then if it is a TXT attachment it opens in a notepad but if it is an HTML attachmnet it gets opened in the same browser window instaed of a new one.
    What do i do to open the HTML attachment in a new Beowser window.
    Regards,
    Sweta.

    Hi Durairaj,
    The thing is that I did not get the desired answer to my query and the thread was posted in a wrong forum thus I have the query again inthe correct forum.
    Regards,
    Sweta.

  • Firefox 30.0 - Used to open PDF file in a new tab when clicked a link. Now new tab opens, does not show file, tab closes. How do I fix it?

    I am using Firefox 30.0. I open a page that has links on it to see some PDF files. When I click on the link, Firefox use to open a new tab and display the PDF file. Now a new tab is opened, nothing gets displayed, and the new tab closes. What setting do I need to change in order to see the PDF file.

    Firefox Menu > Settings > Application
    *Search for "PDF" > Change the Action to "Preview in Firefox"

  • When "Use Google Instant", "Open search results in a new browser window." does not function.

    In the "Google Search Setting", if select "Do not use Google Instant", then the selected search result of Google Search will be displayed in a new window, but if "Use Google Instant", the selected result will replace Google Search window. This problem does not exist when using Chrome Browser.

    That does what it says - even if Google tells the browser to open the page in a new window, you have told Firefox to ignore that and open it in a new tab. Uncheck the box and you should get the result you want.

  • Open a view in a new browser window

    Hi Experts,
    Can you pls guide me to open a new window ( Browser) on clicking a Button, Currently I could open a window but it looks like popup.
    In my case I want a separate browser to be opened.
    Please advice.
    Regards,
    Bala

    There are actually only 2 options:
    -- external browser window via URL (separate WD application is started)
    -- internal (non-movable non-resizable) modal window inside main application window.
    first at the html page, add the code:
    <script language="javascript">
    function openwindow(){
    window.open("view");
    </script>
    in the page_load event,add the code:
    private void Page_Load(object sender, System.EventArgs e)
    this.ImageButton1.Attributes.Add("onclick","openwindow()");
    Message was edited by:
            Kanwalpreet

  • Opening PDF files on a new Mac Pro

    I'm running Leopard X.5.7 and updated to the latest Adobe Reader. However, trying to open some PDF files including my Mac Pro Manual offers the pop-up, "You can't open the application because it is not supported on this architecture." If I use "Quick Look" the PDF does open. Do you have a solution so I don't have to use Quick Look? Never had a problem with Reader on any Mac until this new one. Thanks.

    f the 20" is ADC (rounded connector, squeeze clips, no power cord) you will need a DVI to ADC adapter.
    <http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore.woa/wo/2.RSLID?mco= 7DCD62DB&nplm=M8661LL%2FB>

Maybe you are looking for

  • ORA-19511 Media Management Error

    I am getting following error while taking the backup to tape using OSB: RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: ======================

  • Problem with screen size in Premiere Pro CS5?

    I'm making a movie in Premiere Pro CS5 and I've ran into a problem with the screen size. The source screen shows my footage in widescreen (16:9) but my project screen is playing the widescreen footage in standard size (4:3) so it is cutting off some

  • Alternate t-code for SCOT

    Is there any alternate t-code for SCOT where i can send / post mails one by one. Regards, Ashish.

  • MacBook Pro...Need to access/change computer administrator but don't know it in the first place?  Bought this used...

    I have MacBook Pro i bought used 2-3 yrs ago.  Needing to make some changes and need to access computer administrator.  I just realized i do not know what it is.  Can someone help me access and/or change the computer administrator's password?

  • Using PCI-6251 with Labview 6.1

    I recently purchased a PCI-6251 multifucntion DAQ board to get a higher sampling rate than my old PCI-MIO-16E-4 board.  However I have existing software that I want to run on the new board.  The board came with NI-DAQmx which will only work with Labv