You are viewing a plain text version of this content. The canonical link for it is here.
Posted to odf-users@incubator.apache.org by "Joseph D. Wagner" <jo...@josephdwagner.info> on 2018/01/02 20:41:53 UTC

Margins and Page Size

I'm looking for the code in Simple API to set Margin and Page Size 
(Height and Width).

I saw the example here about getOrCreateMasterPage, but that appears to 
work only with a page break.

https://incubator.apache.org/odftoolkit/simple/document/cookbook/Text%20Document.html#Get%20TextDocument

I need to apply this to the first page of an empty doc.

Thank you for your patience and help.  I'm very new to your library.

Joseph D. Wagner


Re: Margins and Page Size

Posted by "Joseph D. Wagner" <jo...@josephdwagner.info>.
Thanks. I was able to get it to working using "Standard."

Joseph D. Wagner


On 01/03/2018 05:56 AM, Svante Schubert wrote:
> Hello Joseph,
>
> welcome to the list. Although my work is focused on the underlying ODFDOM
> API, I still can guide you to solve your questions regarding the Simple API.
> If I have a similar problem, I do as quite the same you already did and
> look first for some examples, too ;)
>
>     1. Close to your given reference, I found some Simple API example
>     related to page break:
>
>     https://incubator.apache.org/odftoolkit/simple/document/cookbook/Text%20Document.html#Page
>     Break
>     2. Still, the best examples are still those in the regression tests, as
>     you can test them immediately with the sources.
>     Therefore, I have searched in the test folder of Simple API for the
>     method call 'addPageBreak' to have a regression test to be able to run a
>     reproducible scenario and see where is a potential problem and found the
>     test.
>     org.odftoolkit.simple.TextDocumentTest class only using it.
>     3. I let run testAddPagebreakWithMasterPage in my Java IDE and
>     copy/pasted a line of saving the new document right at the start. To know
>     how it looks freshly created. Opening the resulting ODT test documents
>     from simple\target\test-classes in my test editor.
>     (BTW I am using JEdit with the XML and Archive extension so I am able to
>     open and indent the XML within the ODT files without explicitly unzipping
>     it, but any tooling of your choice might work.)
>     4. After running, I saw that the fresh document already contains the
>     empty paragraph with <text:p text:style-name="Standard"/>
>     The next paragraph <text:p>before page break - original
>     Landscape</text:p> is being added with a master page / page style that is
>     never being used.
>     Note: The Simple API is a donation once made by IBM and unfortunately,
>     after they left OpenOffice.org, they also abandoned this project. My aim is
>     to provide better functionality to the ODFDOM layer in the upcoming months
>     by code generation to avoid duplication of work..
>
>
> Why you might need to know are some ODF theory basics as background
> regarding the Page Layout:
> Starting with any top-level paragraph and a table within an ODF document,
> it is possible to change the page layout of an ODF document.
>
> The page properties are referenced three times so it is a little tricky
> when you hear it the first time :)
>
> The top level paragraph/table within the content.xml has a style name. The
> style can be an automatic style within the content.xml with name a name the
> user is never going to be aware of, or a template style, which the user can
> explicitly choose, like "Heading 1", etc.
>
> <office:automatic-styles>
> <style:style style:family="paragraph" style:master-page-name="Landscape"
> style:name="af2c6bb"/>
>
> The style is referencing again to the master styles within the styles.xml
>
> <office:master-styles>
> <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
>
> The page layout name refers to the page layout within the styles.xml
>
> <office:automatic-styles>
> <style:page-layout style:name="pm1">
>                          <style:page-layout-properties
> fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm"
> fo:margin-top="2cm" fo:page-height="29.699cm" fo:page-width="20.999cm"...
>
> Last but not least, there is one unwritten rule. When there is no page
> style given, there is a style like "Standard"  (for LibreOffice,
> OpenOffice..) or something like "Default" for Microsoft Office, that is
> providing the basic page layout and is not explicitly referenced.
>
> Sorry, I have no time to fix this Simple API feature for you, but at least
> I hope the information above assists you to fix it yourself if you like to
> :)
>
> Hope you are at the beginning of a great year!
> Svante
>
> ᐧ
>
> 2018-01-02 21:41 GMT+01:00 Joseph D. Wagner <jo...@josephdwagner.info>:
>
>> I'm looking for the code in Simple API to set Margin and Page Size (Height
>> and Width).
>>
>> I saw the example here about getOrCreateMasterPage, but that appears to
>> work only with a page break.
>>
>> https://incubator.apache.org/odftoolkit/simple/document/cook
>> book/Text%20Document.html#Get%20TextDocument
>>
>> I need to apply this to the first page of an empty doc.
>>
>> Thank you for your patience and help.  I'm very new to your library.
>>
>> Joseph D. Wagner
>>
>>


