горизонтально расположенные полосы: белая, синяя, красная

Как конвертировать RTF в PDF на C# и VB.NET

Конвертирование RTF-файла в файл PDF

using System;
using System.IO;
using System.Collections;
namespace Sample
{
  class Test
  {
    static void Main(string[] args)
    {
      SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis()
      // After purchasing the license, please insert your serial number here to activate the component
      //p.Serial = "XXXXXXXXXXX";

      // Specify some page options.
      p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;

      // Set page header in HTML format.
      p.PageSettings.Header.FromString("<b style=\"color: green;\">Sample header in HTML format</b>", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);

      // Set page footer in RTF format.
      p.PageSettings.Footer.FromString("{\\rtf1 \\b Bold Footer in RTF fotmat}", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf);

      // Set page numbers.
      p.PageSettings.Numbering.Text = "Page {page} of {numpages}";

      if (p != null)
      {
        string rtfPath = @"..\..\example.rtf";
        string pdfPath = Path.ChangeExtension(rtfPath, ".pdf");
        int i = p.RtfToPdfConvertFile(rtfPath, pdfPath);
        if (i != 0)
        {
          System.Console.WriteLine("An error occurred during converting RTF to PDF!");
        }
        else
        {
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true });
        }
      }
    }
  }
}
Imports System
Imports System.IO
Imports System.Collections
Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component
      'p.Serial = "XXXXXXXXXXX";

      ' Specify some page options.
      p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape

      ' Set page header in HTML format.
      p.PageSettings.Header.FromString("<b style="color: green;">Sample header in HTML format</b>", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html)

      ' Set page footer in RTF format.
      p.PageSettings.Footer.FromString("{\rtf1 \b Bold Footer in RTF format}", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf)

      ' Set page numbers.
      p.PageSettings.Numbering.Text = "Page {page} of {numpages}"

      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = Path.ChangeExtension(rtfPath, ".pdf")

        Dim i As Integer = p.RtfToPdfConvertFile(rtfPath, pdfPath)
        If i <> 0 Then
          System.Console.WriteLine("An error occurred during converting RTF to PDF!")
        Else
          System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfPath) With {.UseShellExecute = True})
        End If
      End If
    End Sub
  End Class
End Namespace

Конвертирование строки RTF в байты PDF

using System;
using System.IO;
using System.Collections;
namespace Sample
{
class Test
  {
    static void Main(string[] args)
    {
      SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
      // After purchasing the license, please insert your serial number here to activate the component.
      //p.Serial = "XXXXXXXXXXX";

      // Specify some options.
      p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;

      // Specify page numbers.
      p.PageSettings.Numbering.Text = "Page {page} of {numpages}";

      if (p != null)
      {
        string rtfPath = @"..\..\example.rtf";
        string pdfPath = Path.ChangeExtension(rtfPath, ".pdf");
        byte[] rtfBytes = File.ReadAllBytes(rtfPath);

        // Converting RTF to PDF
        byte[] pdfBytes = p.RtfToPdfConvertByte(rtfBytes);
        if (pdfBytes != null)
        {
          // Save the PDF document to a file for a viewing purpose.
          File.WriteAllBytes(pdfPath, pdfBytes);
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true });
        }
        else
        {
          System.Console.WriteLine("An error occurred during converting RTF to PDF!");
        }
      }
    }
  }
}
Imports System.IO

Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component.
      'p.Serial = "XXXXXXXXXXX"

      ' Specify some options.
      p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape

      ' Specify page numbers.
      p.PageSettings.Numbering.Text = "Page {page} of {numpages}"

      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = Path.ChangeExtension(rtfPath, ".pdf")
        Dim rtfBytes() As Byte = File.ReadAllBytes(rtfPath)

        ' Converting RTF to PDF
        Dim pdfBytes() As Byte = p.RtfToPdfConvertByte(rtfBytes)
        
        If pdfBytes IsNot Nothing Then
          ' Save the PDF document to a file for a viewing purpose.
          File.WriteAllBytes(pdfPath, pdfBytes)
          System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfPath) With {.UseShellExecute = True})
        Else
          System.Console.WriteLine("An error occurred during converting RTF to PDF!")
        End If
      End If
    End Sub
  End Class
End Namespace

Конвертирование RTF-строки в PDF-файл

using System;
using System.IO;
using System.Collections;
namespace Sample
{
class Test
  {
    static void Main(string[] args)
    {
      SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
      // After purchasing the license, please insert your serial number here to activate the component.
      //p.Serial = "XXXXXXXXXXX";
      if (p != null)
      {
        string rtfPath = @"..\..\example.rtf";
        string pdfPath = Path.ChangeExtension(rtfPath,".pdf");

        // 1. Get RTF content from file
        string rtfString = File.ReadAllText(rtfPath);

        // 2. Convert RTF string to a PDF file
        if (p.RtfToPdfConvertStringToFile(rtfString,pdfPath)==0)
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true });
        else
          System.Console.WriteLine("An error occurred during converting RTF to PDF!");
      }
    }
  }
}
Imports System.IO
Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component.
      'p.Serial = "XXXXXXXXXXX"
      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = Path.ChangeExtension(rtfPath, ".pdf")

        ' 1. Get RTF content from file
        Dim rtfString As String = File.ReadAllText(rtfPath)

        ' 2. Convert RTF string to a PDF file
        If p.RtfToPdfConvertStringToFile(rtfString, pdfPath) = 0 Then
          System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfPath) With {.UseShellExecute = True})
        Else
          System.Console.WriteLine("An error occurred during converting RTF to PDF!")
        End If
      End If
    End Sub
  End Class
End Namespace

Инструмент для .NET-преобразования RTF в PDF без автоматизации MS Office

"Our team of developers tasked to create a web-service which required a tool to convert RTF files into PDF under .Net without using MS Office Automation. Google search gave a lot of results, but most of components require MS Word or Adobe products, either the price was not acceptable for us. Some search results followed to Sautinsoft web-site and their PDF Metamorphosis .Net. Guys from online support helped us to create testing project with speed of F1🙂!" (из письма нашего клиента)

Фрагмент кода для преобразования RTF в PDF без использования MS Word:

SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
string[] rtfFiles = System.IO.Directory.GetFiles(@"c:\folder with pdfs\", ".rtf");
foreach (string rtfFile in rtfFiles)
{
	p.RtfToPdfConvertFile(rtfFile, Path.GetFileNameWithoutExtension(rtfFile) + ".pdf");
}

Другие примеры кода SautinSoft.PdfMetamorphosis

DOCX/DOC в PDF ✦ RTF в PDF HTML в PDF Text в PDF Всё в PDF Split/Merge PDF Настройки PDF Запароленный PDF Watermark
 ВВЕРХ