gpt4 book ai didi

java - 打印时设置横向

转载 作者:行者123 更新时间:2023-11-29 03:43:15 26 4
gpt4 key购买 nike

我需要打印一张图片。当我像

这样设置方向时

printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);

一切正常。

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

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;
};

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

最佳答案

当您已经尝试打印页面时,您不能更改方向。

如果您需要提供多个不同方向的页面,您需要查看 BookPageable接口(interface),参见 Printing in Java例如。

唯一的其他解决方案是在 Printable 中旋转图像,这充其量也很麻烦。

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

关于java - 打印时设置横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com