画像を印刷する必要があります。のように向きを設定すると
printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);
すべて正常に動作します。
しかし、次print()
のメソッド内で方向を設定するとPrintable
:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex >= images.size())
return Printable.NO_SUCH_PAGE;
image = images.get(pageIndex);
// if image width>height --> Landscape, else --> Protrait
if (image.getWidth(null) > image.getHeight(null))
pageFormat.setOrientation(PageFormat.LANDSCAPE);
else
pageFormat.setOrientation(PageFormat.PORTRAIT);
graphics2D = (Graphics2D) graphics;
graphics.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), null);
return PAGE_EXISTS;
};
最初のページでは機能しません。つまり、最初のページを除くすべてのページを横向きモードで印刷します。