Print microsoft-word documents using java


General J2EE: Print microsoft-word documents using java

  1. Print microsoft-word documents using java (4 messages)

    Hi, I have a requirement where i need to print word documents on a shared drive. Is it possible using Java code? I wont be using the POI library. Please help me with any other approach that you can think of. Thanks for any help.
  2. Since you don't want to use POI - I assume you are not interested in other java COM bridges.... The interesting swing way of doing this : If you make jeditor pane set the document as your word document and pass it on to the print utilities as might work.. import java.awt.*; import javax.swing.*; import java.awt.print.*; public class PrintUtilities implements Printable { private Component componentToBePrinted; public static void printComponent(Component c) { new PrintUtilities(c).print(); } public PrintUtilities(Component componentToBePrinted) { this.componentToBePrinted = componentToBePrinted; } public void print() { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); if (printJob.printDialog()) try { System.out.println("Calling PrintJob.print()"); printJob.print(); System.out.println("End PrintJob.print()"); } catch (PrinterException pe) { System.out.println("Error printing: " + pe); } } public int print(Graphics g, PageFormat pf, int pageIndex) { int response = NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; // for faster printing, turn off double buffering disableDoubleBuffering(componentToBePrinted); Dimension d = componentToBePrinted.getSize(); //get size of document double panelWidth = d.width; //width in pixels double panelHeight = d.height; //height in pixels double pageHeight = pf.getImageableHeight(); //height of printer page double pageWidth = pf.getImageableWidth(); //width of printer page double scale = pageWidth / panelWidth; int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight); // make sure not print empty pages if (pageIndex >= totalNumPages) { response = NO_SUCH_PAGE; } else { // shift Graphic to line up with beginning of print-imageable region g2.translate(pf.getImageableX(), pf.getImageableY()); // shift Graphic to line up with beginning of next page to print g2.translate(0f, -pageIndex * pageHeight); // scale the page so the width fits... g2.scale(scale, scale); componentToBePrinted.paint(g2); //repaint the page for printing enableDoubleBuffering(componentToBePrinted); response = Printable.PAGE_EXISTS; } return response; } public static void disableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(false); } public static void enableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager(c); currentManager.setDoubleBufferingEnabled(true); } } Bhagvan K
  3. Bhagvan, I do not fancy POI since it is not very mature for word manipulation. I have a bunch of word documents that get generated everyday & dumped on a shared drive. I need to write a java program that prints off these word documents without any user intervention. Is it doable? I would be very grateful if you could suggest any other components that can do it for me. Thanks.
  4. I think this link should help you..!
  5. Recovery data[ Go to top ]

    To my mind one of the best tool for work with word files is-[url=]docx corrupt[/url],because program helped me many times and has free status.At the end it can too help you and recover your damaged files in Microsoft Word format.