I switched from my old Primeface RichEditor to syncfusion WordEditor, and I use the bellow class to transform from html to sdft
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import com.syncfusion.docio.FormatType;
import com.syncfusion.docio.WordDocument;
import com.syncfusion.ej2.wordprocessor.WordProcessorHelper;
public class SFDTAdapter {
public static String sfdtToRtf(String sfdt) throws Exception {
return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Rtf).toString();
}
public static String rtfToSfdt(String rtf) throws Exception {
byte[] bytes = rtf.getBytes(StandardCharsets.UTF_8);
InputStream stream = new ByteArrayInputStream(bytes);
WordDocument document = new WordDocument(stream, FormatType.Rtf);
String sfdt = WordProcessorHelper.load(document);
document.close();
stream.close();
return sfdt;
}
public static String htmlToSfdt(String html) throws Exception {
byte[] bytes = html.getBytes(StandardCharsets.UTF_8);
InputStream stream = new ByteArrayInputStream(bytes);
WordDocument document = new WordDocument(stream, FormatType.Html);
String sfdt = WordProcessorHelper.load(document);
document.close();
stream.close();
return sfdt;
}
public static String sfdtToHtml(String sfdt) throws Exception {
return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Html).toString();
}
}
However, when I process old registers I get the following issue "The element type 'br' must be terminated by the matching end-tag ". According to what I readed, this is because DocIO validates that the content follow the format xhtml 1. Is there a way to say to DocIO that ignore errors, or doesn't verify that format?
Regarding - I get the following issue "The element type 'br' must be terminated by the matching end-tag:
The input HTML string is not well formatted HTML (‘br’ element doesn’t have an end tag).
Essential Word library (DocIO) supports only well formatted HTML (the given HTML content must be in accordance with rules or standards of XHTML 1.0 format). To resolve this issue, please use well-formatted HTML like ‘br’ element has proper start and end tags in the HTML string.
Regarding - Is there a way to say to DocIO that ignore errors, or doesn't verify that format?
No. There is no way to ignore that errors and verify that format in DocIO library. To resolve the issue, please use well-formatted HTML in DocIO like HTML string that has proper element’s start and end tags.