#java #printing
Вопрос:
Я пытаюсь распечатать все страницы с помощью PrintRequestAttributeSet. Однако это не сработало, но ошибок не показывает, так что я понятия не имею, в чем ошибка.
Вот мой код:
public void printMultiplePages() {
PrintRequestAttributeSet myAtt = new HashPrintRequestAttributeSet();
PrinterJob printJob = PrinterJob.getPrinterJob();
myAtt.add(OrientationRequested.LANDSCAPE);
myAtt.add(new MediaPrintableArea(5, 5, 300-2, 300-4, MediaPrintableArea.MM));
printJob.setPrintable(this);
printJob.setPageable(this);
boolean ok = printJob.printDialog(myAtt);
if (ok) {
try {
printJob.print(myAtt);
} catch (PrinterException e) {
System.out.println("Error: " e);
}
}
}
и это мое переопределение
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex < 0) {
return (NO_SUCH_PAGE);
} else {
Graphics2D graphic = (Graphics2D) g;
graphic.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
_component.printAll(graphic);
return (PAGE_EXISTS);
}
}
Может кто-нибудь мне помочь, заранее спасибо.