© Copyright SautinSoft 2002 - 2007
(build 2.0.0 - June 5th, 2007)

Manual for HTML-to-RTF Pro DLL
- .Net component to convert HTML strings (files) to RTF, Text strings (files).
   about | methods and properties | code samples | html samples | faq | order and pricing | support and contacts

HTML-to-RTF Pro DLL .Net - methods and properties description

The component can convert HTML files(strings) into RTF or TXT files (strings) with images, tables, CSS etc.
This scheme shows all methods and properties of DLL component, but you can use not all of members, because all of them are already set by default to make conversion more precision.

Methods:
 ConvertString()
 ConvertFile()
 ConvertFileToString()
 ConvertStringToFile()

 
Properties:

text parameters:
 OutputTextFormat
 Encoding
 RtfLanguage
 FontFace
 FontSize
 PageAlignment
 PreserveFontFace
 PreserveFontSize
 PreserveFontColor
 PreserveHyperlinks
 PreserveHR
 RtfParts

page parameters:
 PageSize
 PageOrientation
 PageMarginLeft
 PageMarginRight
 PageMarginTop
 PageMarginBottom
 PreservepageBreaks
 PageHeader
 PageFooter
 PageNumbers
 PageNumbersAlignH
 PageNumbersAlignV
table parameters:
 PreserveTables
 PreserveTableWidth
 PreserveNestedTables
 BorderVisibility
 TableCellPadding
 DeleteTables

image parameters:
 PreserveImages
 PreserveHttpImages
 ImageCompatible
 HtmlPath (only for ConvertString method)
 DeleteImages
 BaseURL

color parameters:
 PreserveFontColor
 PreserveBackgroundColor

debug parameters:
 CreateTraceFile
 TraceFilePath

license parameters:
 Serial (required in full version)
 
   
   
   
   
string ConvertString(string htmlString) - this method takes HTML string and returns RTF string.
If want to convert HTML string with images, be sure that you have set the member HtmlPath
The parameter HtmlPath helps to converter find a full path to image, because HTML string doesn't have full path. For example, if converter meets <img src="images/img1.png"> and HtmlPath = "d:\" so component will try to open image from:

"d:\images\img1.png"

Example:
string htmlString = "<b>Hello world</b>";
string rtfString = "";
   
//create object (instance) of html2rtf converter
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();
if (h!=null)
{
	//set converter options
   h.OutputTextFormat = SautinSoft.HtmlToRtf.eOutputTextFormat.Rtf;
	h.HtmlPath = @"D:\";
   
   //convert strings
   rtfString = h.ConvertString(htmlString);
   System.Console.WriteLine(rtfString);
} 

int ConvertFile(string htmlFile, string outFolder) - this method converts HTML file into RTF file.

return values:

0 - converting OK
1 - can't open HTML file
2 - can't create RTF file
3 - memory error
4 - an input HTML has zero length

5 - unknown error


