Convert Markdown into DOCX(document) format

Hello Team,

Could you please help us or suggest any predefined classes that can convert Markdown into a document format, similar to HTMLToPDFTool?

Hello,

I would suggest using the DocxTool helper class and especially the DoxTool.addHTML after having converted your Markdown to HTML using MarkdownTool.toHTML

Means, first step MarkdownTool.toHTML, it will convert into html after that DOCXTool.addHTML?

and addHTML method return type void so how it will save into a document format Please suggest

As a matter if fact there is no example in the documentation for the helper class DocxTool (there are some in the Demo though). We will add one.

In your case it should look like:

DocxTool dt = new DocxTool();
dt.newDocument();
dt.addHTML(html);
byte[] d = dt.toByteArray();

Note the underlying Java lib used by this DocxTool helper class is docx4j which is rather slow and resources consuming

PS:

I verified it is OK with a publication of a business object attribute of type “long text” with rendering “Markdown”:

Publication code:

package com.simplicite.objects.Application;

import com.simplicite.util.*;
import com.simplicite.util.annotations.*;
import com.simplicite.util.exceptions.*;
import com.simplicite.util.tools.*;

public class AppTest1 extends ObjectDB {
	@BusinessObjectPublication
	public Object toDocx(PrintTemplate pt) {
		String html =
			"<div style=\"font-family: sans-serif\">"
			+ MarkdownTool.toHTML(getFieldValue("appTstMarkdown"))
			+ "</div>";

		DocxTool dt = new DocxTool();
		dt.newDocument();
		dt.addHTML(html);
		return dt.toByteArray();
	}
}

Usage example of the above publication:


The downloaded file looks like this:

PS: the doc has been updated to provide examples for Docx: Documents code examples | Simplicité Documentation

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.