1) Use this class is using the jawin package that can be downloaded
here: http://sourceforge.net/projects/jawinproject/
or you can download it here:
http://www.sautinsoft.com/samples/jawin-2.0-alpha1.zip
http://www.sautinsoft.com/samples/jawin-2.0-alpha1-src.zip
2). Register DLL in your system, launch (it
is not necessary for automatic installer - htmltortf_pro_com.exe)
:
Regsvr32 Html2Rtf.dll
File "IConverter.java":
import org.jawin.*;
import org.jawin.constants.*;
import org.jawin.marshal.*;
import org.jawin.io.*;
import java.io.*;
public class IConverter extends DispatchPtr
{
public static GUID DIID = new GUID("{a5d34b4f-063d-11d9-B234-000D87800515}");
static public final int iidToken;
static {
iidToken = IdentityManager.registerProxy(DIID, IConverter.class);
}
public IConverter() throws COMException
{
super();
}
public IConverter(String progid) throws COMException { super(progid);}
public IConverter(IUnknown other) throws COMException { super(other);}
public IConverter(GUID ClsID) throws COMException { super(ClsID);}
public int ConvertFile(String HtmlFilePath,String OutputPath, String PageHeader, String PageFooter) throws COMException
{
return ((Integer)invokeN("ConvertFile", new Object[] {HtmlFilePath, OutputPath, PageHeader, PageFooter})).intValue();
}
public String Convert(String strHtml, String PageHeader, String PageFooter) throws COMException
{
return ((String)invokeN("Convert", new Object[] {strHtml, PageHeader, PageFooter}));
}
public void setPreserveTables(boolean PreserveTables) throws COMException
{
put("PreserveTables", PreserveTables);
}
public void setPreserveImages(boolean PreserveImages) throws COMException
{
put("PreserveImages", PreserveImages);
}
public void setPreserveHyperlinks(boolean PreserveHyperlinks) throws COMException
{
put("PreserveHyperlinks", PreserveHyperlinks);
}
public void setPreserveFontFace(boolean PreserveFontFace) throws COMException
{
put("PreserveFontFace", PreserveFontFace);
}
public void setPreserveFontSize(boolean PreserveFontSize) throws COMException
{
put("PreserveFontSize", PreserveFontSize);
}
public void setPreserveFontColor(boolean PreserveFontColor) throws COMException
{
put("PreserveFontColor", PreserveFontColor);
}
public void setPreserveBackgroundColor(boolean PreserveBackgroundColor) throws COMException
{
put("PreserveBackgroundColor", PreserveBackgroundColor);
}
public void setPreserveAlignment(boolean PreserveAlignment) throws COMException
{
put("PreserveAlignment", PreserveAlignment);
}
public void setPreserveTableWidth(boolean PreserveTableWidth) throws COMException
{
put("PreserveTableWidth", PreserveTableWidth);
}
public void setPreserveNestedTables(boolean PreserveNestedTables) throws COMException
{
put("PreserveNestedTables", PreserveNestedTables);
}
public void setPageMarginLeft(int PageMarginLeft) throws COMException
{
put("PageMarginLeft", PageMarginLeft);
}
public void setPageMarginRight(int PageMarginRight) throws COMException
{
put("PageMarginRight", PageMarginRight);
}
public void setPageMarginTop(int PageMarginTop) throws COMException
{
put("PageMarginTop", PageMarginTop);
}
public void setPageMarginBottom(int PageMarginBottom) throws COMException
{
put("PageMarginBottom", PageMarginBottom);
}
public void setBorderVisibility(int BorderVisibility) throws COMException
{
put("BorderVisibility", BorderVisibility);
}
public void setPageOrientation(int PageOrientation) throws COMException
{
put("PageOrientation", PageOrientation);
}
public void setPageSize(int PageSize) throws COMException
{
put("PageSize", PageSize);
}
public void setFontFace(int FontFace) throws COMException
{
put("FontFace", FontFace);
}
public void setFontSize(int FontSize) throws COMException
{
put("FontSize", FontSize);
}
public void setPageAlignment(int PageAlignment) throws COMException
{
put("PageAlignment", PageAlignment);
}
public void setRtfLanguage(int RtfLanguage) throws COMException
{
put("RtfLanguage", RtfLanguage);
}
public void setEncoding(int Encoding) throws COMException
{
put("Encoding", Encoding);
}
public void setOutputTextFormat(int OutputTextFormat) throws COMException
{
put("OutputTextFormat", OutputTextFormat);
}
}
File "html2rtf.java":
import org.jawin.*;
public class html2rtf {
public static void main(String[] args) {
String rtfString = "";
int ret = 0;
try {
IConverter iconv = new IConverter("Html2Rtf.Converter");
iconv.setPreserveTables(true);
iconv.setPreserveNestedTables(true);
iconv.setPreserveTableWidth(true);
rtfString = iconv.Convert("<html><body><p>Hello World!</p></body></html>", "", "");
ret = iconv.ConvertFile("C:/FormCheckerXtras/jawin/acetaminophen.htm", "C:/FormCheckerXtras/jawin/acetaminophen.rtf", "", "");
} catch (COMException e) { }
System.out.println("result:" + rtfString); System.out.println("result:" + ret); } }
|