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

Как настроить выходной PDF-файл на C# и VB.NET

Как настроить продуцируемый PDF-файл

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

      // PDF Metamorphosis .Net generates PDF 1.5 document by default.
      // Let's change the PDF version to PDF_A.
      p.PdfSettings.PdfVersion = SautinSoft.PdfMetamorphosis.PdfSetting.PdfVersions.PDF_A;
      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 });
        }
      }
    }
  }
}
Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      ' How to set a version for the PDF document.
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component
      'p.Serial = "XXXXXXXXXXX"

      ' PDF Metamorphosis .Net generates PDF 1.5 document by default.
      ' Let's change the PDF version to PDF_A.
      p.PdfSettings.PdfVersion = SautinSoft.PdfMetamorphosis.PdfSetting.PdfVersions.PDF_A
      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = "..\..\test.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

Как добавить водяной знак в PDF

using System;
using System.IO;
using System.Collections;
namespace Sample
{
  class Test
  {
    static void Main(string[] args)
    {
      SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
      SautinSoft.PdfMetamorphosis.WaterMark w1 = new SautinSoft.PdfMetamorphosis.WaterMark(@"..\..\WaterMark.png");
      w1.PosX.Mm = 0;
      w1.PosX.Mm = 0;
      w1.PosDX.Mm = 50;
      w1.PosDY.Mm = 50;

      p.WaterMarks.Add(w1);

      SautinSoft.PdfMetamorphosis.WaterMark w2 = p.WaterMarks.Add();
      w2.Img = System.Drawing.Image.FromFile(@"..\..\WaterMark.png");
      w2.Transparency = 20;
      w2.PosX.Mm = 60;
      w2.PosY.Mm = 0;
      w2.PosDX.Mm = 100;
      w2.PosDY.Mm = 100;
      w2.SelectedPages = new int[] { 1 };
      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 });
        }
      }
    }
  }
}
Module sample
  Sub Main()
    Dim p As New SautinSoft.PdfMetamorphosis()
    Dim w1 As New SautinSoft.PdfMetamorphosis.WaterMark("..\..\WaterMark.png")
    w1.PosX.Mm = 0
    w1.PosX.Mm = 0
    w1.PosDX.Mm = 50
    w1.PosDY.Mm = 50

    p.WaterMarks.Add(w1)

    Dim w2 As SautinSoft.PdfMetamorphosis.WaterMark = p.WaterMarks.Add()
    w2.Img = System.Drawing.Image.FromFile("..\..\WaterMark.png")
    w2.Transparency = 20
    w2.PosX.Mm = 60
    w2.PosY.Mm = 0
    w2.PosDX.Mm = 100
    w2.PosDY.Mm = 100
    w2.SelectedPages = New Integer() {1}
    If p IsNot Nothing Then
      Dim rtfPath As String = "..\..\example.rtf"
      Dim pdfPath As String = "..\..\test.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 Module

Как добавить верхний и нижний колонтитулы страницы в PDF

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

      //Let's add page header in HTML format
      string headerInHtml = "<table width=\"100%\" border=\"1\"><tr><td width=\"50%\" align=\"center\"></td><td>You are welcome!</td></tr></table>";
      p.PageSettings.Header.FromString(headerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);

      string footerInRtf = @"{\rtf1\i Italic footer}";
      p.PageSettings.Footer.FromString(footerInRtf, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf);

      if (p != null)
      {
        string inputFile = @"..\..\example.htm";
        string outputFile = Path.ChangeExtension(inputFile, ".pdf");
        int result = p.HtmlToPdfConvertFile(inputFile, outputFile);
        if (result == 0)
        {
          System.Console.WriteLine("Converted successfully!");
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true });
        }
          else
          {
            System.Console.WriteLine("Converting Error!");
          }
        }
      }
    }
  }
}
Module sample
  Sub Main()
    'How to add page header and footer
    Dim p As New SautinSoft.PdfMetamorphosis()
    'After purchasing the license, please insert your serial number here to activate the component
    'p.Serial = "XXXXXXXXXXX"

    'Let's add page header in HTML format
    Dim headerInHtml As String = "<table width="100%" border="1"><tr><td width="50%" align="center"></td><td>You are welcome!</td></tr></table>"
    p.PageSettings.Header.FromString(headerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html)

    Dim footerInRtf As String = "{\rtf1\i Italic Header}"
    p.PageSettings.Footer.FromString(footerInRtf, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf)
    If p IsNot Nothing Then
      Dim inputFile As String = "..\..\example.htm"
      Dim outputFile As String = "..\..\test.pdf"
      Dim result As Integer = p.HtmlToPdfConvertFile(inputFile, outputFile)

      If result = 0 Then
        System.Console.WriteLine("Converted successfully!")
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outputFile) With {.UseShellExecute = True})
      Else
        System.Console.WriteLine("Converting Error!")
      End If
    End If
  End Sub
