Question

I need to do the following (with Grails):

  1. Read a word template
  2. Add user details (e.g. name, last name) to the document
  3. Send the customized word by mail

I am thinking in Apache POI to read .doc, then in the document I will have keywords e.g."°!"#$" and make the customization. Then I will create the document, send it (with Grails plugin) and erase the document from the server

Is this a good approach or I am forgetting something? Thank you very much

EDIT: DOCx4j: My docx operations are simple, so I can go with the "approach 1" in the variable replace, but for some reason the next sample is not working for me: https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/VariableReplace.java

I'm getting a:

| Error 2014-03-27 09:10:23,640 [http-bio-9000-exec-5] ERROR errors.GrailsExceptionResolver  - SAXParseException occurred when processing request: [POST] /Estrategia/pasantiaCorta/generarDocumento
Content is not allowed in prolog.. Stacktrace follows:
Message: Content is not allowed in prolog.

In the line:

// Approach 1 (from 3.0.0; faster if you haven't yet caused unmarshalling to occur):

documentPart.variableReplace(mappings);
Was it helpful?

Solution

Sure, you can use POI or docx4j. For either, you'd be much better off using docx rather than the legacy binary doc format.

For docx4j (my project), see creating-word-docx-documents-dynamically-from-grails

At your step 2 (add user details), there are a variety of approaches you can use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top