Java Print landscape pages with no rotation - Stack Overflow

I'm trying to print a document from Java 23 in LANDSCAPE mode.I print to PDF file when asked for

I'm trying to print a document from Java 23 in LANDSCAPE mode.

I print to PDF file when asked for the destination to print.

When I want it to print my document on landscape, I have a PDF rotated 90° to the left.

These are the files in my project:

  • src/main/java/com/example/littleVHPrinting/App.java
  • src/main/java/com/example/lvhp/print/AppPageable.java
  • src/main/java/com/example/lvhp/print/AppPrintable.java
  • src/main/resources/textContent.txt

This is the most relevant code:

public class AppPageable implements java.awt.print.Pageable {
//stuff...
    @Override
    public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
        PageFormat pf = new PageFormat();
        final Paper paper = new Paper();
        switch(orientation){
            //This has no effect, and pf.setOrientation(PageFormat.LANDSCAPE); prints rotated 90°
            case HORIZONTAL->{paper.setSize(paper.getHeight(), paper.getWidth());}
        }
        paper.setImageableArea(0d, 0d, paper.getWidth(), paper.getHeight());
        pf.setPaper(paper);
        return pf;
    }

//more stuff...
}

If I do pf.setOrientation(PageFormat.LANDSCAPE), I have a rotated PDF like this one. What I really want is a PDF with a LANDSCAPE printing, without rotation, just like this.

Maybe this is not an error from the API, they surely wanted it to work like this, but is not what I need. What can I do?

Thanks in advance.

Full running project on

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744072378a4553780.html

相关推荐

  • Java Print landscape pages with no rotation - Stack Overflow

    I'm trying to print a document from Java 23 in LANDSCAPE mode.I print to PDF file when asked for

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信