首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ODFDom设置.odt Text文档的页面大小、页面方向和页边距

ODFDom设置.odt Text文档的页面大小、页面方向和页边距
EN

Stack Overflow用户
提问于 2015-10-09 22:20:00
回答 1查看 465关注 0票数 0

显然,对于ods电子表格文档,这些设置可以更改,但对于odt,只能更改某些参数:

代码语言:javascript
复制
StyleMasterPageElement defaultPage = templateDocument.getOfficeMasterStyles().getMasterPage("Default");
String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute();
OdfStylePageLayout pageLayoutStyle = defaultPage.getAutomaticStyles().getPageLayout(pageLayoutName);
TextProperties textProperties = TextProperties.getOrCreateTextProperties(pageLayoutStyle);

textProperties.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);

例如,如何设置页面方向?我在odt文档的API中找不到任何引用。

EN

回答 1

Stack Overflow用户

发布于 2017-09-22 04:37:00

您可以使用PageLayoutProperties类更改页面大小和页边距。

关于页面方向,您可以通过切换页面的宽度和高度来获得横向方向,但我不确定这样做是否正确。

代码语言:javascript
复制
public static void main(String[] args) throws Exception
{
    TextDocument odt = TextDocument.newTextDocument(); // From the simple odftoolkit
    odt.addParagraph("Test text...");

    // Getting the page layout properties
    StyleMasterPageElement defaultPage = odt.getOfficeMasterStyles().getMasterPage("Standard");
    String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute();        
    OdfStylePageLayout pageLayoutStyle = defaultPage.getAutomaticStyles().getPageLayout(pageLayoutName);
    PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties(pageLayoutStyle);

    // Setting paper size "letter", portrait orientation
    pageLayoutProps.setPageWidth(215.9); // millimeter...
    pageLayoutProps.setPageHeight(279.4);
    odt.save(new File(System.getProperty("user.home"), "letter_portrait.odt"));

    // Setting paper size "letter", landscape orientation : just switch width/height...
    pageLayoutProps.setPageWidth(279.4);
    pageLayoutProps.setPageHeight(215.9);
    odt.save(new File(System.getProperty("user.home"), "letter_landscape.odt"));

    // Setting paper size "legal", portrait orientation
    pageLayoutProps.setPageWidth(216); 
    pageLayoutProps.setPageHeight(356);
    odt.save(new File(System.getProperty("user.home"), "legal_portrait.odt"));

    // And so on...

    // And you can also set the page margins
    pageLayoutProps.setMarginTop(10);
    pageLayoutProps.setMarginBottom(10);
    pageLayoutProps.setMarginRight(10);
    pageLayoutProps.setMarginLeft(10);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33040656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档