Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing problem in java

 
Chintala Reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to print a html file using javax.print
see the attached code.
Problems
1) The cods is working but printing the file contents (including used html tags)
2) I have specified the page format as landscape but it is printing as per default (portrait).


Code:
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc((InputStream) new FileInputStream(new File("c:\\a.html")), flavor, null);
PrintService psZebra = null;
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
if (services.length >= 0) {
psZebra = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = psZebra.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
aset.add(new Copies(3));
job.print(doc, aset);

} else {
return;
}

Plz suggest the solution.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chintala, do want to have Server Side or Client Side printing? Do you have web based application?
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is working perfectly. You are sending an HTML file to the printer and printing its contents. What you want to do is print how the HTML looks in a browser. You will need to render the HTML using a text component and print that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic