Malformed input RTF for the ScroogeXHTML convert method may cause unexpected errors, exceptions, or empty output documents. If you need to see and verify the RTF code which is actually sent to the convert() method, you may add this code just before the conversion:

  Files.write(Paths.get("example.rtf"),
    rtf.getBytes(StandardCharsets.US_ASCII));

The RTF will be written to a new file in the current directory. Please note: the code will replace an existing file with the same name.

Full example code

package com.scroogexhtml.examples;

import com.scroogexhtml.ScroogeXHTML;
import java.io.File;
import java.io.IOException;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Test {

    public static void main(String[] args) throws IOException {

        String rtf = "{\\rtf1 ... }";

        // create a converter instance
        ScroogeXHTML scrooge = new ScroogeXHTML();

        // configure conversion options
        scrooge.setAddOuterHTML(true);
        scrooge.setConvertTables(true);

        Files.write(Paths.get("example.rtf"),
          rtf.getBytes(StandardCharsets.US_ASCII));

        // convert RTF and write HTML to file
        scrooge.convert(rtf, new File("example.html"));
    }
}

File content of example.rtf

{\rtf1 ...}

File content of example.html

<!DOCTYPE html>
<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Untitled document</title>
    <meta content="ScroogeXHTML for the Java(tm) platform 8.0" name="generator">
  </head>
  <body>
    <p>...</p>
  </body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.