End Module
using System;
using System.IO;
using System.Collections;
namespace Sample
{
  class Test
  {
    static void Main(string[] args)
    {
      // How to change the page footer to the custom footer
      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 inputFile = @"..\..\example.rtf";
        string originalPdf = @"..\..\Original.pdf";
        string customPdf = @"..\..\CustomFooter.pdf";

        // Let's convert RTF which has an own page footer to PDF
        if (p.RtfToPdfConvertFile(inputFile, originalPdf)==0)
        {
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(originalPdf) { UseShellExecute = true });
        }

        // Let's change the footer to custom
        string footerInHtml = "<table width=\"100%\" border=\"1\"><tr><td width=\"50%\" align=\"center\"></td><td>This is new custom footer!</td></tr></table>";
        p.PageSettings.Footer.FromString(footerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);

        // Let's convert RTF to PDF and change the footer to the custom
        if (p.RtfToPdfConvertFile(inputFile, customPdf) == 0)
        {
          System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(customPdf) { UseShellExecute = true });
        }
      }
    }
  }
}
Module sample
  Sub Main()
    'How to change the page footer to the custom footer
    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 inputFile As String = "..\..\example.rtf"
      Dim originalPdf As String = "..\..\Original.pdf"
      Dim customPdf As String = "..\..\CustomFooter.pdf"

      'Let's convert RTF which has a page footer to PDF
      If p.RtfToPdfConvertFile(inputFile, originalPdf) = 0 Then
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(originalPdf) With {.UseShellExecute = True})
      End If

      'Let's change footer to the custom
      Dim footerInHtml As String = "<table width=""100%"" border=""1""><tr><td width=""50%"" align=""center""<</td><td>This is new custom footer!</td></tr></table>"
      p.PageSettings.Footer.FromString(footerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html)

      'Let's convert RTF which has a page footer to PDF
      If p.RtfToPdfConvertFile(inputFile, customPdf) = 0 Then
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(customPdf) With {.UseShellExecute = True})
      End If
    End If
  End Sub
End Module

Как интегрировать все шрифты в PDF

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

      // Let's make that the all text in PDF became in 'Courier New' font
      p.TextSettings.FontFace.Custom("Courier New");

      // Set also a single font size 10
      p.TextSettings.FontSize = 10;

      // Set also single text color
      p.TextSettings.FontColor = System.Drawing.Color.FromArgb(33, 150, 150);

      // Embed all fonts inside PDF.
      p.PdfSettings.EmbedAllFonts = true;

      if (p != null)
      {
        string rtfPath = @"..\..\example.rtf";
        string pdfPath = @"..\..\example.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 });
        }
      }
    }
  }
}
Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      ' How to set a single font for the whole PDF document.
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component
      'p.Serial = "XXXXXXXXXXX"

      ' Let's make that the all text in PDF became in 'Courier New' font
      p.TextSettings.FontFace.Custom("Courier New")

      ' Set also a single font size 10
      p.TextSettings.FontSize = 10

      ' Set also single text color
      p.TextSettings.FontColor = System.Drawing.Color.FromArgb(33, 150, 150)

      ' Embed all fonts inside PDF.
      p.PdfSettings.EmbedAllFonts = True

      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = "..\..\test.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

