Как заменить значение в RTF документе другим RTF на C# и .NET


Полный код

using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
			// Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/
	
            // How to replace values in RTF document by another RTF content.
            // If you need more information about "HTML to RTF .Net" email us at:
            // [email protected]	
            ReplaceValuesInRtf();
        }

        public static void ReplaceValuesInRtf()
        {
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();

            // For example, we've RTF with such content "This is a sample footer as RTF document."
            // Let's replace the string "sample" by another RTF file.
            string sourceRtfFile = @"..\..\..\footer.rtf";
            string wherewithReplaceRtfPath = @"..\..\..\footer.rtf";
            string textToReplace = "sample";
            string resultRtfFile = "Result.rtf";
            
            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile);

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultRtfFile) { UseShellExecute = true });
        }
    }
}

Download

Imports System
Imports System.IO

Namespace Sample
	Friend Class Test

		Shared Sub Main(ByVal args() As String)
			' Get your free 30-day key here:   
            ' https://sautinsoft.com/start-for-free/
	
			' How to replace values in RTF document by another RTF content.
			' If you need more information about "HTML to RTF .Net" email us at:
			' [email protected]	
			ReplaceValuesInRtf()
		End Sub

		Public Shared Sub ReplaceValuesInRtf()
			Dim h As New SautinSoft.HtmlToRtf()

			' For example, we've RTF with such content "This is a sample footer as RTF document."
			' Let's replace the string "sample" by another RTF file.
			Dim sourceRtfFile As String = "..\..\..\footer.rtf"
			Dim wherewithReplaceRtfPath As String = "..\..\..\footer.rtf"
			Dim textToReplace As String = "sample"
			Dim resultRtfFile As String = "Result.rtf"

			h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile)

			' Show the result.
			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultRtfFile) With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.