Printing a HTML page in a JTextPane

Hi all..
I nned to develop a report generating system for one of the softwares that I am writing and I am planing to generat the report as a HTML page (both text and images) and users can preview them on a JTextPane and can save to disk as html files for further use.
I also want to add functionality to the application to print the report through java.
what I want to do is to print what is displayed in JTextPane (Content Type: text/html)
I am familiour with Printable interface what I cant figure out is how to make the JTextPane printable and how to send the data in JTextPane to printers Graphic object
Can somebody give a sample code for this.
Also if you know any other way of printing a HTML formated text without use of any other componant like JTextPane please tel me how to do it.

We had done the same using the JEditor Pane and later print the JEditorPane using the print API..
Here is the code to include the html file.
mainPane = new JEditorPane("file:///C:/project/JavaPrintingAPI/AddGlobalProduct.html");
mainPane.setEditable(false);If it work... hungry for yummy dukes... :-)

Similar Messages

  • Print JSP/HTML Pages (perhaps PDF?)

    Hi,
    i have a table in HTML generated by JSP.
    Just like the following simple example:
    ...<table>
    <%
    for( Enumeration et = free.getSqlIDs().elements(); et.hasMoreElements();)
    String keyt = (String)et.nextElement();
    Bean b = new Bean();
    b.init(path,DB);
    b.setID(keyt);
    b.restore();
    %>
    <tr>
    <td>
    <%out.print(b.getName());%>
    </td>
    <td>
    <%out.print(b.getAdress());%>
    </td>
    </tr>
    %>
    </table>...
    No i want to give a button to the user. When pressed, the HTML-Page should transform to PDF.
    With such a method i want to print the HTML-Page.
    I Know that this is possible with the help of XML/XSP and a stylesheet. But i like to do that with this way:JavaBeans-->JSP-->HTML-->PDF
    Anyone a solution, some code examples for me?
    Or perhaps another solution to print HTML-Pages in a fine design?
    Thank you for your help
    Andy

    Hi,
    no one any idea?
    How do you print Jsp Pages?
    Thank you
    Bye
    Andy

  • Script to print an html page in both sides (duplex printing)

    Hi,
    I have a website that can print page automatically without showing the print dialog box. Now, user's have requirement to print the page in both sides.
    Is there any vbscript/javascript that will auto print the html page in both sides (duplex)
    Thank You!

    Hello,
    This should be asked in Microsoft's ASP.Net forums:
    http://forums.asp.net/
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?&lt;=\G.{2})'|%{if($_){[char][int]&quot;0x$_&quot;}})

  • JEditorPane printing a HTML PAGE

    Hi,
    Here is my problem. I am displaying a HTML Page in a JEditorPane. So far so good.
    when I try to print is printing to my printer. Here is the problem the Text or to say the font doesnot look good in the paper, each letter is not nice and smoth and it looks like some of the pixels in each letter were lost. This happens right when I initialize the JEditorPane with html code. I can also see the pixels in each letter are lost when I initilized it in a JEditorPane.
    Any help will be appreciate.

    How are you printing? Are you using the Printing API?
    You can try antialiasing the text before printing:
    http://www.exampledepot.com/egs/java.awt/AntiAlias.html

  • Printing of HTML pages on OTN

    There are lots of great article's on OTN. For example, http://otn.oracle.com/oramag/webcolumns/2003/techarticles/marinescu.html
    Unfortunately, it is not easy to print these articles in a clean fashion. Would you add a "Printable View" option to pages like this so I can print the article without all the garbage and sidebar information?

    Jon...this is a new feature that we are investigating. Please stay tuned....

  • How to avoid header and footer parts while printing a html page to pdf ?

    Am trying to convert a page from a web site and trying to printing it. i see the file  root folder , destination  and location of the page (file:// D|/file_name/filename001/][time stamp]) at the bottom of the pdf is there any option to disable this ?

    File :: Create :: PDF from Web Page
    In the dialog that presents - click the "Settings" button.
    In the dialog that presents - untick "Place headers and footers on new page"
    Be well...

  • Firefox crashes when I try to print a html page to my laser printer

    I used to be able to print html and pdf files to my laser printer when in Firefox, but now I get an alert that Firefox will crash. I check the box to send info to Firefox, but when I entered "about crashes" as suggested below, I got nothing but a 404 number showing and some text about not having information about crashes "on this server." Does anyone know of a fix for this?

    Post your question on the Firefox forums, as Apple discussion only provide support for Apple products:
    http://forums.mozillazine.org/index.php?c=4

  • Problem in Printing HTML page

    While I am trying to print a HTML page using window.print(), the bgcolor of the table is not printing.

    Did you consider inquiring about this at a Javascript or HTML forum?

  • Printing HTML PAGE in a Applet

    I am tryng to print a HTML Page in a Applet .
    When Using Eclipse Environment everythig goes fine.
    Now I am trying to use the appletviewer to run the same
    source, but it appears the following:
    http://10.15.1.26/
    Conecting to http://10.15.1.26/
    Exception in thread "AWT-EventQueue-2" java.lang.RuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission 10.15.1.26:80 connect,resolve)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
         at java.net.HttpURLConnection.getResponseCode(Unknown Source)
         at javax.swing.JEditorPane.getStream(Unknown Source)
         at javax.swing.JEditorPane.setPage(Unknown Source)
         at javax.swing.JEditorPane.setPage(Unknown Source)
         at javax.swing.JEditorPane.<init>(Unknown Source)
         at AppletPrintHTML$EditorPaneHTMLViewer.loadStartingPage(AppletPrintHTML.java:90)
         at AppletPrintHTML$EditorPaneHTMLViewer.<init>(AppletPrintHTML.java:103)
         at AppletPrintHTML$5.actionPerformed(AppletPrintHTML.java:364)
         at java.awt.Button.processActionEvent(Unknown Source)
         at java.awt.Button.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 10.15.1.26:80 connect,resolve)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    Why I am not allowed to connect to the site without Eclipse? Any Idea?
    Angel Portal

    This code
              * Load a HTML Page
              private void loadStartingPage() {
              try {
                   System.out.println("Conectando a "+ path);
                   mainPane = new JEditorPane(path);
                   } catch (IOException e) {
                        System.err.println("N�o Pode Conectar");
                        System.exit(1);
    Open a html page ( path ) on JEditorPane!
    In Eclipse worked just fine!
    But if I try to do that on a Browser or appletviewer the error a told you shows up.
    I am reading about the The Permission Classes.Someone have heard of it?

  • Printing HTML PAGE

    Java has some Class to handle HTML Pages.
    I want to build a Button that is able to print the
    actual page of the Browser.
    I know about ClipBoard Class, SomeOne has
    some Idea how to do this?
    The idea is to create an applet that creates a button
    to print the actual HTML page.
    Some Idea how to do this, or where I can get this
    information?
    Angel -Portal

    Hello, I got your advise and I could write a small program
    to open a URL ,put it in a JEditorPane like you sad.
    public class EditorPaneHTMLViewer extends JEditorPane implements Printable {
    Inside the code I create a menu to change to portrait to landscape.
    But now I need somehow to print the HTML Page that I took from
    internet.
    I believe that I need to load the content of the JEditorPane to a graphics
    and then set to a Format of a Page and Print, but I do not know how yet.
    Some Hint.
    That true that I could do in a easiest way in JavaScript. But it is going to
    be possible to do landscape and portrait?
    Angel Portal: [email protected]

  • Problems printing html page created from servlet

    Hi
    How do I go about to print a html page that spans outside the visible window (to the left). All I get when I print is the visible page.
    Is it at all possible?
    Would appreciate an answer.
    Thanks
    David Mossberg

    No, not impossible to do.
    You need to provide a printer friendly version of the content so that it spans correctly.
    Again, this is not a Java problem this is an Application problem.
    How you format the data is down to you.

  • Printing html pages from JSF-JSC created pages

    Hi all,
    I have a serious problem with my web apps created with JSC using the JSF components. I designed a page full of tables, developed in vertical for a total of about three or four pages scrolling down.
    When I try to print the generated page from the browser (Firefox, Safari, Explorer) I always get just the first 'page', the entire webpage generated by my application is not saw as a long page, but just 'cutted' out.
    It seems like all JSF components have some problems being like layers or so...any hint? How can I print my html page generated by my web app?
    G

    Perhaps viewing the source of the generated html page will give you a clue to what's wrong..

  • Printing a HTML doc from a JEditor Pane

    I would like to print a HTML page from a JEditorPane. I've searched trhough the web, but haven't found any free libs yet... Does anybody have some tips?

    See
    JEditorPane.setPage(URL)
    once you've done that and its rendered you should be able to print by using my StandardPrint class. Search for StandardPrint.java on this site

  • Opening INTRANET HTML Page

    I did a small software to print an HTML Page.
    But now I have to make it to work on my Office
    in a intranet environment.
    For the http://www.homepage.com/ I used plane String.
    But now I have to use in a intranet. Someone know
    the changes that I have to do to make it work?
    I read I small code the uses the class URL and
    uses Properties props = System.getProperties(); to set up
    proxys data. It is the way? Someone has passed for the
    same trouble?
    Angel Portal

    I did the source based on the Java HomePage source.
    Take a Look!
    import java.applet.Applet;
    import java.awt.Dimension;
    import java.awt.Event;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.HeadlessException;
    import java.awt.Button;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.geom.Point2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Pageable;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import java.io.IOException;
    import javax.swing.JComponent;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JScrollPane;
    import javax.swing.KeyStroke;
    public class AppletPrintHTML extends Applet {
         private static final long serialVersionUID = 1L;
         private Button buttonPrint = null;
         private EditorPaneHTMLViewer MyPanel;
         public AppletPrintHTML() throws HeadlessException {
              super();
              // TODO Auto-generated constructor stub
         * This method initializes this
         * @return void
         public void init() {
              this.setSize(75, 33);
              this.add(getButtonPrint(), null);
         * This method initializes buttonPrint     
         * @return java.awt.Button     
         private Button getButtonPrint() {
              if (buttonPrint == null) {
                   buttonPrint = new Button();
                   buttonPrint.setLabel("Imprimir");
                   buttonPrint.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.out.println("Botao Imprimir");
                             // TODO Auto-generated Event stub actionPerformed()
                             MyPanel = new EditorPaneHTMLViewer ("http://10.15.1.26/");
                             add (MyPanel);
              return buttonPrint;
         public class EditorPaneHTMLViewer extends JFrame {
         * @author Angel Portal
              * Inicializa��o das Vari�veis Globais ao Sistema
         private JComponentVista vista;
         private String path;
         private JEditorPane mainPane;
         PrinterJob printJob = PrinterJob.getPrinterJob();
         PageFormat landscape_portrait = printJob.defaultPage();
              private JMenu menu = new JMenu("File");
              private JMenu menu01 = new JMenu("Op��es");
              private JScrollPane content;
              private int FrameSizeY=550;
              private int FrameSizeX=750;
              private static final long serialVersionUID = 1L;
              private JScrollPane createScrollPane() {
                   JScrollPane editorScrollPane = new JScrollPane(mainPane);
                        editorScrollPane.setPreferredSize(
                                  new Dimension(700,500));
                   return editorScrollPane;
              * Carrega a P�gina HTML
              private void loadStartingPage() {
              try {
                   System.out.println("Conectando a "+ path);
                   mainPane = new JEditorPane(path);
                   } catch (IOException e) {
                        System.err.println("N�o Pode Conectar");
                        System.exit(1);
              * Construtor do EditorPaneHTMLViwer
              public EditorPaneHTMLViewer(String url) {
              super("Pagina Aberta no Painel do JAVA");
              path = url;
              loadStartingPage();
              JMenuBar mb = new JMenuBar();
              JMenuItem item01 = new JMenuItem("Exit");
              JMenuItem item02 = new JMenuItem("Imprimir");
              JMenuItem item03 = new JMenuItem("Retrato");
              JMenuItem item04 = new JMenuItem("Paisagem");
              item01.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,Event.CTRL_MASK));
              item02.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,Event.CTRL_MASK));
              item03.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,Event.CTRL_MASK));
              item04.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,Event.CTRL_MASK));
              item01.addActionListener(new ActionListener()
                                  public void actionPerformed(ActionEvent e01) {
                                       // TODO Auto-generated method stub
                                       System.out.println("Saindo");
                                       System.exit(0);
              item02.addActionListener(new ActionListener()
                                  public void actionPerformed(ActionEvent e02) {
                                       // TODO Auto-generated method stub
                                       printJob = PrinterJob.getPrinterJob();
                                       vista = new JComponentVista(mainPane,landscape_portrait);
                                       vista.scaleToFitX();
                                  printJob.setPageable(vista);
                                  try {
                                  if (printJob.printDialog()) {
                                       System.out.println("Imprimindo");
                                       printJob.print();
                                  }catch (Exception PrintException) { System.out.println(PrintException);}
              item03.addActionListener(new ActionListener()
                                  public void actionPerformed(ActionEvent e03) {
                                       // TODO Auto-generated method stub
                                       System.out.println("Portrait");
                                       landscape_portrait.setOrientation(PageFormat.PORTRAIT);
              item04.addActionListener(new ActionListener()
                                  public void actionPerformed(ActionEvent e04) {
                                       // TODO Auto-generated method stub
                                       System.out.println("LandScape");
                                       landscape_portrait.setOrientation(PageFormat.LANDSCAPE);
              mainPane.setEditable(false);
              menu.add(item02);menu.add(item01);
              menu01.add(item04);menu01.add(item03);
              mb.add(menu);
              mb.add(menu01);
              add(mb);
              setJMenuBar(mb);
              vista = new JComponentVista(mainPane ,new PageFormat());
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              content = createScrollPane();
              setContentPane(content);
              setSize(FrameSizeX,FrameSizeY);
              setVisible(true);
              public void main(String[] args) {
                   //Schedule a job for the event-dispatching thread:
                   System.out.println(args[0]);
                        new EditorPaneHTMLViewer(args[0]);
              * Comjunto de Classes para Impress�o de Component Java
              public class Vista implements Pageable {
                   private int mNumPagesX;
                   private int mNumPagesY;
                   private int mNumPages;
                   private Printable mPainter;
                   private PageFormat mFormat;
                   public Vista(float width,float height,Printable painter,PageFormat format) {
                        // TODO Auto-generated method stub
                        setPrintable(painter);
                        setPageFormat(format);
                        setSize(width,height);
                   protected Vista() {
                        // TODO Auto-generated method stub
                   protected void setPrintable(Printable painter) {
                        mPainter = painter;
                   protected void setPageFormat(PageFormat pageFormat) {
                        // TODO Auto-generated method stub
                        mFormat = pageFormat;
                   protected void setSize(float width,float height) {
                        // TODO Auto-generated method stub
                        mNumPagesX = (int) ((width+mFormat.getImageableWidth()-1)/mFormat.getImageableWidth());
                        mNumPagesY = (int) ((height+mFormat.getImageableHeight()-1)/mFormat.getImageableHeight());
                        mNumPages = mNumPagesX*mNumPagesY;
                   public int getNumberOfPages() {
                        // TODO Auto-generated method stub
                        return mNumPages;
                   protected PageFormat getPageFormat() {
                        return mFormat;
                   public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
                        // TODO Auto-generated method stub
                        if(pageIndex >= mNumPages) {
                             throw new IndexOutOfBoundsException();
                        return getPageFormat();
                   public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
                        // TODO Auto-generated method stub
                        if(pageIndex >= mNumPages){
                             throw new IndexOutOfBoundsException();
                        double originX = (pageIndex % mNumPagesX)*mFormat.getImageableWidth();
                        double originY = (pageIndex / mNumPagesX)*mFormat.getImageableHeight();
                        Point2D.Double origin = new Point2D.Double(originX,originY);
                        return new TranslatePrintable(mPainter,origin);
                   private final class TranslatePrintable implements Printable {
                        private Printable mPainter;
                        private Point2D mOrigin;
                        public TranslatePrintable(Printable painter,Point2D origin) {
                             mPainter = painter;
                             mOrigin = origin;
                        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
                             // TODO Auto-generated method stub
                             Graphics2D g2 = (Graphics2D) graphics;
                             g2.translate(-mOrigin.getX(),-mOrigin.getY());
                             mPainter.print(g2,pageFormat,1);
                             return PAGE_EXISTS;
              public class JComponentVista extends Vista implements Printable {
                   private double mScaleX;
                   private double mScaleY;
                   private JComponent mComponent;
                   public JComponentVista(JComponent c,PageFormat format){
                        setPageFormat(format);
                        setPrintable(this);
                        setComponent(c);
                        Rectangle componentBounds = c.getBounds(null);
                        setSize(componentBounds.width,componentBounds.height);
                        setScale(1,1);
                   protected void setComponent(JComponent c) {
                        // TODO Auto-generated method stub
                        mComponent = c;
                   protected void setScale(double scaleX, double scaleY) {
                        mScaleX = scaleX;
                        mScaleY = scaleY;
                   public void scaleToFitX() {
                        PageFormat format = getPageFormat();
                        Rectangle componentBounds = mComponent.getBounds(null);
                        double scaleX = format.getImageableWidth()/componentBounds.width;
                        double scaleY = scaleX;
                        if ( scaleX < 1 ) {
                             setSize((float) format.getImageableWidth(),
                                       (float) (componentBounds.height*scaleY));
                             setScale(scaleX,scaleY);
                   public void scaleToFitY() {
                        PageFormat format = getPageFormat();
                        Rectangle componentBounds = mComponent.getBounds(null);
                        double scaleY = format.getImageableHeight()/componentBounds.height;
                        double scaleX = scaleY;
                        if ( scaleY < 1 ) {
                             setSize((float) (componentBounds.width*scaleX),
                                       (float) format.getImageableHeight());
                             setScale(scaleX,scaleY);
                   public void scaleToFit(boolean useSymmetricScaling){
                        PageFormat format = getPageFormat();
                        Rectangle componentBounds = mComponent.getBounds(null);
                        double scaleX = format.getImageableWidth()/componentBounds.width;
                        double scaleY = format.getImageableHeight()/componentBounds.height;
                        System.out.println("Scale: " + scaleX + " " + scaleY);
                        System.out.println("Componente X = " + componentBounds.width);
                        System.out.println("Componente Y = " + componentBounds.height);
                        if(scaleX < 1 || scaleY <1 ) {
                             if(useSymmetricScaling) {
                                  if(scaleX < scaleY) {
                                       scaleY = scaleX;
                                  } else {
                                       scaleX = scaleY;
                             setSize((float) (componentBounds.width*scaleX),
                                       (float) (componentBounds.height*scaleY));
                             setScale(scaleX,scaleY);
                   public int print(Graphics graphics, PageFormat pageformat, int pageIndex) throws PrinterException {
                        // TODO Auto-generated method stub
                        Graphics2D g2 = (Graphics2D) graphics;
                        g2.translate((int)pageformat.getImageableX(),(int)pageformat.getImageableY());
                        Rectangle componentBounds = mComponent.getBounds(null);
                        g2.translate(-componentBounds.x,-componentBounds.y);
                        g2.scale(mScaleX,mScaleY);
                        boolean wasBuffered = mComponent.isDoubleBuffered();
                        mComponent.paint(g2);
                        mComponent.setDoubleBuffered(wasBuffered);
                        return PAGE_EXISTS;
    } // @jve:decl-index=0:visual-constraint="136,10"
    As you can see I used String to pass to the Applet the url that I wish to display!. Works!
    But now I am changing to the class URL in the new code, so there is a
    methods like this:
    path = new URL(url);
    and ...
              Properties props = System.getProperties();
              props.put("https.proxyHost", "webcache1.eng");
              props.put("https.proxyPort", "8080");
    I also find it in the Sun Home Page.
    I believe that I can access https://www.homepage.com/ with this lines!
    I garantee that you can just access http://www.homepage.com/ with the
    code above!!!!!
    Angel Portal

  • Print HTML-Page

    Hi, i want to print a HTML-formated Page without the tags and whit pictures in the page, i think thats also called WYSIWYG. How i can do this ? Is there a possiblility to convert HTML to printerfriendly format like RAW ?

    maybe you can't got the printer coz your printer didn't support the html flavor like me.
    My printer is HP-400 Monochrome. As far I have explore. I just can print txt files :(
    There's my code and the error msg.
    ---my code----
    //Example: PrintHTML.java
    import java.io.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import javax.print.event.*;
    public class PrintHTML {
         public static void main(String args[]) {
              PrintHTML ps = new PrintHTML();
         public PrintHTML() {
              /* Construct the print request specification.
              * The print data is Postscript which will be
              * supplied as a stream. The media size
              * required is A4, and 2 copies are to be printed
              DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_HOST;
              PrintRequestAttributeSet aset =
                   new HashPrintRequestAttributeSet();
              aset.add(MediaSizeName.ISO_A4);
              aset.add(new Copies(2));
              aset.add(Sides.TWO_SIDED_LONG_EDGE);
              aset.add(Finishings.STAPLE);
              /* locate a print service that can handle it */
              PrintService[] pservices = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.JPEG, null);
              PrintService service = ServiceUI.printDialog(null, 50, 50, pservices, pservices[0], flavor, aset);
              System.out.println("Print Services Located");
              if (pservices.length > 0) {
                   System.out.println("selected printer " + pservices[0].getName());
                   /* create a print job for the chosen service */
                   DocPrintJob pj = pservices[0].createPrintJob();
                   System.out.println("Create PrintJob succed");
                   try {
                        * Create a Doc object to hold the print data.
                        * Since the data is postscript located in a disk file,
                        * an input stream needs to be obtained
                        * BasicDoc is a useful implementation that will if requested
                        * close the stream when printing is completed.
                        FileInputStream fis = new FileInputStream("test.html");
                        Doc doc = new SimpleDoc(fis, flavor, null);
                        /* print the doc as specified */
                        pj.print(doc, aset);
                        * Do not explicitly call System.exit() when print returns.
                        * Printing can be asynchronous so may be executing in a
                        * separate thread.
                        * If you want to explicitly exit the VM, use a print job
                        * listener to be notified when it is safe to do so.
                        System.out.println("Udh selesai ngeprint.");
                   } catch (IOException ie) {
                        System.err.println(ie);
                   } catch (PrintException e) {
                        System.err.println(e);
    ---error messages---
    Exception in thread "main" java.lang.IllegalArgumentException: text/html; charse
    t="cp1252"; class="java.io.InputStream" is an unsupported flavor
    at sun.print.Win32PrintService.getSupportedAttributeValues(Win32PrintSer
    vice.java:903)
    at sun.print.ServiceDialog$MediaPanel.updateInfo(ServiceDialog.java:1683
    at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:
    1051)
    at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:332)
    at sun.print.ServiceDialog.<init>(ServiceDialog.java:149)
    at javax.print.ServiceUI.printDialog(ServiceUI.java:161)
    at PrintHTML.<init>(PrintHTML.java:34)
    at PrintHTML.main(PrintHTML.java:11)

Maybe you are looking for