Example:
// create object (instance) of html2rtf converter
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();
h.ConvertFile("D:\test.htm", "d:\");

The method also supports internet paths, so you can use it to download HTML file from internet and next convert it to RTF.
For example:

h.ConvertFile("http://www.yahoo.com/", @"d:\test.rtf");

h.OutputTextFormat = SautinSoft.HtmlToRtf.eOutputTextFormat.Html;
h.ConvertFile("http://www.htmltortf.com/index.php", @"d:\test.html");

string ConvertFileToString(string htmlFile) - this method takes path to HTML file and returns RTF string.

int ConvertStringToFile(string htmlString, string rtfFile) - this method takes HTML string and path to output RTF file.

You may adjust the component and output RTF file will look as you wish.

PageHeader - put text in RTF page header (unlimited symbols max)


Possible values: any string
Default value: ""
Example:
h.pageHeader = "page Header Example";
Example:
h.pageHeader = "{\b Bold page Header Example}";
Example:
h.pageHeader = "{\b\i Bold Italic page Header Example}";
Example:
h.pageHeader = "{\qc Centered page Header Example}";

How to insert images in header or footer?

You can insert even complete HTML file with images and tables inside header and footer. But at first you have to convert it to RTF.
This a C# sample:

// create object of SautinSoft.HtmlToRtf
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();

//prepare header and footer with company logo
h.RtfParts = SautinSoft.HtmlToRtf.eRtfParts.RtfBody;

string header = h.ConvertString("<table width=\"100%\" border=\"0\">"+
"<tr>" +
"<td width=\"200\"><img src=\"d:\\logo.gif\" width=\"200\" height=\"100\"></td>"+
"<td><div align=\"center\"><font color=\"#0099FF\" size=\"4\">Some</font><em> text</em> in <strong>header</strong></div></td>"+
"</tr>"+
"</table>");
string footer = h.ConvertString("<table width=\"100%\" border=\"0\">"+
"<tr>" +
"<td width=\"200\"><img src=\"d:\\logo.gif\" width=\"100\" height=\"50\"></td>"+
"<td><div align=\"center\"><font color=\"#0099FF\" size=\"4\">Some</font><em> text</em> in <strong>footer</strong></div></td>"+
"</tr>"+
"</table>");

//convert general html to rtf
h.RtfParts = SautinSoft.HtmlToRtf.eRtfParts.RtfCompletely;
h.PageHeader = @"[header]";
h.PageFooter = @"[footer]";
string rtfString = h.ConvertFileToString(@"d:\test.htm");

//put new header and footer
rtfString = rtfString.Replace("[header]",header);
rtfString = rtfString.Replace("[footer]",footer);

//save rtf file
StreamWriter sw = new StreamWriter(@"d:\test.rtf",false);
sw.Write(rtfString);
sw.Close();

pageFooter - put text in RTF page footer (unlimited symbols max)


Possible values: any string
Default value: ""
Example:
h.pageFooter = "page Footer Example";

! If you don't want that header/footer appears in produced RTF document, use empty strings "".

borderVisibility - this property set table border's visibility;
or
Possible values: Hidden, SameAsOriginalHtml, Visible.
Integer values:

Name
Integer equivalent
Visible
1
Hidden
0
SameAsOriginalHtml
2

Default value: Hidden
Example:
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();
h.borderVisibility = Visible;
h.borderVisibility = 1;

Encoding - default Encoding of HTML page
Possible values: AutoSelect, ISO_8859_1, ISO_8859_5, KOI8_R, Windows_1250, Windows_1251, Windows_1252, Windows_1253, Windows_1254, Windows_1255, Windows_1256, Windows_1257, Windows_1258.
Integer values:

Name
Integer equivalent
AutoSelect
0
ISO_8859_1
1
ISO_8859_5
2
KOI8_R
3
Windows_1251
4
UTF_8
5
Windows_1254
6
Windows_1256
7
Windows_1250
8
Windows_1252
9
Windows_1253
10
Windows_1255
11
Windows_1257
12
Windows_1258
13

Default value: AutoSelect
Example:
h.Encoding = ISO_8859_1;
Example: h.Encoding = 1;

OutputTextFormat - type of output file (Rtf, Doc, Text or Html)
Possible values: Rtf, Doc, Text, Html.
Integer values:

Name
Rtf
Text
Html
Doc

Default value: Rtf
Example:
h.OutputTextFormat = SautinSoft.HtmlToRtf.eOutputTextFormat.Text;

FontFace - default font face
Possible values: f_Arial, f_Times_New_Roman, f_Verdana, f_Helvetica, f_Courier, f_Courier_New,
f_Times, f_Georgia, f_MS_Sans_Serif, f_Futura, f_Arial_Narrow, f_Garamond, f_Impact,
f_Lucida_Console, f_Tahoma, f_Inform, f_Symbol, f_WingDings, f_Traditional_Arabic
Integer values:

Name
Integer equivalent
f_Arial
0
f_Times_New_Roman
1
f_Verdana
2
f_Helvetica
3
f_Courier
4
f_Courier_New
5
f_Times
6
f_Georgia
7
f_MS_Sans_Serif
8
f_Futura
9
f_Arial_Narrow
10
f_Garamond
11
f_Impact
12
f_Lucida_Console
13
f_Tahoma
14
f_Inform
15
f_Symbol
16
f_WingDings
17
f_Traditional_Arabic
18

Default value: f_Arial
Example:
h.FontFace = SautinSoft.HtmlToRtf.eFontFace.f_Verdana;
Example:
h.FontFace = 2;

FontSize - default font size
Possible values: Any size
Default value: 10
Example:
h.FontSize = 12;

PageAlignment - default page alignment
Possible values: AlignLeft, AlignRight, AlignCenter, AlignJustify.
Integer values:

Name
Integer equivalent
AlignLeft
0
AlignCenter
1
AlignRight
2
AlignJustify
3

Default value: AlignLeft
Example:
h.PageAlignment = AlignLeft;
Example: h.PageAlignment = 0;

preserveAlignment - keep alignment as in HTML
or
Possible values: 1 or 0
Default value: 1

preserveTables - convert tables or transform to text
or
Possible values: 1 or 0
Default value: 1

preserveNestedTables - preserve nested tables as in HTML or transform it to plain tables
or
Possible values: 1 or 0
Default value: 1

PreserveImages - convert images or skip them (this feature works in all methods)
or
Possible values: 1 or 0
Default value: 1

PreserveHttpImages - download images which have remote path such as "<img src="http://..."> or <img src="www.google.com...> or skip them
or
Possible values: 1 or 0
Default value: 0

PreserveFontFace - keep font face as in HTML
or
Possible values: 1 or 0
Default value: 0

PreserveFontSize - keep font size as in HTML
or
Possible values: 1 or 0
Default value: 1

PreserveFontColor - keep font color as in HTML
or
Possible values: 1 or 0
Default value: 1

PreserveBackgroundColor - keep background color as in HTML (for table columns and text)

Possible values: 1 or 0
Default value: 1

PreserveHyperlinks - keep hyperlinks as in HTML
or
Possible values: 1 or 0
Default value: 1

PreserveTableWidth - keep width of table columns as in HTML
or
Possible values: 1 or 0
Default value: 1

PageSize - select page size for RTF

Possible values: A4, A3, A5, B5, Letter, Legal, Executive, Monarh
Default value: Letter
Integer values:

Name
Integer equivalent
A4
0
A3
1
A5
2
B5
3
Letter
4
Legal
5
Executive
6
Monarh
7

Example: h.PageSize = SautinSoft.HtmlToRtf.ePageSize.Legal;

PageOrientation - select page orientation: Portrait or Landscape

Possible values: Portrait or Landscape
Default value: Portrait
Integer values:

Name
Integer equivalent
Portrait
0
Landscape
1

Example: h.PageOrientation = SautinSoft.HtmlToRtf.ePageOrientation.Landscape

pageMarginLeft, pageMarginRight, pageMarginTop, pageMarginBottom - set page margins

Possible values: any value in millimeters
Default values:
   pageMarginLeft      = 25
   pageMarginRight    = 20
   pageMarginTop      = 20
   pageMarginBottom = 20

RtfLanguage - language which will be used for spelling in Microsoft Word
Possible values: l_Albanian, l_English, l_Belgian, l_Bulgarian, l_Hungarian, l_Danish, l_Spanish,
l_Italian, l_Latvian, l_Lithuanian, l_German, l_Netherlands, l_Norwegian, l_Portuguese, l_Romanian, l_Russian,
l_Ukrainian, l_Finnish, l_French, l_Czech, l_Swedish, l_Turkish, l_Arabic.
Integer values:

Name
Integer equivalent
l_Albanian
1052
l_English
1033
l_Belgian
2067
l_Bulgarian
1026
l_Hungarian
1038
l_Danish
1030
l_Spanish
3082
l_Latvian
1062
l_Lithuanian
1063
l_German
1031
l_Netherlands
1043
l_Norwegian
2068
l_Portuguese
2070
l_Romanian
1048
l_Russian
1049
l_Ukrainian
1058
l_Finnish
1035
l_French
1036
l_Czech
1029
l_Swedish
1053
l_Arabic
1053
l_Turkish
1055
l_Japanese
932
l_SimplifiedChinese
936
l_TraditionalChinese
950
l_Korean
949
l_Thai
874

Default value: l_English
Example:
h.RtfLanguage = SautinSoft.HtmlToRtf.eRtfLanguage.l_English

ImageCompatible - select image compatible: image_Word or image_WordPad

Possible values: image_Word or image_WordPad
Default value: image_Word
Integer values:

Name
Integer equivalent
image_Word
0
image_WordPad
1

When you selected image_Word the images will be strored in JPG, PNG and WMF formats:
{\pict...\pngblip....89504e470d0a1a0a000......}
{\pict...\jpegblip....ffd8ffe070d0a1a0a000......}
{\pict...\wmetafile8....010009000003de000......}

When you selected image_WordPad the images will be strored in BMP format:
{\pict...\dibitmap0....28000000690100......}

Example:
h.PageOrientation = SautinSoft.HtmlToRtf.ePageOrientation.image_WordPad

PreservepageBreaks - preserve page breaks as in HTML

If '1', then converter will create new page in RTF each time when it meet 'page-break-before:' or 'page-break-aftrer:'.
Possible values: 1 or 0
Default value: 0
This is example for page-breaks:

<HTML>
<HEAD>
<TITLE>page-break-after</TITLE>
<STYLE>
P.after {page-break-after: always}
P.before {page-break-before: always}
</STYLE>
</HEAD>
<BODY>
<p class="before">Some text</p>
<p class="after">Some text</p>
<p>Some text</p>
</BODY>
</HTML>

 

PageNumbers - put page numbers

Possible values: pageNumDisable, pageNumFirst and pageNumSecond
Default value: pageNumDisable
Integer values:

Name
Integer equivalent
pageNumDisable
0
pageNumFirst
1
pageNumSecond
2

Example: h.PageNumbers = SautinSoft.HtmlToRtf.ePageNumbers.pageNumFirst

PageNumbersAlignH - horizontal alignment of page numbers
Possible values: AlignLeft, AlignRight, AlignCenter.
Integer values:

Name
Integer equivalent
AlignLeft
0
AlignCenter
1
AlignRight
2

Default value: AlignCenter
Example:
h.PageNumbersAlignH = SautinSoft.HtmlToRtf.ePageAlignment.AlignLeft

PageNumbersAlignV - vertical alignment of page numbers
Possible values: AlignTop, AlignBottom
Integer values:

Name
Integer equivalent
AlignTop
4
AlignBottom
5

Default value: AlignBottom
Example:
h.PageNumbersAlignV = SautinSoft.HtmlToRtf.ePageAlignment.AlignLeft

PreserveHR - keep horizontal rule <HR> as in HTML

Possible values: 1 or 0
Default value: 1

RtfParts - allows to create completely RTF or only RTF body which you can insert inside another RTF file

Possible values: RtfCompletely, RtfBody
Default value: RtfCompletely

Name
Integer equivalent
RtfCompletely
0
RtfBody
1


Example:
h.RtfParts = SautinSoft.HtmlToRtf.eRtfParts.RtfBody

CreateTraceFile - forces DLL to create tracing text file, this file shows you debug info and helps find some errors

Possible values: 0 or 1
Default value: 0
Example:
h.CreateTraceFile = 1
By default tracing file will be created on C:\htmltortf-trace.txt, you can also specify path for this file using this parameter:

TraceFilePath - path for tracing file

Possible values: any string
Default value: "C:\htmltortf-trace.txt"
Example:
h.TraceFilePath = @"D:\report.txt";


HtmlPath - path of HTML file, needs to convert HTML string with images and CSS

This parameter helps to component find a full path to images and CSS external file when you are using method ConvertString() or ConvertStringToFile()

Possible values: any string
Default value: ""
Example:
h.HtmlPath = @"D:\my webs\";

TableCellPadding - set default cell padding in pix for all tables inside converting file

Possible values: 0 to 10
Default value: 2
Example:
h.TableCellPadding = 10;

Serial - your individual serial number to activate your product copy

After purchasing you will get the full version of product and your serial number. This parameter doesn't have any effect in trial version. This parameter is necessary in full version, please don't forget to spcify it by your serial number.

Possible values: any string
Default value: ""
Example:
h.Serial = "XXXXXXXXX";

DeleteImages - specify that component removes images from input HTML

For example if you are converting from HTML to HTML converter will remove all tags <img ...>. If you are converting from HTML to RTF you will also not see images if this parameter is specified to 1.

Possible values: 0 or 1
Default value: 0
Example:
h.DeleteImages = 1;

DeleteTables - specify that component removes all tables from input HTML

For example if you are converting from HTML to HTML converter will remove all table's tags like a <table>, <tr>, <td>. If you are converting from HTML to RTF you will also not see tables if this parameter is specified to 1.

Possible values: 0 or 1
Default value: 0
Example:
h.DeleteTables = 1;

BaseURL - specify base URL for HTML

For example if you are converting remote HTML and it has only relative path to images, for example <img src="images\logo.jpg">, specify domain name as this parameter.

Possible values: any string
Default value: ""
Example:

h.BaseURL =
"http://www.sautinsoft.com/";
h.PreserveHttpImages = 1;
h.ConvertFile(@"http://www.sautinsoft.com",@"d:\test.rtf");