How to print a local file from jsp

Hi,
I want to print a local file(eg. .doc,.pdf) from a jsp.
Please help me with any answer or any example code
Thanks in advance
Regards,
Sanjeev

Try this:
index1.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Link rel='alternate' media='print' href=null>
<script Language=JavaScript>
function setPrintPage(prnThis){
prnDoc = document.getElementsByTagName('Link');
prnDoc[0].setAttribute('href', prnThis);
window.print();
</script>
</head>
<body >
<a href="#" onclick="setPrintPage('index.jsp');"> Click to Print </a>
</html>This will print index.jsp without opening it in browser. Hope this helps!

Similar Messages

  • How to open a local file from javascript in a jsp-page

    Hi
    I have created an iview from a PAR file. In the par file I have a jsp-page with some javascript code. From the javascript coe I want to open a new window with an Excel file.
    I have tried window.open("c:
    test.xls", "test_window"), but it doesn't seem to work. I have created a small HTML page locally with the same command and there a new window opens with the Excel file.
    If I change the local file path with an URL it also works.
    Any idea how to open a local file ?
    Thanks
    /Jakob

    Jacob,
    I'm not 100% (but 99,9%) and it has to do with security ristrictions of the browser not allowing to have local workstation interation from the web. This is ofcourse very dangerous if the browser would allow it... So therfore it is blocked. What if somone would point to a file/executable that formats your drive so for that reason it is not allowed to have web interaction with a local file. Only with Java Applets this is possible but still with many limitations, and what I remember Google Gears and Adobe Air do have some limited web 2 local file interaction... So best and most simple solution you are left with is pointing to a url instead of a file on a c:\ drive.
    PS The reason why it works when you start the html from your local PC has todo with the fact that the browser detects that the html is not running in the web at that moment therefor allowing the access.
    Cheers,
    Benjamin Houttuin

  • Open a Local file from JSP

    Hi All,
    I want to access a local file from a JSP. On click of the link the local file should open. The location of the local file is
    O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
    and the hyper link on the JSP shows
    file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
    somehow the file does not open from the JSP page but it opens from the browser if I type
    'file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc' in the address bar.
    Can anybody please help.
    regards,
    Shardul.

    if you'd like to show the real path to the user, use simply an ftp server !
    however, if you prefer a secure solution, so use a servlet:
    example:
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class SendWord extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
        //get the 'file' parameter
        String fileName = (String) request.getParameter("file");
        if (fileName == null || fileName.equals(""))
          throw new ServletException(
              "Invalid or non-existent file parameter in SendWord servlet.");
        // add the .doc suffix if it doesn't already exist
        if (fileName.indexOf(".doc") == -1)
          fileName = fileName + ".doc";
        String wordDir = getServletContext().getInitParameter("word-dir");
        if (wordDir == null || wordDir.equals(""))
          throw new ServletException(
              "Invalid or non-existent wordDir context-param.");
        ServletOutputStream stream = null;
        BufferedInputStream buf = null;
        try {
          stream = response.getOutputStream();
          File doc = new File(wordDir + "/" + fileName);
          response.setContentType("application/msword");
          response.addHeader("Content-Disposition", "attachment; filename="
              + fileName);
          response.setContentLength((int) doc.length());
          FileInputStream input = new FileInputStream(doc);
          buf = new BufferedInputStream(input);
          int readBytes = 0;
          while ((readBytes = buf.read()) != -1)
            stream.write(readBytes);
        } catch (IOException ioe) {
          throw new ServletException(ioe.getMessage());
        } finally {
          if (stream != null)
            stream.close();
          if (buf != null)
            buf.close();
      public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
        doGet(request, response);
    }hope that helps

  • How to Print  a PDF file from within a ABAP ( from gui input)

    Hi champions,
    This is Client requirement:
    "We need to print a PDF file from within a ABAP"
    We first need to test whether it is even feasible, and then if it 
    is, then write a small test ABAP which can accept a PDF file
    name as input (from GUI) and then print it to a SAP print
    device (printer).”
    Please Can any body help me on this.......
    It's urgent
    Thanks
    Basu

    Check following blog for PDF output from SAP
    /people/thomas.jung3/blog/2005/04/28/setting-up-an-adobe-writer-for-abap-output
    anya

  • How to print a pdf file from Labview

    Hi,
    Does anyone know how to print a pdf file form Labview. I need to be able to point on the pdf file and to print it.
    Activex examples doesnt seem to be working it always displays an error, on every PC that I tryed to run it.
    {"code 3005" ,,,"Automation Open: Object specified is not creatable in Display PDF in Dialog.vi"}.
    Thank you for your help.
    Regards,
    Jenia.

    You can use the "System Exec.vi". The command line should have the following structure:
    "<Path to AcroRd32.exe>" /t "<Path to document>" "Printer name"
    For example"
    "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /t "C:\myreport.pdf" "Tektronix Phaser 300i"
    Regards;
    Enrique
    www.vartortech.com

  • How to read a local file from Applet Code

    Hi
    I am developing a application and i want to access a local file from the applet
    So pls help me in coding for this

    You can't do that, at least not with an unsigned applet.
    Sign your applet and it should work just like normal file access.

  • How to call java class file from jsp

    hi
    we need to call java classes (which are written separately in .java file )from jsp file. we need it for our project if anyone knows about please reply us.
    bye
    siva sankari

    you can call the methods in a lot of ways. you could use scriptlets with the
    <%@ page import="package.class"%> and then inside instantiate an object
    <%
         MyClass mc = new MyClass(parameters if any);
         mc.theMethodYouWantToCall();
    %>or as Madathil has stated,
    or use the JSP tags
    <jsp:useBean id="anyname" class="classname"/>and then use the getProperty tag
    or even Custom Tags

  • How to retrieve a local file from a portal report.

    Hi,
    I need to access a local htm file from my local directory. I stored the filename in
    a table. And I built a portal report to select the filename from the table. The filename
    in the report will be link to a procedure that I created to pass the filename. The
    procedure code is as follow:
    (v_filename in varchar2) IS
    url varchar2(100);
    BEGIN
    url := 'uploaddoc/'&#0124; &#0124;v_filename;
    portal30.wwv_redirect.url(p_url =>url);
    END;
    Then in the httpd.conf file, I put in an alias like this:
    I put an alias in the httpd.conf file like this:
    Alias /uploaddoc/ "C:\My_Data\uploaddoc/"
    I stopped the http server and restarted it after I made the changes.
    When I run the report, I click on the filename link: in my example,it is:
    internal_portal_faq, the filename is passed to the procedure that I created.
    But I got the following error message on the browser:
    No DAD configuration Found
    DAD name:
    PROCEDURE : internal_portal_faq
    URL : http://localhost:80/pls/portal30/uploaddoc/internal_portal_faq
    I am running on version 3.07 on NT on my laptop.
    Any idea what I did wrong?
    P.S. I don't want to upload the file using a portal form into the blob field.
    Thanks;
    Kelly.
    null

    Hi,
    I found out a way to do this myself. If anyone is interested in that, just drop me an email.
    Kelly.
    null

  • How to print names all files from a given folder into a file??

    Hi,
    Given is folder which contains folder's n files. the same is wd every folder.
    How to print names of all files in parent dir.
    ex: C drive
    1) windows 2)prog files 3) Documents 4) a.txt
    1.a) cursors.........
    2.a) netbeans.....
    3.a) rcm_b05
    output:
    c:\windows\cursors\s.txt
    c:\progfiles\ram\m.tc
    a.txt

    Hi,
    look at http://exampledepot.com/egs/java.io/TraverseTree.html, copy the "visitAllFiles" method and implement the "process" method as follows:
        public static void process(File f) {
            System.out.println( f.getAbsolutePath());
        }- Michael

  • How to print a pdf file from reader?

    We have Reader X1 and cannot print a pdf file. Although it says 'print', it only allows us to save the file

    Go to the Printer's properties and make sure that the "Print to File" box is not ticked.

  • How to print a PDF file from Swing(JFC/swing)

    Hi,
    I am able to dislay a PDF file in Swing but how can I print it from there. I want to do it without using Acrobat reader.

    You can use the "System Exec.vi". The command line should have the following structure:
    "<Path to AcroRd32.exe>" /t "<Path to document>" "Printer name"
    For example"
    "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /t "C:\myreport.pdf" "Tektronix Phaser 300i"
    Regards;
    Enrique
    www.vartortech.com

  • How to create a text file from jsp?

    In JSP, what is the command to create a text file and dump a variable in it?

    You mean StringBuffer?

  • How to read a local file from Forms10g using PJC/Bean

    I'm trying to read a file on the client machine using a Bean.
    The code in the Bean is:
    File fp = new File(mFileName);
    printToConsole( "AFTER creating a File object " );
    if (fp.exists())
    I get the message after creating File object. But at the next statement - fp.exists() - the Forms session terminates giving a FRM-92100 - Your connection to the server was interrupted.
    Any ideas?
    Thanks in advance for your help.
    Amit

    Frank, Thank you for your response on signing the jar. That was exactly what I was missing. After signing the jar, I am able to do client level operations.
    Grant, Thank you for asking about WebUtil. To give you a background as to what we are trying to do - to integrate our Forms 10g application with another software - in this case a client-server app. We want to send a message from this app. to our Forms10g app.(a pre-defined Form in the app.) which would initiate certain Forms navigation based on the message. In essence, Forms needs to be "listening" to this app. (in a non-blocking mode, the Forms app. should not be "locked-out" while listening for a message)
    The only way I could think of was to write a Bean (modified version of Frank's Dispatch Event sample on his blog) which would spawn a thread and listen for a message from the other app. For our prototype, I started off with watching for a file on the client machine. The final goal is to listen for a message on MQ. This will facilitate us to integrate our Forms10g app. with any other app.
    Regarding WebUtil, I did not find a way to do the listening/polling in a non-blocking way. Maybe I must have missed the obvious - Frank can very well attest to that.
    Any feedback is most welcome.
    Thanks.
    Amit

  • How to execute oracle reports file from jsp using WL as an app server

    I plan to use jsp to accept IN parameters and later want to execute oracle
              report execute stored in some directory and provide results back to the
              client browser window. Is this possible in JSP + WL? If yes, can you
              provide some tips on the code?
              Thanks.
              

    Try
    sqlplus "sys/oracletest as sysdba" @bpk.sql
    Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
    Remember to put an exit at the end of the bpk.sql script.

  • How do I print a pdf file from windows 8?

    I can't find a command to print a pdf file. I'm working with windows 8. can anybody tell me how do I find that command?

    Please see FAQ: How to print a PDF file from Adobe Reader Touch.
    Starting from version 1.1, Adobe Reader Touch supports printing.
    If you do not see the Print button in the toolbar, you have an older version of Adobe Reader Touch. Please download and install the latest version of Adobe Reader Touch via the Windows Store.

Maybe you are looking for

  • AIRPORT EXRESS with airtunes - MAC MINI RECEPTION

    HI MAC BOFFS, I have just managed to configure a an airport express with airtunes, and managed to get it on the network, but music keeps dropping from the remote speakers. When i get sound it is excellent quality but only for a few seconds. I have no

  • Video playback = periodic restarts

    Recently, my video iPod has started to restart/reboot itself in the middle of video playback. This only happens occasionally, not all the time. Maybe every 30 minutes or so. I don't have any videos from the iTunes Store -- these have all been encoded

  • Cold Fusion MX and Windows 7

    Hi, has anyone had experience with installing CF MX on a Windows 7 system? I had trouble with Vista. I am planning to buy a new computer and they are all on Windows 7. I want to make sure if I will be able to have my CF MX installed on it without hav

  • Actionscript 3 and _self

    Hi Guys, I'm trying to get a page to load in the same tab, instead of creating a new tab (like HTML target=""_self" instead of _blank) I've tried a few different things I've found on different forums, nothign seems to be working though This is what I

  • Printing from ipad4

    Would anyone be kind enough to explain the best way to print to my eprinter from my ipad4?  I've got Docs2Go, Evernote, Doc2, and Dropbox apps installed. I've tried all of them but with the exception of Dropbox, I can't seem to find the print option