This blog post shares a GenDoc feature I did not know we had for flexible index generation.

GenDoc Index Generation

The GenDoc project has come a long way since its inception many years ago. In the early days, we faced two significant challenges in the realm of document generation that couldn't be easily tackled within PHP code. These challenges were the inclusion of documents within other documents and the insertion of an index at specific points in a document.

To address these issues, we developed a Java application that leveraged the capabilities of the OpenOffice headless service. We introduced two directives to make these tasks possible: {include document} for document inclusion and {insertindex} for adding an index.

Fast forward to February 2020, when we made a significant breakthrough by incorporating the include functionality directly into PHP, reducing our reliance on Java. However, the index functionality remained tied to Java. In the past year, unoconv updated its codebase, rendering the previous version obsolete. We had to adapt to this change and make our system compatible with the latest unoconv API.

But here's the exciting news: during this transition, we discovered that the new unoconv version is smarter than ever. It autonomously searches any document you send its way for an OpenOffice index and seamlessly updates it. This means that the need for manual index management has greatly diminished.

In the old days, you would use the {insertindex} directive to specify the location of the index within your document. We would then replace this directive with a fully functional index and ensure it displayed the correct page numbers. However, styling and formatting options were limited, leaving users with a somewhat default index appearance.

Today, you still have the option to use the {insertindex} directive if you have Java and OpenOffice headless installed. However, you can also insert an index into your document using Open Office's built-in tools. This means you have full control over the style and appearance of your index, which will automatically generate when we convert the ODT document to PDF. This also has another advantage, the {insertindex} directive will repeat the same index everywhere you add it in the document while, using the native Open Office index support we can have different indexes in different parts of the document (like an automatically generated appendix) and they will all update correctly.

There is a slight caveat to this improved process. The automatic index update will only occur when you convert your document to PDF because this is when we send it to the unoconv server. In other words, if you download the ODT version, you'll need to manually update the index if necessary.

With this enhancement, you can now harness all the powerful features of GenDoc without the hassle of installing Java and OpenOffice headless service. Instead, all you need is the unoconv Docker container, making document generation more accessible and flexible than ever before.


Photo by Maksym Kaharlytskyi on Unsplash

Previous Post Next Post