Ask Your Question

Creating a "table of content" for a doc-file in a HTML to DOC conversion

asked 2017-12-18 13:03:11 +0200

kaasstick gravatar image

I was wondering if it is possible to create a "Table of Contents" dynamicly in the conversion process.

I've written a PHP script which puts some html together then adds the footer and header using the sdfield tag(<div title="footer"> <center><sdfield type=PAGE subtype=RANDOM format=PAGE>14</sdfield>/<sdfield type=DOCSTAT subtype=PAGE format=PAGE>14</sdfield></center> </div>) to a HTML file. Then I convert the HTML file to a DOC file (using soffice --headless --convert-to doc:"MS Word 97") because that is the result we're aiming for.

The file is nearly perfect to our requirements except for the missing "Table of contents" (preferably on page 3). However at this point i'm lost. Is there a special tag I can use here? Or is it possible to use some sort of document as a template so that i can insert the table tag beforehand?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-12-18 14:29:48 +0200

ajlittoz gravatar image

updated 2017-12-18 20:17:54 +0200

You definitely need to insert some sort of tag at the location where you want your TOC. But this solves only half the problem.

Contents of the TOC is gathered from specific paragraph styles, but default Heading 1 to Heading 10. To make your TOC from <H1> to H6>, you need to customize the TOC engine. The simplest way is to define a template with paragraph styles H1 to H6 matching your taste for sections headings. In Outline & Numbering tab of style definition, give the required outline level to your Hx styles (1 for H1, 2 for H2, etc.).

Save the template.

Do the conversion, then import the styles from your template and Tools->Update->Update all.

Since this implies manual process, you can insert the TOC with Insert->Tables & Indexes->Tables & Indexes on the same occasion.

This procedure can be automated with macros but I never used any.

If this answer helped you, please accept it by clicking the check mark ✔ to the left and, karma permitting, upvote it. If this resolves your problem, close the question, that will help other people with the same question.

edit flag offensive delete link more


actually the TOC engine doesn't seem to have any issues with the H1~H6 tags.. since after conversion i added the TOC manually and that gave the exact result we're aiming for.

however.. the question "What tag" remains.

Your solution requires my environment to run the gui, however that's not an option for me on this server environment. Thanks for explaining your approach though!

kaasstick gravatar imagekaasstick ( 2017-12-18 15:08:53 +0200 )edit

answered 2017-12-19 10:30:36 +0200

kaasstick gravatar image

Maybe an alternative solution would be simpler. I've created references (anchor links) and those seem to work fine, now all I need it to get the pagenumber for the item so I can show them.

edit flag offensive delete link more


I assume you generate then your TOC with fields. Fields may display content, section number, page number, … You just need to enter two fields: one for content, the other one for page number.

ajlittoz gravatar imageajlittoz ( 2017-12-19 14:42:42 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-12-18 13:03:11 +0200

Seen: 346 times

Last updated: Dec 19 '17