(3.0.9.1 - March 27th, 2009)


Manual for HTML-to-RTF Pro DLL .Net
- pure C# component to convert HTML to Word, HTML to DOC, HTML to RTF, HTML to Text. Works with strings and 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 may specify only few of them, because all of properties are already set by default to make conversion as original.
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 or URL into RTF file.

return values:

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



Example:
//create an object of the HTML-to-RTF Pro .Net
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();
h.ConvertFile(@"d:\test.htm", @"d:\test.rtf");

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 or URL 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 HTML file with 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 an 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:

eBorderVisibility
Visible
Hidden
SameAsOriginalHtml

Default value: Hidden
Example:

SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();
h.borderVisibility = eBorderVisibility.Visible;

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:

eEncoding
AutoSelect
ISO_8859_1
ISO_8859_5
KOI8_R
Windows_1251
UTF_8
Windows_1254
Windows_1256
Windows_1250
Windows_1252
Windows_1253
Windows_1255
Windows_1257
Windows_1258

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

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

eOutputTextFormat
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:

eFontFace
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

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

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

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

ePageAlignment
AlignLeft
AlignCenter
AlignRight
AlignJustify

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

preserveAlignment - (bool) keep alignment as in HTML
or
Possible values: true or false
Default value: true

preserveTables - (bool) convert tables or transform to text
or
Possible values: true or false
Default value: true

preserveNestedTables - (bool) preserve nested tables as in HTML or transform it to plain tables
or
Possible values: true or false
Default value: true

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

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

PreserveFontFace - (bool) keep font face as in HTML
or
Possible values: true or false
Default value: true

PreserveFontSize - (bool) keep font size as in HTML
or
Possible values: true or false
Default value: true

PreserveFontColor - (bool) keep font color as in HTML
or
Possible values: true or false
Default value: true

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

Possible values: true or false
Default value: true

PreserveHyperlinks - (bool) keep hyperlinks as in HTML
or
Possible values: true or false
Default value: true

PreserveTableWidth - (bool) keep width of table columns as in HTML
or
Possible values: true or false
Default value: true

PageSize - select page size for RTF

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

ePageSize
A4
A3
A5
B5
Letter
Legal
Executive
Monarh

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

PageOrientation - select page orientation: Portrait or Landscape

Possible values: Portrait or Landscape
Default value: Portrait

ePageOrientation
Portrait
Landscape

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

pageMarginLeft, pageMarginRight, pageMarginTop, pageMarginBottom - set page margins

Possible values: any float value in millimeters
Default values:
   pageMarginLeft      = 25.0f;
   pageMarginRight    = 20.0f;
   pageMarginTop      = 20.0f;
   pageMarginBottom = 20.0f;

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.

eRtfLanguage
l_Albanian
l_English
l_Belgian
l_Bulgarian
l_Hungarian
l_Danish
l_Spanish
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_Arabic
l_Turkish
l_Japanese
l_SimplifiedChinese
l_TraditionalChinese
l_Korean
l_Thai

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

eImageCompatible
image_Word
image_WordPad

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 - (bool) preserve page breaks as in HTML

If 'true', then converter will create new page in RTF each time when it meet 'page-break-before:' or 'page-break-aftrer:'.
Possible values: true or false
Default value: true

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

ePageNumbers
pageNumDisable
pageNumFirst
pageNumSecond

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

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

ePageAlignment
AlignLeft
AlignCenter
AlignRight

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

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

ePageAlignment
AlignTop
AlignBottom

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

PreserveHR - (bool) keep horizontal rule <HR> as in HTML

Possible values: true or false
Default value: true

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

eRtfParts
RtfCompletely
RtfBody


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

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

Possible values: true or false
Default value: false
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 true.

Possible values: true or false
Default value: false
Example:
h.DeleteImages = true;

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: true or false
Default value: false
Example:
h.DeleteTables = true;

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 = true;
h.ConvertFile(@"http://www.sautinsoft.com",@"d:\test.rtf");

© Copyright SautinSoft™ 2002 - 2009