File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Printing problem in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Printing problem in java" Watch "Printing problem in java" New topic
Author

Printing problem in java

Chintala Reddy
Greenhorn

Joined: Jun 19, 2006
Posts: 2
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

Joined: Sep 16, 2004
Posts: 3636
Chintala, do want to have Server Side or Client Side printing? Do you have web based application?


My blood is tested +ve for Java.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8877
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Printing problem in java