Print JEditorPane Contents

Hi friends,
In my billing application i use JEditorPane and set some billing document. If i want to print the contents which one is correct.
1.
editPane.print(null, null, false, null, null, false);or
2.use print job and attributes. I used the 2 method but i cant hide the print dialog box.
so please help me.

Don't double post. I've removed the thread you started 27 minutes after your last response on this one, with the same question.
db

Similar Messages

  • How to print jEditorPane content

    Hi,
    I have got the html content in jeditorPane and i wanted to print the content to the printer in landscape mode. can any one help me out?, I appreciate your time . Infact i did see an example here but when i started running it, i could end up no where.
    Thanks,
    krishna

    infact the example i saw in this forum, rythos , is the author but i could not make the code he posted there working. I would appreciate if some one can take interest into it.
    Below is the Rythos Code :
    import javax.swing.*;import java.awt.*;import java.awt.image.*;import java.io.*;import java.util.*;import javax.print.*;import javax.print.attribute.*;import javax.print.attribute.standard.*;import javax.print.event.*;import javax.swing.text.*;import javax.imageio.*;import javax.imageio.stream.*;/** * Sets up to easily print HTML documents. It is not necessary to call any of the setter * methods as they all have default values, they are provided should you wish to change * any of the default values.*/public class Printer {     public static int DEFAULT_DPI = 72;     public static float DEFAULT_PAGE_WIDTH_INCH = 8.5f;     public static float DEFAULT_PAGE_HEIGHT_INCH = 11f;     int x = 100;     int y = 80;     GraphicsConfiguration gc;     PrintService[] services;     PrintService defaultService;     DocFlavor flavor;     PrintRequestAttributeSet attributes;     Vector pjlListeners = new Vector();     Vector pjalListeners = new Vector();     Vector psalListeners = new Vector();     public Printer() {          gc = null;          attributes = new HashPrintRequestAttributeSet();          flavor = null;          defaultService = PrintServiceLookup.lookupDefaultPrintService();          services = PrintServiceLookup.lookupPrintServices( flavor, attributes );          // do something with the supported docflavors          DocFlavor[] df = defaultService.getSupportedDocFlavors();          for( int i = 0; i < df.length; i++ )               System.out.println( df.getMimeType() + " " + df[i].getRepresentationClassName() );          // if there is a default service, but no other services          if( defaultService != null && ( services == null || services.length == 0 ) ) {               services = new PrintService[1];               services[0] = defaultService;          }     }     /**     * Set the GraphicsConfiguration to display the print dialog on.     *     * @param gc a GraphicsConfiguration object     */     public void setGraphicsConfiguration( GraphicsConfiguration gc ) {          this.gc = gc;     }     public void setServices( PrintService[] services ) {          this.services = services;     }     public void setDefaultService( PrintService service ) {          this.defaultService = service;     }     public void setDocFlavor( DocFlavor flavor ) {          this.flavor = flavor;     }     public void setPrintRequestAttributes( PrintRequestAttributeSet attributes ) {          this.attributes = attributes;     }     public void setPrintDialogLocation( int x, int y ) {          this.x = x;          this.y = y;     }     public void addPrintJobListener( PrintJobListener pjl ) {          pjlListeners.addElement( pjl );     }     public void removePrintJobListener( PrintJobListener pjl ) {          pjlListeners.removeElement( pjl );     }     public void addPrintServiceAttributeListener( PrintServiceAttributeListener psal ) {          psalListeners.addElement( psal );     }     public void removePrintServiceAttributeListener( PrintServiceAttributeListener psal ) {          psalListeners.removeElement( psal );     }     public boolean printJEditorPane( JEditorPane jep, PrintService ps ) {          if( ps == null || jep == null ) return false;          // get the root view of the preview pane          View rv = jep.getUI().getRootView( jep );          // get the size of the view (hopefully the total size of the page to be printed          int x = ( int ) rv.getPreferredSpan( View.X_AXIS );          int y = ( int ) rv.getPreferredSpan( View.Y_AXIS );          // find out if the print has been set to colour mode          DocPrintJob dpj = ps.createPrintJob();          PrintJobAttributeSet pjas = dpj.getAttributes();          // get the DPI and printable area of the page. use default values if not available          // use this to get the maximum number of pixels on the vertical axis          PrinterResolution pr = ( PrinterResolution ) pjas.get( PrinterResolution.class );          int dpi;          float pageX, pageY;          if( pr != null ) dpi = pr.getFeedResolution( PrinterResolution.DPI );          else dpi = DEFAULT_DPI;          MediaPrintableArea mpa = ( MediaPrintableArea ) pjas.get( MediaPrintableArea.class );          if( mpa != null ) {               pageX = mpa.getX( MediaPrintableArea.INCH );               pageY = mpa.getX( MediaPrintableArea.INCH );          } else {               pageX = DEFAULT_PAGE_WIDTH_INCH;               pageY = DEFAULT_PAGE_HEIGHT_INCH;          }          int pixelsPerPageY = ( int ) ( dpi * pageY );          // make colour true if the user has selected colour, and the PrintService can support colour          boolean colour = pjas.containsValue( Chromaticity.COLOR );          colour = colour & ( ps.getAttribute( ColorSupported.class ) == ColorSupported.SUPPORTED );          // create a BufferedImage to draw on          int imgMode;          if( colour ) imgMode = BufferedImage.TYPE_3BYTE_BGR;          else imgMode = BufferedImage.TYPE_BYTE_GRAY;          BufferedImage img = new BufferedImage( x, y, imgMode );          Graphics myGraphics = img.getGraphics();          myGraphics.setClip( 0, 0, x, y );          myGraphics.setColor( Color.WHITE );          myGraphics.fillRect( 0, 0, x, y );          // call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics          rv.paint( myGraphics, new Rectangle( 0, 0, x, y ) );           try {               // write the image as a JPEG to the ByteArray so it can be printed                Iterator writers = ImageIO.getImageWritersByFormatName( "jpeg" );               ImageWriter writer = ( ImageWriter ) writers.next();               ByteArrayOutputStream out = new ByteArrayOutputStream();               ImageOutputStream ios = ImageIO.createImageOutputStream( out );               writer.setOutput( ios );               // get the number of pages we need to print this image               int imageHeight = img.getHeight();               int numberOfPages = ( int ) ( ( imageHeight / pixelsPerPageY ) + 0.5 );               // print each page               for( int i = 0; i < numberOfPages; i++ ) {                    int startY = i * pixelsPerPageY;                                        // get a subimage which is exactly the size of one page                    BufferedImage subImg = img.getSubimage( 0, startY, x, pixelsPerPageY );                    writer.write( subImg );                    SimpleDoc sd = new SimpleDoc( out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null );                    printDocument( sd, ps );                    // reset the ByteArray so we can start the next page                    out.reset();               }          } catch( PrintException e ) {               System.out.println( "Error printing document." );               e.printStackTrace();               return false;          } catch( IOException e ) {               System.out.println( "Error creating ImageOutputStream or writing to it." );               e.printStackTrace();               return false;          }          // uncomment this code and comment out the 'try-catch' block above          // to print to a JFrame instead of to the printer/*          JFrame jf = new JFrame();          PaintableJPanel jp = new PaintableJPanel();          jp.setImage( img );          JScrollPane jsp = new JScrollPane( jp );          jf.getContentPane().add( jsp );          Insets i = jf.getInsets();          jf.setBounds( 0, 0, newX, y );          jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );          jf.setVisible( true );*/          return true;     }     /**     * Print the document to the specified PrintService.     * This method cannot tell if the printing was successful. You must register     * a PrintJobListener      *     * @return false if no PrintService is selected in the dialog, true otherwise     */     public boolean printDocument( Doc doc, PrintService ps ) throws PrintException {          if( ps == null ) return false;          addAllPrintServiceAttributeListeners( ps );          DocPrintJob dpj = ps.createPrintJob();          addAllPrintJobListeners( dpj );          dpj.print( doc, attributes );          return true;     }     public PrintService showPrintDialog() {          return ServiceUI.printDialog(                gc, x, y, services, defaultService, flavor, attributes );     }     private void addAllPrintServiceAttributeListeners( PrintService ps ) {          // add all listeners that are currently added to this object           for( int i = 0; i < psalListeners.size(); i++ ) {               PrintServiceAttributeListener p = ( PrintServiceAttributeListener ) psalListeners.get( i );               ps.addPrintServiceAttributeListener( p );          }     }     private void addAllPrintJobListeners( DocPrintJob dpj ) {          // add all listeners that are currently added to this object           for( int i = 0; i < pjlListeners.size(); i++ ) {               PrintJobListener p = ( PrintJobListener ) pjlListeners.get( i );               dpj.addPrintJobListener( p );          }     }     // uncomment this also to print to a JFrame instead of a printer/*     protected class PaintableJPanel extends JPanel {          Image img;          protected PaintableJPanel() {               super();          }          public void setImage( Image i ) {               img = i;          }                    public void paint( Graphics g ) {               g.drawImage( img, 0, 0, this );                         }     }*/}

  • Print html content of an JEditorPane

    Hello!
    I have an JEditorPane with some HTML Content displayed (as it is displayed in a browser).
    Now i want to sent this content to a printer.
    After some search i found the DocumentRenderer class from this link:
    http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    It may be trivial, but i don't know how to create a HTMLDocument Object from my JEditorPane (and its contents).
    Maybe somebody can help me out with this.
    my code so far:
    DocumentRenderer renderer = new DocumentRenderer();
    HTMLDocument doc = new HTMLDocument();
    //At this point i don't  know how to get my JEditorPane/it's contents "into" the HTMLDocument Object
    renderer.setDocument(doc);
    renderer.print(doc);                               Many thanks in advance for help!

    find it out by myself.
    HTMLDocument doc = (HTMLDocument)myJEditorPane.getDocument();But now i ran in another problem:
    Checkboxes are not displayed when i print this content.
    Is it possible to solve this problem?

  • Print context content on a client local printer

    Hi All,
    We need to print the content of my context node using local printer of the client PC. We cannot use Adobe Forms because it is not supported on our UNIX platform.
    We tried to use some Java libraries, but print goes to J2EE's server printer.
    SAP EP is placed in Internet, not in Intranet.
    May you help us?
    Regards,
    Matteo.

    Are your clients PCs also running UNIX?
    If they are Windows systems, you could export the context data to Excel and print from there. There is a tutorial here in SDN.
    Armin

  • How to print the content of a textarea in java?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button?
    for instance:
    JTextarea textarea = new JTextArea();
    JButton print = new JButton ();
    file_menu.add(print) ;
    print.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    ////----> what could i put here to print the content of my textarea named 'textarea' ? Does anyone know a class i could implement here? for instance: 'Print print = new Print(textarea);'
    I've searched on the web but i didn't find it...
    Thanks very much for your help...
    S�bastien

    public class TA extends JTextArea implements Printable{
    public TA(){
    super();
    this.setPreferredSize(new Dimension(500,500));
    public TA(int x, int y){
    super(x,y);
    public int print(Graphics g, PageFormat pf,int pi){
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX(),pf.getImageableY());
    Font f = new Font("Monospaced", Font.PLAIN,6);
    g2.setFont (f);
    g2.drawString(this.getText(),100,100);
    this.paint(g2);
    return Printable.PAGE_EXISTS;
    And use in Action Listener
    // get the print job
    if(pj.printDialog()){
    PageFormat pformat = pj.defaultPage();
    pformat.setOrientation(PageFormat.PORTRAIT);
    System.out.println(pj.defaultPage());
    pj.setPrintable(ta,pj.pageDialog(pformat));
    try{
    pj.print();
    catch(PrinterException p){

  • How to print the content of a text edit ?

    Hi to all,
    I have a view with a text edit and I want to print its content. I created a button and I want to print text edit content pressing this button. How can I do? Which java code I have to insert in that button?
    thanks a lot,
    Antonio

    Antonio,
    Sadly, there is no way to do it directly. Even in plain HTML application it is impossible to print text of UI control (<textarea> in this case).
    So you have to open new browser window containing entered text and let user print text himself. Or invoke window.print() on document load event.
    VS

  • How to print the content of LinkedList int[] and LinkedList LinkedList ?

    Hi guys, its been a long time since i posted here, and now im coming back to programming using java. My problem is, how can i print the content of the list?
    Example:
    LinkedList<int[]> list = new LinkedList<int[]>;
    int[] input = {1,2,3,4,5};
    int[] input2 = {2,32,43,54,65};
    list.add(input);
    list.add(input2);
    how can i print all the content of the linkedlist?
    Please help me..I know its a dumb question but i really dunno how.
    here is the code:
    import java.util.LinkedList;
    import java.util.Scanner;
    import java.util.Arrays;
    public class Test{
         static void printThis(String[] in){
              System.out.print("Value: ");
              for(int i = 0;i<in.length;i++){
                   System.out.print(in[i] + " ");
              System.out.println();
         static void reset(String[] val){
              for(int i = 0;i<val.length;i++){
                   val[i] = "";
         public static void main(String[] args){
              LinkedList<String[]> list = new LinkedList<String[]>();
              LinkedList<String> listTrans = new LinkedList<String>();
              System.out.print("Enter the number of records: ");
              Scanner s = new Scanner(System.in);
              int numOfRecords = s.nextInt();
              System.out.print("Enter the number of records per run: ");
              s = new Scanner(System.in);
              System.out.println();
              int numOfRecordsInMemory = s.nextInt();
              String[] getData = new String[numOfRecords];
              String[] transferData = new String[numOfRecordsInMemory];
              int numOfRuns = 0;
              int counter = 0;
              for(int i = 0;i<numOfRecords;i++){
                   counter++;
                   System.out.print("Enter value number " + counter + ": ");
                   Scanner scan = new Scanner(System.in);
                   getData[i] = scan.next();
                   listTrans.add(getData);
              if(getData.length%numOfRecordsInMemory == 0){
                   numOfRuns = getData.length/numOfRecordsInMemory;
              }else if(getData.length%numOfRecordsInMemory != 0){
                   numOfRuns =(int)(getData.length/numOfRecordsInMemory)+ 1;
              System.out.println();
              System.out.println("Number of Runs: " + numOfRuns);
         int pass = 0;
         System.out.println("Size of the main list: " + listTrans.size());
         while(listTrans.size() != 0){
              if(listTrans.size() >= numOfRecordsInMemory){
                   for(int i = 0;i<numOfRecordsInMemory;i++){
                        transferData[i] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
              }else if(listTrans.size() < numOfRecordsInMemory){
                   pass = listTrans.size();
                   for(int k = 0;k<pass;k++){
                        transferData[k] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
    //This is the part that is confusing me.
    //im trying to print it but its not working.
              System.out.println("Size of the next list: " + list.size());
    //          for(int i = 0;i<list.size();i++){
    //                    System.out.println();
    //               for(int j = 0;j<list.get(i)[j].length();j++){                    
    //                    System.out.print(list.get(i)[j] + " ");

    Here's the funnest, mabye clearest way you could do it: Use 2 Mappers
    package tjacobs.util;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import tjacobs.Arrays;
    public class Mapper <T>{
         public static interface MappedFunc<T> {
              void map(T value);
         public Mapper(T[] vals, MappedFunc<T> function) {
              this (new Arrays.ArrayIterator<T>(vals), function);
         public Mapper(Iterator<T> iterator, MappedFunc<T> function) {
              while (iterator.hasNext()) {
                   function.map(iterator.next());
         public static void main(String[] args) {
              String[] s = new String[] {"a","b", "c", "abc", "ab"};
              MappedFunc<String> func = new MappedFunc<String>() {
                   public void map(String s) {
                        if (s.toLowerCase().startsWith("a")) {
                             System.out.println(s);
              Mapper m = new Mapper(s, func);
    }

  • How to print the contents of a form(window)

    I'm devloping visitors application in java. After the data entry, I need to display the selected information from database along with the photo and take a printout so that it looks like a card.
    I know how to display the contents in a form. How do I print the contents of the form?
    -Thanx
    Hane

    in JComponent there is a method called print(Graphics g)
    you can use that with a Printable class
    read bout the java.print package in the java doc

  • How to print the contents of doubly-Linked List

    Hi
    I have a DLList consists of header , trailer and 10 linked nodes in between
    Is there a simple way to print the contents ie "the elements"
    of the list
    thanks

    In general you should write an iterator for every linked data structure for fast traversal. I'm guessing you're writing your own DLL for an assignment because one normally uses the LinkedList structure that is included in the api. Anyway, here is an example of how the iterator is implemented for a double linked list:
    http://www.theparticle.com/_javadata2.html#Doubly_Linked_Lists_with_Enumeration

  • How to print a content of a window

    I'm totatlly new to handling printer in java. can any one give me a hand to do this.
    what i want to do is i have a generated html report inside a JTextPane. i want to print this to take a rough copy of it. the text pane is inside a JInternalFrame and there is a button on it for this.
    can any one give me sample code for this. (to print a content of a TextPane)
    please use good comments in the code so i can get a good idea about this.
    Thankx in advance...

    Sorry for some error at code before. here is the revision:
    import java.awt.*;
    import java.awt.print.*;
    import javax.swing.*;
    public class ComponentPrintable implements Printable { // sorry forgot class keyword
         private Component componentToPrint; // in your case it's JTextPane
         public ComponentPrintable(Component componentToPrint) {
              this.componentToPrint = componentToPrint;
         public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
              if (pi > 0)
                   return NO_SUCH_PAGE;
              componentToPrint.print(g);
              // 'retrun' should be return...
              return PAGE_EXISTS;
         public static void main(String[] args) throws Exception {
              PrinterJob printerJob = PrinterJob.getPrinterJob();
              JLabel componentToPrintLabel = new JLabel(
                        "Here is sample of component to be printed");
              ComponentPrintable cp = new ComponentPrintable(componentToPrintLabel);
              printerJob.setPrintable(cp);
              // you can set page format by calling printerJob.pageDialog(...)
              printerJob.print();
    }you can compile and run it.
       $javac ComponentPrintable.java
       don't forget to turn on printer and prepare paper...
       $java ComponentPrintable
       see the result

  • Can you print the contents of a blob in Bi Publisher

    For example, Bi Publisher generate a pdf file in apex that will print the contents of a blob.
    Let's say you have a record with test.xls in a blob, can I take the test.xls out of the record and have bi publisher print it.
    Thanks,
    Doug

    BI Publisher can add some blobs to a report, such as a .jpg / .gif / .png, but excel just doesn't make sense, nor do I think it would work.
    Tyler Muth
    http://tylermuth.wordpress.com
    "Applied Oracle Security: Developing Secure Database and Middleware Environments": http://sn.im/aos.book

  • Urgent: how to print the contents displayed in JTextPane

    hi all,
    i've a problem printing the contents typed in styled format in JTextPane, when i print the contents nothing is printed. can anyone tell how can i print the contents typed in styled format or so. the code for implementing the print is given below.
    class ContentsArea extends JTextPane implements Pritable {
       public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
          if (pi >= 1) {
             return Printable.NO_SUCH_PAGE;
          Graphics2D g2d = (Graphics2D) g;
          g2d.translate(pf.getImageableX(), pf.getImageableY());
          g2d.translate(pf.getImageableWidth() / 2,
                          pf.getImageableHeight() / 2);
          Dimension d = getSize();
          double scale = Math.min(pf.getImageableWidth() / d.width,
                                    pf.getImageableHeight() / d.height);
          if (scale < 1.0) {
              g2d.scale(scale, scale);
          g2d.translate(-d.width / 2.0, -d.height / 2.0);
          return Printable.PAGE_EXISTS;
    }i'd be grateful to all ppl who helps me.
    Afroze.

    What's the exact problem? The printer printing a blank sheet or the printer not doing anything at all? First make sure in the main program you've got something along the lines of...
    import java.awt.print.*;
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printerJob.defaultPage();
    if(!printerJob.printDialog()) return; //not essential but lets the user tweak printer setup
    pageFormat = printerJob.pageDialog(pageFormat); //ditto
    printerJob.setPrintable(this, pageFormat);
    print(...);
    The above code should go in an ActionListener, triggered when the user hits a print button or menuitem. I'm guessing you already have something similar set up.
    Then your print(...) method should be similar to
    public int print(Graphics g, PageFormat pageFormat, int pageIndex)
         if(pageIndex>0) return NO_SUCH_PAGE;
         Graphics2D gg = (Graphics2D)g;
         gg.draw(whatever's going to be printed);
         return PAGE_EXISTS;
    Which it is, although yours has clever scaling stuff built in ) The only thing you're not doing is rendering the actual content.
    So if you want the contents of the textpane, it'd make sense to use something like g.drawString(myTextPane.getContents()); in the print method. Note it's g and not g2d, since Graphics2D has more complicated text handling routines.
    I'm no expert tho )

  • I need to print the contents of a text area

    i am trying to create an editor and one of the options is print, so i want to print the contents of the text area. can someone help

    See Printing the Contents of a Component in http://java.sun.com/docs/books/tutorial/2d/printing/index.html

  • What is the best way  to print the contents within a scrolling textbox in a fillable form?

    I have created a form using Acrobat 9 Pro which contains several text boxes that allow for unlimited text.  When printing out completed forms,  any text that requires scrolling will not print.  Is there any way to be able to print the contents of all text boxes regardless of length of content?

    Yes, when you set the font size to Auto, the font size shrinks to include all the entered text in the visible area. Otherwise the hidden the text is not displayed and you see observe a "+" sign. You might also want to consider the option to make your form flowable using Adobe LiveCycle Designer.
    ~Deepak

  • 3D PDF files in portfolio prints to Adobe PDF printer without content

    3D PDF files in portfolio prints to Adobe PDF printer without content, but if printed from single 3D PDF file everything is fine. I need batch printing (this is the reason I use portfolio) of large amount of 3DPDF files because of the need to have proper preview of these files in browsers. Any ideas or workarounds how to have preview pdf's or jpg's of the single paged 3D PDF files, keeping relevant file names?

    I suspected as much.  I was hopeful it was something like a setting that needed to be changed or a reg hack that needed a bit changed from 0 to 1 to make the printing work as expected.  I only installed the local printer to see if the RDP session
    tunnel was in fact causing the print size to balloon so I will continue to instruct users to use that instead of the local redirected printer.  I am disappointed but not surprised.
    Edit:
    Additionally I have tested the functionality of setting the GPO settings for Easy Print to use the redirected printer's drivers instead of the ones used by easy print, by setting “Computer
    Configuration -> Administrative templates -Windows Components -> Remote Desktop Services > Remote Desktop Session Host -> Printer Redirection”.
    to “Disabled” but
    with no luck.  In fact the printer received the proper Adobe PDF driver, but the job went out into print spool hell and was lost to the ether.  I have concluded that this approach will not bear any fruit.

Maybe you are looking for