0

Is it possible to print a file (txt, image, pdf, ...) to a printer using its path?

For example:

I have a file in C:\directory\file.txt. Can I give this path to java and launch a print command to printer?

SlimenTN
  • 3,383
  • 7
  • 31
  • 78
  • By printing, I suppose you mean to a printer? – fge Jan 12 '15 at 12:53
  • @fge yes I mean printer – SlimenTN Jan 12 '15 at 12:54
  • Oh, an actual printer. I thought you were talking about the console. – user123 Jan 12 '15 at 12:55
  • 1
    http://stackoverflow.com/questions/3687184/java-check-if-file-is-in-print-queue-in-use <- Look at the accepted answer here. – user123 Jan 12 '15 at 12:57
  • You'll have to be able to read the file first. Either by implementing that functionality yourself (a bad idea in most cases) or by using someone elses implementation. – blalasaadri Jan 12 '15 at 12:59
  • the file that I want to print can be a txt, pdf or image.So I need a way to print it without reading it. – SlimenTN Jan 12 '15 at 13:03
  • possible duplicate of [Connecting and printing to a printer in Java](http://stackoverflow.com/questions/6278405/connecting-and-printing-to-a-printer-in-java) – Thomas Weller Jan 12 '15 at 13:03
  • Very basic answer - yes you can. You really need to show that you've had a go at this and any code samples you've tried / problems you've had. Have a look at the questions linked in comments above - basically all pointing you to the javax.print package. Tutorial here: http://docs.oracle.com/javase/tutorial/2d/printing/, API docs here: http://docs.oracle.com/javase/7/docs/api/javax/print/package-frame.html – J Richard Snape Jan 12 '15 at 13:26

1 Answers1

1

try this
String file_path = "C:\directory\file.txt"
Desktop.getDesktop().print(new File(file_path));

iosgloding
  • 11
  • 1