Как задать номера страниц в PDF

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

      //Page 1 of N, position: 30 mm from the left of the page
      p.PageSettings.Numbering.Text = "Page {page} of {numpages}";
      p.PageSettings.Numbering.PosX.Mm = 30;
      p.PageSettings.Numbering.PosY.Mm = 10;
      p.PageSettings.Numbering.FontFace = "Courier";
      p.PageSettings.Numbering.FontSize = 22;

      if (p != null)
      {
        string rtfPath = @"..\..\example.rtf";
        string pdfPath = @"..\..\example.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 });
        }
      }
    }
  }
}
Module sample
  Sub Main()
    ' This sample shows how to specify page numbers
    Dim p As New SautinSoft.PdfMetamorphosis()
    ' After purchasing the license, please insert your serial number here to activate the component
    'p.Serial = "XXXXXXXXXXX"

    'Page 1 of N, position: 30 mm from the left of the page
    p.PageSettings.Numbering.Text = "Page {page} of {numpages}"
    p.PageSettings.Numbering.PosX.Mm = 30
    p.PageSettings.Numbering.PosY.Mm = 10
    p.PageSettings.Numbering.FontFace = "Courier"
    p.PageSettings.Numbering.FontSize = 22

    ' This is page number N
    'p.PageSettings.Numbering.Text = "This is page number {page}"
    If p IsNot Nothing Then
      Dim rtfPath As String = "..\..\example.rtf"
      Dim pdfPath As String = "..\..\test.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 Module

Как настроить поля и размер страницы в PDF

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

      //Let's set: A3, Landscape orientation, left and right margins: 1.5 Inch, top and bottom: 1 Inch
      p.PageSettings.Size.A3();
      p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;
      p.PageSettings.MarginLeft.Inch(1.5f);
      p.PageSettings.MarginRight.Inch(1.5f);
      p.PageSettings.MarginTop.Inch(1.0f);
      p.PageSettings.MarginBottom.Inch(1.0f);

      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 });
        }
      }
    }
  }
}
Module sample
  Sub Main()
    'How to set page size, orientation and margins
    Dim p As New SautinSoft.PdfMetamorphosis()
    ' After purchasing the license, please insert your serial number here to activate the component
    'p.Serial = "XXXXXXXXXXX"

    'Let's set: A3, Landscape orientation, left and right margins: 1.5 Inch, top and bottom: 1 Inch
    p.PageSettings.Size.A3()
    p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape
    p.PageSettings.MarginLeft.Inch(1.5F)
    p.PageSettings.MarginRight.Inch(1.5F)
    p.PageSettings.MarginTop.Inch(1.0F)
    p.PageSettings.MarginBottom.Inch(1.0F)

    If p IsNot Nothing Then
      Dim rtfPath As String = "..\..\example.rtf"
      Dim pdfPath As String = "..\..\test.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 Module

Как установить один шрифт во всём PDF-документе

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

      // Let's make that the all text in PDF became in 'Comic Sans MS' font
      p.TextSettings.FontFace.Custom("Comic Sans MS");

      // Set also a single font size 10
      p.TextSettings.FontSize = 10;

      // Set also single text color
      p.TextSettings.FontColor = System.Drawing.Color.FromArgb(33, 150, 33);

      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 });
        }
      }
    }
  }
}
Namespace Sample
  Friend Class Test
    Shared Sub Main(ByVal args() As String)
      ' How to set a single font for the whole PDF document.
      Dim p As New SautinSoft.PdfMetamorphosis()
      ' After purchasing the license, please insert your serial number here to activate the component
      'p.Serial = "XXXXXXXXXXX"

      ' Let's make that the all text in PDF became in 'Comic Sans MS' font
      p.TextSettings.FontFace.Custom("Comic Sans MS")

      ' Set also a single font size 10
      p.TextSettings.FontSize = 10

      ' Set also single text color
      p.TextSettings.FontColor = System.Drawing.Color.FromArgb(33, 150, 33)

      If p IsNot Nothing Then
        Dim rtfPath As String = "..\..\example.rtf"
        Dim pdfPath As String = "..\..\test.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

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

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