Не могу понять, печатает в win7 нормально, в Mandriva2009 печатает пол страницы и замерает, потом вообще перестал печатать , даже тестовые страницы ? В чем может быть проблема, программа искл. не вызывает.
| Код | /* * To change this template, choose Tools | Templates * and open the template in the editor. */
package Jservers;
/* * Copied from this tutorial: * * http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing... * * And also from a post on the forums at java.swing.com. My apologies that do not have * a link to that post, by my hat goes off to the poster because he/she figured out the * sticky problem of paging properly when printing a Swing component. */ import java.awt.*; import javax.swing.*; import java.awt.print.*; import javax.print.attribute.DocAttributeSet; import javax.print.attribute.HashDocAttributeSet; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Chromaticity; import javax.print.attribute.standard.Copies; import javax.print.attribute.standard.MediaPrintableArea; import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.OrientationRequested; import javax.print.attribute.standard.PrintQuality; import sun.nio.cs.FastCharsetProvider; public class PrintContent implements Printable { private Component componentToBePrinted; static public String type_list=""; public static void printComponent(Component c,String type) { type_list=type; new PrintContent(c).print(); } public PrintContent(Component componentToBePrinted) { this.componentToBePrinted = componentToBePrinted; } public void print() { // DocAttributeSet docAttributes=new HashDocAttributeSet(); //docAttributes.add(Chromaticity.MONOCHROME); PrintRequestAttributeSet printAttributes=new HashPrintRequestAttributeSet(); printAttributes.add(new Copies(1)); if(type_list.equals("Land")){ printAttributes.add(OrientationRequested.LANDSCAPE); printAttributes.add(new MediaPrintableArea( 0, // отсуп слева 0, // отсуп сверху 600, // ширина 600, // высота MediaPrintableArea.MM)); printAttributes.add(MediaSizeName.ISO_A4); } else{ printAttributes.add(OrientationRequested.PORTRAIT); } printAttributes.add(PrintQuality.DRAFT); printAttributes.add(Chromaticity.MONOCHROME); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); // printJob.printDialog(); if (true) try { System.out.println("Calling PrintJob.print()"); printJob.print(printAttributes); System.out.println("End PrintJob.print()"); if(Card.flag_go){ Card.printNext(); } } 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); } }
|
|