Book druckt nur die erste Seite aus

schulzp

Grünschnabel
Hallo,

und zwar hab ich das Problem, dass bei einem Book-bestehend aus 2 Seiten,
immer nur die 1. ausgedruckt wird!

Was ist falsch?

Danke
 
Hi,

ich habe das selbe Problem.

Weiß jemand woran es liegen könnte?

Ich habs auf einer Tutorial Seite gelesen und so umgesetzt.

Code:
public void printPages(Pageable printComponents) {
    boolean doPrint = this.printerJob.printDialog();

    if (doPrint) {
      try {
        this.printerJob.setPageable((Book) printComponents);
        this.printerJob.print();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

Druckt aber leider immer nur die erste Seite aus. Das selbe gilt auch wenn ich den Book TypeCast nicht anwende.

Bräuchte dies unbedingt. Danke
 
Und einen Beitrag weitergelesen und schon hab ichs. :-(

Ich hab bei meinem Paper das Printable implementiert noch

Code:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    Graphics2D graphics2D = (Graphics2D) graphics;

    double x = pageFormat.getImageableX();
    double y = pageFormat.getImageableY();
    double w = pageFormat.getImageableWidth();
    double h = pageFormat.getImageableHeight();

    double sx = w / this.getWidth();
    double sy = h / this.getHeight();

    graphics2D.translate(x, y);
    //graphics2D.scale(sx, sy);

    this.printAll(graphics2D);

    if (pageIndex != 0) {
      return Printable.NO_SUCH_PAGE;
    }
    else {
      return Printable.PAGE_EXISTS;
    }
}

sowas stehen gehabt. Anscheinend regelt die Klasse Book selbst ob noch eine Seite existiert oder nicht. Auch gut. Es sieht auf jedenfall jetzt so aus

Code:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    Graphics2D graphics2D = (Graphics2D) graphics;

    double x = pageFormat.getImageableX();
    double y = pageFormat.getImageableY();
    double w = pageFormat.getImageableWidth();
    double h = pageFormat.getImageableHeight();

    double sx = w / this.getWidth();
    double sy = h / this.getHeight();

    graphics2D.translate(x, y);
    //graphics2D.scale(sx, sy);

    this.printAll(graphics2D);

    /*
    if (pageIndex != 0) {
      return Printable.NO_SUCH_PAGE;
    }
    else {
      return Printable.PAGE_EXISTS;
    }
    */
   return Printable.PAGE_EXISTS;
  }

und die print Anweisung

Code:
public void printPages(Pageable printComponents) {    

    //Dies dem printerJob vor dem Aufruf des printDialog() setzen!
    this.printerJob.setPageable((Book) printComponents);

    if (this.printerJob.printDialog()) {
      try {
        this.printerJob.print();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

Vielleicht kann ich so anderen auch mal helfen.

Gruß

Romsl
 
Zuletzt bearbeitet:
Zurück