Java/j2ee - Printing the file(without priview) located in Application server.

Posted on 2009-12-21
Last Modified: 2012-05-08
I have developed a JAVA BEEN which currently able to print the file located in my local PC to my default printer configured (without opening doc).

I have placed the file in remote HTTP/apache server and configured same to access the file using the URL. Which is also working fine
(Like    http://server-name:port/interface-dir/test.pdf.)
Now I have requirement to print the same remote file just by passing the input as URL to above java code. ( as http is only the way to access file located on the app server).

Please advise how to achieve this. Or any there way
Question by:mansur_mca
    LVL 14

    Assisted Solution

    How are you printing now?

    You can create a File instance with a URL:

    File(URI uri)
              Creates a new File instance by converting the given file: URI into an abstract pathname.

    Then create a FileInputStream with that file:
    FileInputStream(File file)
              Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.

    Read from stream and print.
    Or pass this to whatever mechanism you are using for printing.

    LVL 92

    Expert Comment

    can you post the code you use to print the file?
    LVL 1

    Author Comment


    you have given an excellent solution, I will pass to this info to my team and update you.  

    please let me know, your above solution can do PDF file printed just like normal file print view format usually we see?

    if not, to bring file print on pages like as normal file print ( formatted), is there still method are available.

    kindly please let me know the update for the above.

    If the above soultion does work, then I will let you know about coding
    LVL 92

    Accepted Solution

    you can't create a File from a http url
    you instead need to change your existing code to accept a URL instead of a File
    If thats not possible then you need to first download the file
    LVL 14

    Assisted Solution

    Bah, objects is correct, Sorry about that.
    There is a File constructor that takes a URI but this won't work in yoru case. You need to download the file or otherwise handle the URL.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now