Re: Margins and Page Size

Posted by Svante Schubert <sv...@gmail.com>.
Hello Joseph,

welcome to the list. Although my work is focused on the underlying ODFDOM
API, I still can guide you to solve your questions regarding the Simple API.
If I have a similar problem, I do as quite the same you already did and
look first for some examples, too ;)

   1. Close to your given reference, I found some Simple API example
   related to page break:

   https://incubator.apache.org/odftoolkit/simple/document/cookbook/Text%20Document.html#Page
   Break
   2. Still, the best examples are still those in the regression tests, as
   you can test them immediately with the sources.
   Therefore, I have searched in the test folder of Simple API for the
   method call 'addPageBreak' to have a regression test to be able to run a
   reproducible scenario and see where is a potential problem and found the
   test.
   org.odftoolkit.simple.TextDocumentTest class only using it.
   3. I let run testAddPagebreakWithMasterPage in my Java IDE and
   copy/pasted a line of saving the new document right at the start. To know
   how it looks freshly created. Opening the resulting ODT test documents
   from simple\target\test-classes in my test editor.
   (BTW I am using JEdit with the XML and Archive extension so I am able to
   open and indent the XML within the ODT files without explicitly unzipping
   it, but any tooling of your choice might work.)
   4. After running, I saw that the fresh document already contains the
   empty paragraph with <text:p text:style-name="Standard"/>
   The next paragraph <text:p>before page break - original
   Landscape</text:p> is being added with a master page / page style that is
   never being used.
   Note: The Simple API is a donation once made by IBM and unfortunately,
   after they left OpenOffice.org, they also abandoned this project. My aim is
   to provide better functionality to the ODFDOM layer in the upcoming months
   by code generation to avoid duplication of work..


Why you might need to know are some ODF theory basics as background
regarding the Page Layout:
Starting with any top-level paragraph and a table within an ODF document,
it is possible to change the page layout of an ODF document.

The page properties are referenced three times so it is a little tricky
when you hear it the first time :)

The top level paragraph/table within the content.xml has a style name. The
style can be an automatic style within the content.xml with name a name the
user is never going to be aware of, or a template style, which the user can
explicitly choose, like "Heading 1", etc.

<office:automatic-styles>
<style:style style:family="paragraph" style:master-page-name="Landscape"
style:name="af2c6bb"/>

The style is referencing again to the master styles within the styles.xml

<office:master-styles>
<style:master-page style:name="Standard" style:page-layout-name="pm1"/>

The page layout name refers to the page layout within the styles.xml

<office:automatic-styles>
<style:page-layout style:name="pm1">
                        <style:page-layout-properties
fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm"
fo:margin-top="2cm" fo:page-height="29.699cm" fo:page-width="20.999cm"...

Last but not least, there is one unwritten rule. When there is no page
style given, there is a style like "Standard"  (for LibreOffice,
OpenOffice..) or something like "Default" for Microsoft Office, that is
providing the basic page layout and is not explicitly referenced.

Sorry, I have no time to fix this Simple API feature for you, but at least
I hope the information above assists you to fix it yourself if you like to
:)

Hope you are at the beginning of a great year!
Svante

ᐧ

2018-01-02 21:41 GMT+01:00 Joseph D. Wagner <jo...@josephdwagner.info>:

> I'm looking for the code in Simple API to set Margin and Page Size (Height
> and Width).
>
> I saw the example here about getOrCreateMasterPage, but that appears to
> work only with a page break.
>
> https://incubator.apache.org/odftoolkit/simple/document/cook
> book/Text%20Document.html#Get%20TextDocument
>
> I need to apply this to the first page of an empty doc.
>
> Thank you for your patience and help.  I'm very new to your library.
>
> Joseph D. Wagner
>
>