• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing directly to printer

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

I am working on a small app that chooses a file and when I click the print button it will simply print the file to the chosen printer(from the printDialog()).

I have looked at numerous tutorials and examples but most of them refer to printing components from swing or loading the file into a textarea before printing the text from that textarea.

I would like to know if there is a simple way of implementing the feature I am after and possibly some helpful code if kind enough.

I have also tried the Desktop class but opens the associated app to use its print feature.

Thank you

DP
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Unfortunately, there is no way to "simply print a file". Java knows what to do with certain file types (e.g. text and PostScript), but in general only an application that knows what to do with a given file format can print a file (say, a web browser for an HTML file, or Adobe Reader for a PDF file). That's why the Desktop class uses the application that "owns" the file to print it.

A smart printer can help (e.g., some printers know what to do with PDFs), but generally they need something like PostScript or PCL as input, not just any file format.
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic