Merge two RTF strings and create new sinlge RTF document
Namespace:
SautinSoftAssembly: SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 4.6.10.19
Syntax
| C# | Visual Basic |
Return Value
A merged RTF document or empty string in case of merging failed
Remarks
A merged RTF document will contain 1st RTF document and next 2nd RTF document by order.


Examples
using System; using System.IO; namespace Sample { class Test { static void Main(string[] args) { //Merge two RTF documents in memory //If you need more information about HTML-to-RTF Pro DLL .Net email us at: //support[at]sautinsoft.com SautinSoft.HtmlToRtf objH = new SautinSoft.HtmlToRtf(); //objH.Serial = "XXXXXXXXXXXXXXX"; string firstRtf=""; string secondRtf=""; string singleRtf=""; //1. Read contents of the RTF files firstRtf=ReadFileString(@"d:\report1.rtf"); secondRtf=ReadFileString(@"d:\report2.rtf"); //Merge two RTF strings in memory and get a new single RTF string singleRtf = objH.MergeRtfString(firstRtf, secondRtf); /// <returns>A merged RTF document or empty string in case of merging failed</returns> if(singleRtf!="") { int ret=WriteToFile(@"d:\single.rtf",singleRtf); if (ret==0) System.Diagnostics.Process.Start(@"d:\single.rtf"); } } public static string ReadFileString(string path) { using (StreamReader reader = new StreamReader(path)) { return reader.ReadToEnd(); } } public static int WriteToFile(string fileName, string contents) { try { StreamWriter sw = new StreamWriter(fileName); sw.Write(contents); sw.Close(); } catch { return 2; } return 0; } } }
Imports System Imports System.IO Imports System.Text Module Module1 Sub Main() 'Merge two RTF documents in memory 'If you need more information about HTML-to-RTF Pro DLL .Net email us at: 'support[at]sautinsoft.com Dim objH As New SautinSoft.HtmlToRtf 'objH.Serial = "XXXXXXXXXXXXXXX"; Dim firstRtf As String = "" Dim secondRtf As String = "" Dim singleRtf As String = "" '1. Read contents of the RTF files firstRtf = ReadFromFile("d:\report1.rtf") secondRtf = ReadFromFile("d:\report2.rtf") 'Merge two RTF strings in memory and get a new single RTF string singleRtf = objH.MergeRtfString(firstRtf, secondRtf) ''' <returns>A merged RTF document or empty string in case of merging failed</returns> If singleRtf <> "" Then Dim ret As Integer = WriteToFile("d:\single.rtf", singleRtf) If ret = 0 Then System.Diagnostics.Process.Start("d:\single.rtf") End If End If End Sub Public Function ReadFromFile(ByVal fileName As String) As String Dim fileString As String = "" Try Dim fs As System.IO.FileStream = New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read) Dim b(CInt(Fix(fs.Length)) - 1) As Byte If fs.Read(b, 0, CInt(Fix(fs.Length))) > 0 Then Dim arCharRes(fs.Length - 1) As Char For i As Integer = 0 To fs.Length - 1 arCharRes(i) = ChrW(b(i)) Next i fileString = New String(arCharRes) End If fs.Close() Return fileString Catch Return "" End Try End Function Public Function WriteToFile(ByVal fileName As String, ByVal fileStr As String) As Integer Try Dim sw As New StreamWriter(fileName, False) sw.Write(fileStr) sw.Close() Catch Return 2 End Try Return 0 End Function End Module