DocIO throws error when converting from html to sfdt
P粉373990857
P粉373990857 2023-09-09 21:58:02
0
1
549

I switched from the old Primeface RichEditor to syncfusion WordEditor and used the class below to convert 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 deal with the old register, I get the following problem "Element type 'br' must be terminated by a matching closing tag". From what I've read, this is because DocIO validates that the content follows the xhtml 1 format. Is there a way to tell DocIO to ignore errors, or not validate the format?

P粉373990857
P粉373990857

reply all(1)
P粉244155277

About - I get the following issue "Element type 'br' must be terminated by a matching closing tag:

The input HTML string is not well-formed HTML (the "br" element has no closing tag).

RequiredWord Library (DocIO ) supports only well-formed HTML (a given HTML content must conform to the rules or standards of the XHTML 1.0 format). To resolve this issue, use well-formed HTML, such as a "br" element with correct opening and closing tags in the HTML string.

About - Is there a way to tell DocIO to ignore errors, or not validate the format?

No. There is no way to ignore the error and validate the format in the DocIO library. To resolve this issue, use well-formed HTML in DocIO, such as an HTML string with correct element opening and closing tags.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!