Merge two RTF strings and create new sinlge RTF document

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 5.8.2.8

Syntax

      
 C#  Visual Basic 
public string MergeRtfString(
	string rtf1,
	string rtf2
)
Public Function MergeRtfString ( _
	rtf1 As String, _
	rtf2 As String _
) As String

Parameters

rtf1
String
1st RTF document as string
rtf2
String
2nd RTF document as string

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

CopyMerge multiple RTF documents using C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Merge multiple RTF files
            // If you need more information about "HTML to RTF .Net" email us at:
            // support[at]sautinsoft.com        
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
            // After purchasing the license, please insert your serial number here to activate the component
            //h.Serial = "XXXXXXXXXXXXXXX";

            DirectoryInfo htmlDir = new DirectoryInfo(@"..\..\..\..\..\..\Testing HTMLs");

            // Array with several RTF files.            
            string[] rtfFiles = new string[] { "footer.rtf", "footer.rtf", "footer.rtf" };
            string singleRtf = String.Empty;

            // Let's divide RTF documents using page break.
            h.MergeOptions.PageBreakBetweenDocuments = true;

            foreach (string rtfFile in rtfFiles)
            {
                string rtfFilePath = Path.Combine(htmlDir.FullName, rtfFile);

                // Copy 1st RTF to 'singleRtf'
                if (String.IsNullOrEmpty(singleRtf))
                    singleRtf = File.ReadAllText(rtfFilePath);
                // Merge 2nd, 3rd ....
                else
                    singleRtf = h.MergeRtfString(singleRtf, File.ReadAllText(rtfFilePath));
            }
            // Save 'singleRtf' to a file only for demonstration purposes.
            string singleRtfPath = Path.Combine(htmlDir.FullName, "single.rtf");
            File.WriteAllText(singleRtfPath, singleRtf);
            System.Diagnostics.Process.Start(singleRtfPath);
        }
    }
}
CopyMerge multiple RTF documents using VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' Merge multiple RTF files
        ' If you need more information about "HTML to RTF .Net" email us at:
        ' support[at]sautinsoft.com        
        Dim h As New SautinSoft.HtmlToRtf()
        ' After purchasing the license, please insert your serial number here to activate the component
        'h.Serial = "XXXXXXXXXXXXXXX";


        Dim htmlDir As New DirectoryInfo("..\..\..\..\..\Testing HTMLs")

        ' Array with several RTF files.            
        Dim rtfFiles() As String = {"footer.rtf", "footer.rtf", "footer.rtf"}
        Dim singleRtf As String = String.Empty

        ' Let's divide RTF documents using page break.
        h.MergeOptions.PageBreakBetweenDocuments = True

        For Each rtfFile As String In rtfFiles
            Dim rtfFilePath As String = Path.Combine(htmlDir.FullName, rtfFile)

            ' Copy 1st RTF to 'singleRtf'
            If String.IsNullOrEmpty(singleRtf) Then
                singleRtf = File.ReadAllText(rtfFilePath)
                ' Merge 2nd, 3rd ....
            Else
                singleRtf = h.MergeRtfString(singleRtf, File.ReadAllText(rtfFilePath))
            End If
        Next rtfFile
        ' Save 'singleRtf' to a file only for demonstration purposes.
        Dim singleRtfPath As String = Path.Combine(htmlDir.FullName, "single.rtf")
        File.WriteAllText(singleRtfPath, singleRtf)
        System.Diagnostics.Process.Start(singleRtfPath)
    End Sub
End Module

See Also