打印时设置LANDSCAPE方向 [英] Setting LANDSCAPE orientation when printing

查看:1350
本文介绍了打印时设置LANDSCAPE方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打印图像.当我设置方向

I need to print an image. When I set orientation like

printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);

一切正常.

但是当我在Printableprint()方法内设置方向时:

But when I set orientation inside print() method of 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;
};

不适用于首页.即以横向"模式打印除第一页以外的所有页面.

推荐答案

已经尝试打印页面时,无法更改方向.

You can not change the orientation when your already trying to print the page.

如果需要提供许多方向不同的页面,则需要查看可分页接口,请参见以Java打印(例如).

If you need to provide a number of pages with different orientations, you will want to look at the Book and Pageable interfaces, see Printing in Java for examples.

您唯一需要解决的另一种方法是在Printable中旋转图像,这充其量是很麻烦的.

The only other solution you have is to rotate the image in Printable, which is troublesome at best.

ps-当工作时,打印很有趣;)

ps - Printing is fun...when it works ;)

这篇关于打印时设置LANDSCAPE方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