apache odftoolkit portrait/landscape mode

225 views Asked by At

I'm using library apache odftoolkit to generate report from Java code to *.odt file. Have code like this:

outputOdt = TextDocument.newTextDocument();
Paragraph p = outputOdt.addParagraph("some text");
p.appendTextContent("some text");

I'm adding paragraphs, tables, setting fonts, and it works fine. But I need to set some pages in my document in Landscape mode but don't know how to do this. I found API class PageLayoutProperties and method setPrintOrientation(), but don't know where to call it. Anybody know?

2

There are 2 answers

0
Vitaliy On

Found solution:

TextDocument outputOdt;
for( Iterator<StyleMasterPageElement> it = outputOdt.getOfficeMasterStyles().getMasterPages(); it.hasNext(); ) {
            StyleMasterPageElement page = it.next();
            String pageLayoutName = page.getStylePageLayoutNameAttribute();
            OdfStylePageLayout pageLayoutStyle = page.getAutomaticStyles().getPageLayout( pageLayoutName );
            PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties( pageLayoutStyle );

            double tmp = pageLayoutProps.getPageWidth();
            pageLayoutProps.setPageWidth( pageLayoutProps.getPageHeight());
            pageLayoutProps.setPageHeight( tmp );
        }
0
Jaap On

I came across this existing question and answer:

How can the Page Size, Page Orientation, and Page Margins of an ods Spreadsheet Be Set Using ODFDOM?

which is about doing the same thing for an ODS spreadsheet, which is essentially the same. Key is to set the page height and width as well as the print orientation in the PageLayoutProperties