How to do Mail Merge from Java

Are you developing software that needs to generate documents or reports?

With Docmosis you can quickly and easily add Mail Merge document generation to any application.

Docmosis can output in multiple formats: PDF, ODT, Doc, DocX, HTML and RTF.

Start with Mail Merge style TEMPLATES

Templates allow you to visually layout and format a document.

Docmosis templates are just regular documents, created using Microsoft Word or OpenOffice, with added placeholders for any dynamic content.

Java Mail Merge

The document production process is simple:

  1. Your application passes data to Docmosis. For example: XML/JSON.
  2. Docmosis merges the data with your template, to produce the finished document.
  3. Docmosis delivers the document to the specified destinations.


// Mail Merge from  myTemplate.doc  to  result.pdf
File templateFile = new File("myTemplate.doc");
File outputFile = new File("result.pdf");
DocumentProcessor.renderDoc(myTemplateFile, outputFile, buildData());


The power of Docmosis comes from the combination of:

  • our simple plain-text templating placeholders (eg: <<name>>), plus
  • your templates inherit the powerful features of the editors used to create them.

Docmosis allows you to:

  • Develop and maintain documents faster than an “all code” solution.
  • Layout your documents visually using editors you already know.
  • Output in two or more formats – without writing any extra code.
  • Easily collaborate on document design with Business Teams and End Users

Creating Templates is EASY

Docmosis templates can be created using Microsoft Word or OpenOffice Writer - with NO plug-ins.

There is no need to learn a new report-writing-tool with limited features.


Here is a few of the many things you can do with the Docmosis templating system:

  • Insert dynamic text or images into the: body; headers and footers.
  • Add/remove any content based on conditional data.
  • Modify formatting during document generation based on the data.
  • Expand table rows, numbered lists and bullet lists to match the data.
  • Dynamically insert images and watermarking.
  • Hyperlink insertion.
  • Insert HTML content.


Download example Templates/Data/Output files from our Examples section.


Start a Free Trial

Great features in one Mail-Merge Engine

Docmosis has taken the best of mail-merging principles to the application space:

  • Normal word processor documents - no plug-ins or customisations
  • Word and OpenOffice input formats supported including doc, docx and odt.
  • Great output options including PDF, ODT, DOC, DOCX, RTF and HTML.
  • Some of the most complex requirements are simple to do, like: don't break table-rows, keep-together, repeat table heading, page numbering etc.
  • Scalable from simple use to continuous multi-threaded, distributed performance.

How good is it?

Docmosis has been engineered for performance from the outset with a focus on low-memory footprint, stream-oriented and pre-optimized rendering and built-in load distribution facilities.

The output is typically very impressive, particularly PDF results which are high quality (zoom well) searchable and can even be password protected or created in archive format PDF/A-1.

Docmosis is used in: Defence, Finance, Legal, Logisitics, Health, Education and Technology applications, trusted by some very busy customers.

Some of our customers have also been kind enough to share some sample documents:

view sample documents

Test our team

We give you full access to our Support Team during your evaluation.

If you aren't sure if Docmosis suits your particular application then just contact support  tell us what you are trying to do.

We have many years of experience with creating documents using mail merge techniques.

Start here for an INTODUCTION to DOCMOSIS.