Page 1 of 1

Best practice for generating documents

PostPosted: Fri Feb 23, 2018 3:35 am
by Kai_
Hi all,

Are there any best practices for generating a document by deleting sections from a template? (Sections purely in the sense below, not the Word sense)

My main use of docx4j is as a document generator.

Documents typically have:

Heading 1

Clause i

Clause ii

Sub-heading a

Clause i...

Heading 2

Sub-heading a

Clause I

Table

Image...

Heading 3...etc.


However sometimes Heading 2 (and all content) isn't relevant, so I'd like to delete it.

The system that I have working currently relies on hardcoded indexes (i.e. getContents(12).remove(), get contents(13).remove()...), so everything is thrown out of whack if I or someone helping me adds a new clause somewhere in the middle.

I was hoping that the tree structure would store paragraphs inside headings, making them simple to delete, but evidently this isn't how the docx format works.

Struggling to decide whether or not to use content controls, which I can train someone to use while editing my docs, OpenDoPE (could someone who isn't a programmer still help me update my documents with this?), or other tools and how to go about this.

Thanks in advance,
Kai_

Re: Best practice for generating documents

PostPosted: Fri Feb 23, 2018 8:37 pm
by jason
Kai_ wrote:I was hoping that the tree structure would store paragraphs inside headings, making them simple to delete, but evidently this isn't how the docx format works.


You can use content controls to the same effect.

OpenDoPE content control data binding introduces a "conditional" content control, so that the content control will be removed if the XPath condition evaluates to false.

Since you can nest these (and repeats), you can use pretty complex logic if you need to.

Non-programmers do edit OpenDoPE templates. You can always enhance or replace the authoring tool if you want.

At run time, is your system interactive (ie user with web browser) or batch?

Re: Best practice for generating documents

PostPosted: Sat Feb 24, 2018 11:28 am
by Kai_
Thanks for the time and answer Jason, I'll do a bit more reading about XPaths and have a read through one of your samples.

I'm looking into batch processing (maybe via an excel spreadsheet) for a majority of the controls first, and then using a Word custom sidebar to delete / replace the final few. No idea where to even start on that, but that's the next mission :D

Thanks!