© Copyright SautinSoft 2002 - 2009
(3.0.0 - February 18th, 2009)

Manual for RTF-to-HTML DLL COM
- component to convert Text, RTF strings (files) to HTML, XHTML strings (files).
     about | methods and properties | code samples | rtf samples | order and pricing | license | support and contacts
 
VB 6.0
ASP/ VBScript sample
Java
ASP.Net samples
PHP
 
VB 6.0

1. Register DLL in your system, run:
regsvr32 RTF2HTML.dll

2 . Add a reference to the “SautinSoft Rtf-to-Html DLL” control:

3. This is sample function:

Private Function TestRTF2HTML() As String
Dim strRet As String
Dim h As New RTF2HTML.Converter
h.OutputFormat = RTF2HTML.Html
h.Encoding = RTF2HTML.Windows_1252
strRet = h.ConvertFile("D:\test.rtf", "D:\HTML files\")
MsgBox strRet
End Function

ASP/ VBScript sample

1. Register DLL in your system, launch: Regsvr32 Rtf2Html.dll

Sample1:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Private Function TestRTF2HTML() As String
Dim strRet As String
Dim ImageFolder As String
Dim ImageSubFolder As String
Dim h As New RTF2HTML.Converter

h.Encoding = RTF2HTML.eEncoding.ISO_8859_1
h.PreserveImages = True
h.OutputFormat = RTF2HTML.html
h.FontFace = "Arial"
h.PreserveFontFace = True
h.PreserveFontColor = True

ImageFolder = "D:\"
ImageSubFolder = ""
strRet = h.ConvertString("This test string", ImageFolder, ImageSubFolder)
MsgBox strRet
End Function
%>


Sample2:

This is example of function on VBScript:

<% set fs = server.CreateObject("scripting.filesystemobject") set h = server.CreateObject("RTF2HTML.Converter") h.OutputFormat = RTF2HTML.Html_with_CSS h.PreserveFontColor = True h.PreserveFontSize = True h.PreserveImages = True strOut = h.ConvertString(strOut, "", "") set h = nothing strhtmlname = "Html_" & session.SessionID & ".html"'gets unique name strPhysicalFileName = server.MapPath("../temp") &"\" & strhtmlname strURL = "../temp/" & strhtmlname
if not fs.FileExists(strPhysicalFileName) then
fs.CreateTextFile strPhysicalFileName
end if
set myHtml = fs.OpenTextFile(strPhysicalFileName,2)
myHtml.write strout
myHtml.close
set fs=nothing
response.redirect strURL
%>

Java

1) Use this class is using the jawin package that can be downloaded here: http://sourceforge.net/projects/jawinproject/
2). Register DLL in your system, launch:

Regsvr32 Html2Rtf.dll

IConverter.java

import org.jawin.*;
public class IConverter
extends DispatchPtr {
public static GUID DIID = new GUID("{1A21ED6F-1BB2-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 String ConvertString(String strRtf) throws COMException {
return ( (String) invokeN("ConvertString", new Object[] {strRtf}));
}
public String ConvertFiletoString(String RtfFilePath) throws COMException {
return ( (String) invokeN("ConvertFiletoString", new Object[] {RtfFilePath}));
}
public void setPreserveImages(boolean PreserveImages) throws COMException {
put("PreserveImages", PreserveImages);
}
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 setOutputFormat(int OutputFormat) throws COMException {
put("OutputFormat", OutputFormat);
}
public void setEncoding(int Encoding) throws COMException {
put("Encoding", Encoding);
}
public void setTableBorders(boolean TableBorders) throws COMException {
put("TableBorders", TableBorders);
}
public void setHtmlParts(int HtmlParts) throws COMException {
put("HtmlParts", HtmlParts);
}
public void setFontFace(String FontFace) throws COMException {
put("FontFace", FontFace);
}
public void setFontSize(String FontSize) throws COMException {
put("FontSize", FontSize);
}
public void setTitle(String Title) throws COMException {
put("Title", Title);
}
public void setFileExtension(String FileExtension) throws COMException {
put("FileExtension", FileExtension);
}
}
ConvertServlet.java

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import java.io.*;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jawin.*;
public class ConvertServlet
extends HttpServlet{
public ConvertServlet() {
}
public void init() throws ServletException {
super.init();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
MultipartRequest multi = new MultipartRequest(request,
"/files", 0x1f4000, new DefaultFileRenamePolicy());
Enumeration files = multi.getFileNames();
StringBuffer sb = new StringBuffer();
IConverter iconv = new IConverter(new GUID("{1A21ED6F-1BB2-11D9-B234-000D87800515}"));
iconv.setOutputFormat(1);
iconv.setEncoding(9);
iconv.setPreserveFontFace(false);
iconv.setPreserveFontColor(false);
iconv.setPreserveFontSize(false);
iconv.setPreserveImages(false);
while (files.hasMoreElements()) {
String name = (String) files.nextElement();
File fbin = multi.getFile(name);
FileReader f = new FileReader(fbin.getPath());
int k;
while((k = f.read()) != -1){
sb.append( (char) k);
}
}

String html = iconv.ConvertString(sb.toString());
html = html.replaceAll("charset=iso-8859-1", "charset=iso-8859-15");
System.out.println("ConvertServlet.html: \n" + html);
out.println(html);
}
catch (Exception e) {
e.printStackTrace(out);
}
}
public void destroy() {
}
}


ASP.Net

Sample 1 - ASP.Net/VB

1. Install HTML2RTF on the webserver.
2. Use regsvr32 to register the DLL, launch: Regsvr32 Rtf2Html.dll
3. Request the aspx page in a browser from a client

rtf2html.aspx

<%@ Page Language="VB" validaterequest="False" AspCompat="True" %>
<script runat="server">
Sub Rtf2Html(sender As Object, e As EventArgs)
Dim str_HTML As String
Dim obj_HTML = Server.CreateObject("RTF2HTML.Converter")
obj_HTML.PreserveImages = False
str_HTML = obj_HTML.ConvertString(txt_rtf.Text, "", "")
txt_HTML.Text = str_HTML
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<strong><u>RTF text</u></strong>
<br />
<asp:TextBox id="txt_rtf" runat="server" Width="600px" TextMode="MultiLine" Height="250px"></asp:TextBox>
</p>
<p>
<strong><u>HTML text</u></strong>
<br />
<asp:TextBox id="txt_html" runat="server" Width="600px" TextMode="MultiLine" Height="250px"></asp:TextBox>
</p>
<p>
<asp:Button id="btn_rtf2html" onclick="Rtf2Html" runat="server" Text="RTF to HTML"></asp:Button>
</p>
</form>
</body>
</html>

PHP

$rtf2htmlCom = new COM("RTF2HTML.Converter");
$rtf2htmlCom->PreserveImages=true;
$rtf2htmlCom->OutputFormat = 1;
$rtfFile = "C:\\Inetpub\\wwwroot\\rtf2htm\\Word1.rtf";
$htmlFile ="C:\\Inetpub\\wwwroot\\rtf2htm\\Word1.htm";
$result =$rtf2htmlCom->ConvertFile($rtfFile,$htmlFile);
print($result);
unset($rtf2htmlCom);
echo "done";

Copyright © 2002-2009, SautinSoft. All rights reserved.