meiya 0 Report post Posted April 24, 2008 salam semua... ade tak otai2 java dalam ni.. diharapkan dapat membantu... aku nak buat satu coding java ni.. die akan get HTML file/code dan kemudian die akan printkan output HMTL ni...so masalahnye skarang ialah, aku boleh print tp die akan kelaur output HTML code to sendiri...yang aku nak ialah die akan keluarkan output macam dalam web browser..aku dah try search kat google, tp setakat ni tak jumpe lagi solution..kalau ade sape2 terer java..leh la kasi idea kat aku coding aku mcm ni :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) { } } }}output yang aku dapat lak( yang aku nak output die mcm dalam browser tu, bukan html code ni) :<html><body><div style="page-break-after:'always'; background-color:#EEEEEE; width:400; height:70"> testPrint</div>ABCDEFGHIJK<p> </p></body></html>thanks in advanced Quote Share this post Link to post Share on other sites
unexistance 3 Report post Posted April 24, 2008 pakai JEditorPane Quote Share this post Link to post Share on other sites
meiya 0 Report post Posted April 24, 2008 pakai JEditorPaneoo.... kalau pakai JeditorPane ni mmg kena taruk ke url die tu...kalau nak suruh die build frame dgn HTML code yang kita pastu boleh ke? lgi satu aku nak terus print je, tanpa display HTML tu... eniwei, thanks for reply Quote Share this post Link to post Share on other sites
unexistance 3 Report post Posted April 24, 2008 0. boleh letak 'http://' atau 'file:///' atau HTML kod tu wrap dalam URL constructor (kalau tak silap aku la)1. tak paham..2. g: jeditor print Quote Share this post Link to post Share on other sites
meiya 0 Report post Posted April 30, 2008 0. boleh letak 'http://' atau 'file:///' atau HTML kod tu wrap dalam URL constructor (kalau tak silap aku la)1. tak paham..2. g: jeditor printthank for reply...masalah aku dah settle..aku draw balik gune java graphics.. mmg JEditorPane boleh view HTML, tapi kalau aku setkan panel tu as visible-false (sebab mmg tak nak view pun HTML tu)and convert to Graphics, masa print akan kuar kosong je...so, tak nak aku gune graphic je... thanks for the idea Quote Share this post Link to post Share on other sites