Converts Text, RTF string to PDF file.

Namespace:  SautinSoft
Assembly:  PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 5.3.4.18

Syntax

      
 C#  Visual Basic 
public int RtfToPdfConvertStringToFile(
	string inputString,
	string outputFileName
)
Public Function RtfToPdfConvertStringToFile ( _
	inputString As String, _
	outputFileName As String _
) As Integer

Parameters

inputString
String
RTF or Text document as string
outputFileName
String
Local path to output PDF file

Return Value

0 - converting successfully
2 - can't create output file, check the output path
3 - converting failed

Examples

CopyHow to convert RTF string to PDF file in C#
using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            //this property is necessary only for registered version
            //p.Serial = "XXXXXXXXXXX";

            //specify some options
            p.PageStyle.PageOrientation.Landscape();
            //specify header in HTML format
            p.Header.Html("<b>Sample header in HTML format</b>");

            //specify footer in RTF format
            p.Footer.Rtf("{\b Bold footer}");

            //specify page numbers
            p.PageStyle.PageNumFormat = "Page {page} of {numpages}";

            if (p != null)
            {
                string rtfPath = @"..\..\..\..\..\test.rtf";
                string pdfPath = @"..\..\..\..\..\test.pdf";
                string rtfString = "";


                //1. Get RTF content from file
                ReadFromFile(rtfPath,ref rtfString);


                //2. Converting RTF to PDF
                int i = p.RtfToPdfConvertStringToFile(rtfString,pdfPath);

                if (i==0)
                {
                    System.Diagnostics.Process.Start(pdfPath);
                }
                else
                {
                    System.Console.WriteLine("An error occured during converting HTML to PDF!");
                }
            }
        }
        public static int ReadFromFile(string fileName,ref string fileStr)
        {
            try
            {
                FileInfo fi = new FileInfo(fileName);
                StreamReader strmRead = fi.OpenText();
                fileStr = strmRead.ReadToEnd();
                strmRead.Close();
                return 0;
            }
            catch 
            {
                //error open file
                System.Console.WriteLine("Error in open file");
                return 1;
            }
        }
    }
}
CopyHow to convert RTF string to PDF file in VB.Net
Imports System
Imports System.IO
Imports System.Text

Module sample

    Sub Main()
        Dim p As New SautinSoft.PdfMetamorphosis

        'this property is necessary only for registered version
        'p.Serial = "XXXXXXXXXXX";


        'specify some options
        p.PageStyle.PageOrientation.Landscape()
        'specify header in HTML format
        p.Header.Html("<b>Sample header in HTML format</b>")

        'specify footer in RTF format
        p.Footer.Rtf("{\b Bold footer}")

        'specify page numbers
        p.PageStyle.PageNumFormat = "Page {page} of {numpages}"

        If Not p Is Nothing Then
            Dim rtfPath As String = "..\..\..\..\..\test.rtf"
            Dim pdfPath As String = "..\..\..\..\..\test.pdf"
            Dim rtfString As String = ""


            '1. Get RTF content from file
            ReadFromFile(rtfPath, rtfString)


            '2. Converting RTF to PDF
            Dim i As Integer = p.RtfToPdfConvertStringToFile(rtfString, pdfPath)

            If i = 0 Then
                System.Diagnostics.Process.Start(pdfPath)
            Else
                System.Console.WriteLine("An error occured during converting HTML to PDF!")
            End If
        End If
    End Sub
    Public Function ReadFromFile(ByVal fileName As String, ByRef fileStr As String) As Integer
        Try
            Dim fi As New FileInfo(fileName)
            Dim strmRead As StreamReader = fi.OpenText()
            fileStr = strmRead.ReadToEnd()
            strmRead.Close()
            Return 0
        Catch
            'error open file
            System.Console.WriteLine("Error in open file")
            Return 1
        End Try
    End Function
End Module

See Also