How to print a HTML file in browser look using DocPrintJob

Hello guys,
Does anyone know how to print HTML output/file into browser look?
I'm using DocPrintJob and the DocFlavor set to DocFlavor.INPUT_STREAM.AUTOSENSE.
posted below is my code :
public class BasicPrint {
    public static void main(String[] args) {
        try {
            // Open the image file
            String testData = "C:/new_page_1.html";
            InputStream is = new BufferedInputStream(new FileInputStream(testData));
            DocFlavor flavor =  DocFlavor.INPUT_STREAM.AUTOSENSE;
            // Find the default service
            PrintService service = PrintServiceLookup.lookupDefaultPrintService();
            System.out.println(service);
            // Create the print job
            DocPrintJob job = service.createPrintJob();
            Doc doc= new SimpleDoc(is, flavor, null);
            // Monitor print job events; for the implementation of PrintJobWatcher,
            // see e702 Determining When a Print Job Has Finished
            PrintJobWatcher pjDone = new PrintJobWatcher(job);
            // Print it
            job.print(doc, null);
            // Wait for the print job to be done
            pjDone.waitForDone();
            // It is now safe to close the input stream
            is.close();
        } catch (PrintException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
    static class PrintJobWatcher {
        // true iff it is safe to close the print job's input stream
        boolean done = false;
        PrintJobWatcher(DocPrintJob job) {
            // Add a listener to the print job
            job.addPrintJobListener(new PrintJobAdapter() {
                public void printJobCanceled(PrintJobEvent pje) {
                    allDone();
                public void printJobCompleted(PrintJobEvent pje) {
                    allDone();
                public void printJobFailed(PrintJobEvent pje) {
                    allDone();
                public void printJobNoMoreEvents(PrintJobEvent pje) {
                    allDone();
                void allDone() {
                    synchronized (PrintJobWatcher.this) {
                        done = true;
                        PrintJobWatcher.this.notify();
        public synchronized void waitForDone() {
            try {
                while (!done) {
                    wait();
            } catch (InterruptedException e) {
}the printed ouput for this code will be look like this
<html>
<body>
<div style="page-break-after:'always';
            background-color:#EEEEEE;
            width:400;
            height:70">
     testPrint</div>
ABCDEFGHIJK<p>
 </p>
</body>
</html>however, the output that i want is the HTML in browser look not HTML code itself.
i've tried to change the DocFlavor into any TEXT_HTML type but it gives error:
sun.print.PrintJobFlavorException: invalid flavor if you guys has any idea or solution, can you share with me... already search in Google but still not found any solution
Thanks in advanced.
Advertisement
Reply

hi,
do the following
URL url = null;
try
     url = new URL("http://www.xyz.com");
catch (MalformedURLException e)
      System.out.println("URL not correct " + e.toString());
if (url != null)
       getAppletContext().showDocument(url,"_blank"); //shows the page in a new unnamed top level browser instance.
}hope that helpz
cheerz
ynkrish