org-mode-ox-odt
org-mode-ox-odt copied to clipboard
Implement `org-odt-export-string-as-odt-string` function (a parallel to ox.el's `org-export-string-as` function)
Implement org-export-string-as-odt
function (a parallel to ox.el's org-export-string-as
function)
Cc @PiotrPanasiuk
This bug is a result of discussion https://github.com/kjambunathan/org-mode-ox-odt/discussions/180
Generate Page Header using `org-odt-export-string-as-odt-string' and Org Babel
Note that the snippet below uses org-odt-export-string-as-odt-string',
nxml-modestyle blocks and
noweb` expansion to configure page headers.
To get this
Generate Page Header using `org-odt-export-string-as-odt-string' and Org Babel
do this
#+TITLE: Generate Page Header using `org-odt-export-string-as-odt-string' and Org Babel
#+attr_odt: :target "extra_styles"
#+begin_src nxml
<style:style style:name="MyPageHeader"
style:parent-style-name="Heading"
style:next-style-name="Subtitle"
style:family="paragraph"
style:class="chapter">
<style:paragraph-properties fo:text-align="center"
style:justify-single-word="false" />
<style:text-properties fo:font-size="14pt"
fo:font-weight="bold"
style:font-size-asian="14pt"
style:font-size-complex="14pt"
style:font-weight-asian="bold"
style:font-weight-complex="bold" />
</style:style>
#+end_src
#+name: headertext
#+begin_src org :exports none
,#+ATTR_ODT: :style "MyPageHeader"
,#+begin_header
# Since the content is routed through ~shell~, the line breaks are
# double-escaped.
[[https://Orgmode.org][/Emacs Orgmode/]]\\\\
,#+end_header
#+end_src
#+name: tostring-headertext
#+begin_src sh :noweb yes :exports none :results verbatim
cat <<EOF
<<headertext>>
EOF
#+end_src
#+name: tonxml-tostring-headertext
#+begin_src emacs-lisp :exports none :var string=tostring-headertext
(org-odt-export-string-as-odt-string string)
#+end_src
#+RESULTS: tonxml-tostring-headertext
: <text:p text:style-name="MyPageHeader"><text:a xlink:type="simple" xlink:href="https://orgmode.org"><text:span text:style-name="Emphasis">Emacs Orgmode</text:span></text:a><text:line-break/></text:p>
#+attr_odt: :target "master_styles"
#+begin_src nxml :noweb yes
<style:master-page style:name="Standard"
style:page-layout-name="Mpm1">
<style:header>
<<tonxml-tostring-headertext()>>
</style:header>
<style:footer>
<text:p text:style-name="MP1">
<text:page-number text:select-page="current"></text:page-number>
</text:p>
</style:footer>
</style:master-page>
#+end_src
First page first page first page first page first page first page
first page first page first page first page first page first page
first page first page first page first page first page.
#+ATTR_ODT: :page-break t
Second page second page second page second page second page second
page second page second page second page second page second page
second page second page second page second page second page second
page.
#+ATTR_ODT: :page-break t
Third page third page third page third page third page third
page third page third page third page third page third page
third page third page third page third page third page third
page.
Here is an improved version which eliminates sh
block with EOF
constructs and uses org-babel-expand-noweb-references
and org-babel-goto-named-src-block
.
This basically removes one moving part and improves reliability.
#+TITLE: Generate Page Header using `org-odt-export-string-as-odt-string' and Org Babel
#+attr_odt: :target "extra_styles"
#+begin_src nxml
<style:style style:name="MyPageHeader"
style:parent-style-name="Heading"
style:next-style-name="Subtitle"
style:family="paragraph"
style:class="chapter">
<style:paragraph-properties fo:text-align="center"
style:justify-single-word="false" />
<style:text-properties fo:font-size="14pt"
fo:font-weight="bold"
style:font-size-asian="14pt"
style:font-size-complex="14pt"
style:font-weight-asian="bold"
style:font-weight-complex="bold" />
</style:style>
#+end_src
#+name: headertext/org
#+begin_src org :exports none
,#+ATTR_ODT: :style "MyPageHeader"
,#+begin_header
# Since the content is routed through ~shell~, the line breaks are
# double-escaped.
[[https://Orgmode.org][/Emacs Orgmode/]]\\
,#+end_header
#+end_src
#+name: headertext/nxml
#+begin_src emacs-lisp :exports none :var name="headertext/org"
(org-odt-export-string-as-odt-string
(org-babel-expand-noweb-references
(org-babel-goto-named-src-block name)))
#+end_src
#+attr_odt: :target "master_styles"
#+begin_src nxml :noweb yes
<style:master-page style:name="Standard"
style:page-layout-name="Mpm1">
<style:header>
<<headertext/nxml()>>
</style:header>
<style:footer>
<text:p text:style-name="MP1">
<text:page-number text:select-page="current"></text:page-number>
</text:p>
</style:footer>
</style:master-page>
#+end_src
First page first page first page first page first page first page
first page first page first page first page first page first page
first page first page first page first page first page.
#+ATTR_ODT: :page-break t
Second page second page second page second page second page second
page second page second page second page second page second page
second page second page second page second page second page second
page.
#+ATTR_ODT: :page-break t
Third page third page third page third page third page third
page third page third page third page third page third page
third page third page third page third page third page third
page.
For me this solution is kind of complicated and hard to use on production. Do see any hope for the improvement? Is it possible to use it with #+odt_styles_file: base_style1.ott at all, becouse I have tried few times w/o success :(.
For me this solution is kind of complicated and hard to use on production. Do see any hope for the improvement? Is it possible to use it with #+odt_styles_file: base_style1.ott at all, becouse I have tried few times w/o success :(.
There is some experimental code in my work area which can allow custom headers and footers, and it is much easier to use. I will be committing the changes in next few weeks, .... and in anticipation of this feature I opened a bug for myself for yesterday Add an ability to specify Page Header and Footers through Org snippets.
Your request is very much in radar. I quickly reviewed this and the linked bug description.
IIUC, you wanted a link in page header.
Since it is almost 6 months, I think you may have changed your mind. What do you want in your header and footer.
Since you seem interested in easily configurable header and footer elements, I may very well accelerate the fixing of this code.
So, yes ... let me know what you want in the header and footer.
You wanted a link in the Page Header ... What else? If you specify your requirement, I will build my unit test around that.
With header I could managed by myself and even I have added a picture somehow (only converted svg in draw works) but with the link in the footer it is difficult. In my case I think about possibility to add a Document Number at the bottom of document which is wrapped in the footer with table. Nice thing to have would be possibility to i.e. DN as the link with location somewhere in intranet. To spot more light for my layout please check the attachment. document_template.zip
With header I could managed by myself and even I have added a picture somehow (only converted svg in draw works) but with the link in the footer it is difficult. In my case I think about possibility to add a Document Number at the bottom of document which is wrapped in the footer with table. Nice thing to have would be possibility to i.e. DN as the link with location somewhere in intranet. To spot more light for my layout please check the attachment. document_template.zip
You no longer have to use the Babel blocks to create headers and footers. See my https://github.com/kjambunathan/org-mode-ox-odt/commit/07a1ca90e4bee9b2e2d19e2d8e465d563071ce08.
Use the following zip
file. The file has comments inline, and it should answer all the question you have
document_template_modified.zip
As the comment in the snippet says,
Macro expansion within link doesn't work [[{{{DocUrl}}}][DN: {{{DocID}}}]], but macro expansion in link description works. That is, these work
- [[https://orgmode.org][{{{DocUrl}}}]]
- {{{DocUrl}}}
Please file a feature report against [[https://lists.gnu.org/archive/html/emacs-orgmode/]] if you want macro expansion to happen in the hyperlink portion of ~org links~.
I am copying the contents in the above zip file here, so that the contents gets indexed by search engines.
To get this
A ODT document with a logo as a header, and document metadata as footer.
do this
# #+ODT_VALIDATE: abort
#+options: ':nil *:t -:t ::t <:t H:2 \n:nil ^:t arch:headline
#+options: author:nil broken-links:nil c:nil creator:nil
#+options: d:(not "LOGBOOK") date:nil e:t email:t f:t inline:t num:t
#+options: p:nil pri:t prop:t stat:t tags:t tasks:t tex:t latex:t
#+options: timestamp:t title:t todo:nil toc:nil |:t
#+LANGUAGE: en
#+tags: Pytanie(P) Development(D) Odwołanie(O) NC(n) C(c) Risk(r)
#+PRIORITIES: A C B
#+select_tags: export
#+exclude_tags: noexport
#+creator: Emacs 28.1 (Org mode 9.5.5)
#+description:
#+keywords:
# #+odt_preferred_output_format: ott
#+odt_preferred_output_format: pdf
# #+odt_styles_file: base_style1.ott
#+odt_extra_images:
#+odt_extra_styles:
#+odt_extra_automatic_styles:
#+odt_master_styles:
#+odt_content_template_file:
#+odt_automatic_styles:
#+odt_display_outline_level: 2
#+bib_file:
#+ODT_DOCUMENT_PROPERTIES: DOC-TITLE DOC-SUBTITLE DOC-STATUS DOC-ID DOC-VERSION DOC-CREATED-DATE DOC-MODIFIED-DATE DOC-URL
#+title: Org-Mode
#+subtitle: Organise your life
#+email:
#+DOC-TITLE: Org-MOde
#+DOC-SUBTITLE: Organise your life
#+DOC-STATUS: Version
#+DOC-ID: DN: 00008889990
#+DOC-VERSION: 1
#+DOC-CREATED-DATE: [2022-12-01 czw]
#+DOC-MODIFIED-DATE: <2022-12-01 czw>
#+DOC-URL: https://orgmode.org
#+MACRO: DocTitle {{{keyword-to-documentproperty(DOC-TITLE)}}}
#+MACRO: DocSubTitle {{{keyword-to-documentproperty(DOC-SUBTITLE)}}}
#+MACRO: DocStatus {{{keyword-to-documentproperty(DOC-STATUS)}}}
#+MACRO: DocID {{{keyword-to-documentproperty(DOC-ID)}}}
#+MACRO: DocVersion {{{keyword-to-documentproperty(DOC-VERSION)}}}
#+MACRO: DocURL {{{keyword-to-documentproperty(DOC-URL)}}}
#+MACRO: CreatedDate {{{keyword-to-documentproperty(DOC-CREATED-DATE)}}}
#+MACRO: ModifiedDate {{{keyword-to-documentproperty(DOC-MODIFIED-DATE)}}}
#+PAGEBREAK:
#+TOC: headlines 2
# +TOC: listings
#+TOC: tables
* APPROVALS
Voluptate elit, nulla qui irure laboris nulla adipiscing. Incididunt
exercitation excepteur aute occaecat magna culpa id. Do proident,
laboris dolore consequat voluptate esse occaecat. Occaecat excepteur
commodo laborum deserunt laboris dolor adipiscing. Eu duis labore
cillum do qui proident, nisi.
* DOCUMENT HISTORY
Sed qui incididunt minim sed voluptate proident, culpa quis laborum
aliquip non in.
* RELATED DOCUMENTS
Id consequat sunt velit consequat enim ullamco esse. Dolor cillum
fugiat nostrud culpa elit, culpa voluptate. Sed esse amet, ea officia
anim deserunt nostrud pariatur consectetur cillum anim. Excepteur
nulla sint eiusmod elit, laboris velit officia. Eu adipiscing dolore
mollit consequat magna sint elit,.
* Title 1
:PROPERTIES:
:ATTR_ODT: :page-break t :page-style "OrgPage"
:END:
# Macro expansion within link doesn't work [[{{{DocUrl}}}][DN:
# {{{DocID}}}]], but macro expansion in regular text works:
- [[https://orgmode.org][{{{DocUrl}}}]]
- {{{DocUrl}}}
Page 1
* Title 2
:PROPERTIES:
:ATTR_ODT: :page-break t
:END:
Page 2
* Title 3
:PROPERTIES:
:ATTR_ODT: :page-break t
:END:
Page 3
#+BEGIN_CENTER
*END OF DOCUMENT*
#+END_CENTER
* Footnotes
Start the first page with ~OrgFirstPage~, so that second and
subsequent pages use ~OrgPage~ style.
#+ATTR_ODT: :target "extra_styles"
#+begin_src nxml
<style:style style:name="OrgTitle"
style:parent-style-name="Title"
style:family="paragraph"
style:master-page-name="OrgFirstPage">
<style:paragraph-properties style:page-number="auto" />
<style:text-properties fo:font-size="24pt" />
</style:style>
#+end_src
----------------
Supper ~Page Number~ in ~OrgFirstPage~.
#+ATTR_ODT: :page-style "OrgFirstPage"
#+begin_footer
#+end_footer
----------------
Configure ~Header~ of ~OrgPage~
~OrgPage~ has a ~header~ and a ~footer~.
- ~header~ has an image
- ~footer~ has a table with ~Document Metadata~, and a legal T&C.
The ~header~ is centered has a bottom rule / border. See
~Header~.
#+ATTR_ODT: :page-style "OrgPage"
#+begin_header
#+ATTR_ODT: :style "Header"
#+begin_center
#+ATTR_ODT: :width 5 :inner-frame (anchor "as-char")
[[./hdrimage.svg]]
#+end_center
#+end_header
#+ATTR_ODT: :target "extra_styles"
#+begin_src nxml
<style:style style:name="Header"
style:parent-style-name="Text_20_body"
style:family="paragraph">
<style:paragraph-properties fo:border-bottom="0.06pt solid #000000"
fo:border-left="none"
fo:border-right="none"
fo:border-top="none"
fo:padding="0.049cm"
fo:text-align="center"
style:justify-single-word="false" />
</style:style>
#+end_src
----------------
Configure ~Footer~ of ~OrgPage~
#+ATTR_ODT: :page-style "OrgPage"
#+begin_footer
#+ATTR_ODT: :widths "2,1"
| {{{DocSubTitle}}} | [[https://orgmode.org][DN: {{{DocID}}}]] |
| {{{DocTitle}}} | {{{DocVersion}}} |
#+begin_center
This document is not to be reproduced, modified, adapted, published,
translated in any material form in whole or in part nor disclosed to
any third party without the prior written permission of community -
All rights reserved
{{{ODTPageNumber}}}/{{{ODTPageCount}}}
#+end_center
#+end_footer
Do ~M-x org-odt-insert-style-from-file~ RET ~OrgPageLayout~ RET. And
in the resulting ~nxml~ block create a
~<style:header-style>...</style:header-style>/~ with a header width of
~min-width~ of ~6cm~. Note that the header image has a width of
~5cm~.
----------------
If you export the below file you will see that the ~Footer~ size is
too display the contents. So increase the ~Footer~ height. Use the
~LibreOffice UI~ to fix the footer height.
Use ~M-x org-odt-insert-style-name-or-style-definition-from-file~,
pick the ~OrgPageLayout~ style (= page layout used by [[https://github.com/kjambunathan/org-mode-ox-odt/blob/d1d85a80a1db367b6df3e6c5e7d82f2f9517edeb/etc/styles/OrgOdtStyles.xml#L1102][~OrgPage~]] style)
and increase the ~fo:min-height~ of
~<style:footer-style>...</style:footer-style>~ to ~5 cm~.
#+ATTR_ODT: :target "extra_automatic_styles"
#+begin_src nxml
<style:page-layout style:name="OrgPageLayout"
style:page-usage="mirrored">
<style:page-layout-properties fo:margin-bottom="2cm"
fo:margin-left="2cm"
fo:margin-right="2cm"
fo:margin-top="2cm"
fo:page-height="29.7cm"
fo:page-width="21.001cm"
style:footnote-max-height="0cm"
style:num-format="1"
style:print-orientation="portrait"
style:writing-mode="lr-tb">
<style:footnote-sep style:adjustment="left"
style:color="#000000"
style:distance-after-sep="0.101cm"
style:distance-before-sep="0.101cm"
style:line-style="solid"
style:rel-width="25%"
style:width="0.018cm" />
</style:page-layout-properties>
<style:header-style />
<style:footer-style>
<style:header-footer-properties fo:margin-left="0cm"
fo:margin-right="0cm"
fo:margin-top="0.499cm"
fo:min-height="5cm"
style:dynamic-spacing="false" />
</style:footer-style>
</style:page-layout>
#+end_src