Announcement

Collapse
No announcement yet.

Grafik ohne Druckdialog ausdrucken

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grafik ohne Druckdialog ausdrucken

    Hallo,

    ist es möglich das der Druckvorgang auch ohne Druckdialog
    gestartet werden kann.
    Für Eure Hilfe wär ich echt dankbar
    Ciao

    Uwe

    class BarcodePrint
    extends Frame
    {
    public void doDraw(Graphics2D g, boolean printer) {
    try {
    int y = 40;
    int x = 10;
    int linespace = 25;
    int fontSize = 8;
    int barHeight = 10;
    int barWidth = 1;

    if (printer) {
    y = 50;
    x = 20;
    linespace = 60;
    fontSize = 25;
    barHeight = 25;
    barWidth = 2;
    }

    g.setColor(Color.black);
    Font ft = new Font(null, Font.TRUETYPE_FONT, fontSize);

    String testLine = "Mein TEst";

    Barcode bc = BarcodeFactory.createCode128B("My Barcode");
    bc.setBarHeight(barHeight);
    bc.setBarWidth(barWidth);
    bc.setFont(ft);
    bc.draw(g, x, y);
    y += linespace;

    }
    catch (BarcodeException e) {
    System.out.println("Exception: " + e.getMessage());
    e.printStackTrace();
    }
    }

    public void toPrinter() {
    JobAttributes attr = new JobAttributes();
    int[] printerResolution = new int[3];
    printerResolution[0] = 200;
    printerResolution[1] = 200;
    printerResolution[2] = 3;
    PageAttributes pgattr = new PageAttributes(PageAttributes.ColorType.MONOCHROME ,
    PageAttributes.MediaType.NA_LETTER,
    PageAttributes.OrientationRequestedType.PORTRAIT,
    PageAttributes.OriginType.PRINTABLE, PageAttributes.PrintQualityType.HIGH,
    printerResolution);

    //Und hier kommt nun der Dilalog ins Spiel//////////////
    PrintJob pj= Toolkit.getDefaultToolkit().getPrintJob(this, "Print Barcode Test", attr, pgattr);


    if (pj != null) {
    BufferedImage bi = new BufferedImage(
    pj.getPageDimension().width,
    pj.getPageDimension().height,
    BufferedImage.TYPE_BYTE_BINARY);

    Graphics2D g2 = (Graphics2D) bi.getGraphics();
    g2.setBackground(Color.white);
    g2.clearRect(0, 0, 20000, 20000);
    doDraw(g2, true);
    System.out.println("Printer resolution " + pj.getPageResolution());
    System.out.println("Print Dimension " + pj.getPageDimension());
    Graphics g = pj.getGraphics();
    g.drawImage(bi, 0, 0, this);
    pj.end();
    }
    System.out.println("BarcodeProto.toPrinter: Done");
    }

    }

  • #2
    habe ich auch schon versucht zu machen, ohne erfolg :

    Comment


    • #3
      Hi,
      kenn mich auch nicht besonders gut aus, aber google vielleicht mal nach JasperPrintManager. Mit dem kann man auf jeden Fall beim Drucken das Druckmenü unterdrücken, weiß aber nicht, ob das ansonsten für deine Zwecke geeignet ist.
      Lg, Mari

      Comment

      Working...
      X