PDF Metamorphosis .Net - Powerful .Net component
to convert RTF to PDF, HTML to PDF, Text to PDF, split and merge PDF documents.
version 3.0.5.320 (January 21th, 2010)
Contents | About PDF Metamorphosis .Net | Methods and Properties | Samples | License | Pricing | Support and Contacts
PDF Metamorphosis .Net - methods and properties description
The component can convert XHTML, HTML, RTF files (strings) into PDF files (strings) with images, tables, CSS etc.
This scheme shows all methods and properties of the DLL component. All properties are already set by default to make conversion more accurately.

Methods for converting HTML, XHTML, RTF to PDF:

 RtfToPdfConvertByte()
 RtfToPdfConvertFile()
 RtfToPdfConvertFileToByte()
 RtfToPdfConvertStringToFile()

 HtmlToPdfConvertFile()
 HtmlToPdfConvertFileToByte()
 HtmlToPdfConvertStringToByte()
 HtmlToPdfConvertStringToFile()

Methods to Split and Merger PDF files:

 SplitPDF()
 MergePDF()

Properties and methods for adjusting an output PDF:

PageStyle parameters:
 PageStyle.PageSize
 PageStyle.PageOrientation
 PageStyle.PageMarginLeft
 PageStyle.PageMarginRight
 PageStyle.PageMarginTop
 PageStyle.PageMarginBottom
 PageStyle.PageNumFormat

License parameters:

 Serial
 SetSerial()


Error parameters:

 ErrorTrace

 

TextStyle parameters:

 TextStyle.FontFace
 TextStyle.FontSize
 TextStyle.FontColor
 TextStyle.TextAlignment
 TextStyle.Header
 TextStyle.Footer
 TextStyle.InputFormat


Html to PDF parameters:

 HtmlOptions.Header
 HtmlOptions.Footer
 HtmlOptions.BaseUrl


byte[] RtfToPdfConvertByte(string rtfString) - this method takes RTF string and returns PDF as bytes array.

byte[] RtfToPdfConvertByte(byte[] rtfBytes) - this method takes RTF bytes array and returns PDF as bytes array.

Method returns 'null' in case of converting failed.

Example C#:

            string rtfString = @"{\rtf1{\fonttbl{\f0 Courier;}}\f0\fs24 Hello word\par}";
            
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            if (p!=null)
            {
                //set converter options (not required)
                p.TextStyle.FontSize = 14;
                p.PageStyle.PageSize.Letter();

                //converting
                byte[] pdfBytes = p.RtfToPdfConvertByte(rtfString);

                //save PDF bytes to file
                FileStream fs = new FileStream(@"d:\sautinsoft.pdf", FileMode.Create, FileAccess.Write);
                fs.Write(pdfBytes, 0, pdfBytes.Length);
                fs.Close();
            }

Example VB:

            Dim rtfString As String = "{\rtf1{\fonttbl{\f0 Courier;}}\f0\fs24 Hello word\par}"

            Dim p As New SautinSoft.PdfMetamorphosis()
            If p IsNot Nothing Then
                'set converter options (not required)
                p.TextStyle.FontSize = 14
                p.PageStyle.PageSize.Letter()

                'converting
                Dim pdfBytes() As Byte = p.RtfToPdfConvertByte(rtfString)

                'save PDF bytes to file
                Dim fs As New FileStream("d:\sautinsoft.pdf", FileMode.Create, FileAccess.Write)
                fs.Write(pdfBytes, 0, pdfBytes.Length)
                fs.Close()
            End If


int RtfToPdfConvertFile(string inputFileRtf, string outputFilePdf) - converts RTF file into PDF file, takes path to RTF file and path to PDF file. Creates new PDF file, if PDF is already exist it will be overwritten.

Returns result of converting as integer value:

0 - converting OK

1 - can't open RTF file, please check an input path

2 - can't create PDF file, please check an output path

3 - converting error, to solves this issue we advice you to email us: pdfmetamorphosis@sautinsoft.com

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            if (p!=null)
            {
                int result = p.RtfToPdfConvertFile(@"d:\test.rtf", @"d:\test.pdf");

                if (result == 0)
                    System.Diagnostics.Process.Start(@"d:\test.pdf");
                else
                    System.Console.WriteLine("Converting error");
            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()
            If p IsNot Nothing Then
                Dim result As Integer = p.RtfToPdfConvertFile("d:\test.rtf", "d:\test.pdf")

                If result = 0 Then
                    System.Diagnostics.Process.Start("d:\test.pdf")
                Else
                    System.Console.WriteLine("Converting error")
                End If

            End If

byte[] RtfToPdfConvertFileToByte(string rtfFile) - this method takes path to RTF file and returns PDF as bytes array.

Returns PDF document as byte array. Returns null if converting failed.

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            if (p!=null)
            {
                //converting
                byte[] pdfBytes = p.RtfToPdfConvertFileToByte(@"d:\test.rtf");

                if (pdfBytes != null)
                {
                    //save PDF bytes to file
                    FileStream fs = new FileStream(@"d:\sautinsoft.pdf", FileMode.Create, FileAccess.Write);
                    fs.Write(pdfBytes, 0, pdfBytes.Length);
                    fs.Close();
                }

            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()
            If p IsNot Nothing Then
                'converting
                Dim pdfBytes() As Byte = p.RtfToPdfConvertFileToByte("d:\test.rtf")

                If pdfBytes IsNot Nothing Then
                    'save PDF bytes to file
                    Dim fs As New FileStream("d:\sautinsoft.pdf", FileMode.Create, FileAccess.Write)
                    fs.Write(pdfBytes, 0, pdfBytes.Length)
                    fs.Close()
                End If
            End If

int RtfToPdfConvertStringToFile(string rtfString, string pdfFile) - this method takes RTF string and path to output PDF file.

Creates a new PDF file, if PDF is already exist it will be overwritten.

Returns result of converting as integer value:

0 - converting OK

1 - can't open RTF file, please check an input path

2 - can't create PDF file, please check an output path

3 - converting error, to solves this issue we advice you to email us: pdfmetamorphosis@sautinsoft.com

Example C#:

            string rtfString = @"{\rtf1{\fonttbl{\f0 Courier;}}\f0\fs24 Hello word\par}";
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            if (p != null)
            {
                int result = p.RtfToPdfConvertStringToFile(rtfString, @"d:\test.pdf");
                if (result == 0)
                    System.Diagnostics.Process.Start(@"d:\test.pdf");
                else
                    System.Console.WriteLine("Converting error");              
            }

Example VB:

            string rtfString = @"{\rtf1{\fonttbl{\f0 Courier;}}\f0\fs24 Hello word\par}";
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            if (p != null)
            {
                int result = p.RtfToPdfConvertStringToFile(rtfString, @"d:\test.pdf");
                if (result == 0)
                    System.Diagnostics.Process.Start(@"d:\test.pdf");
                else
                    System.Console.WriteLine("Converting error");              
            }

int HtmlToPdfConvertFile(string inputFileName, string outputFileName) - converts HTML file or URL into PDF file, takes path to HTML file or URL and path to PDF file. Creates a new PDF file, if PDF is already exist it will be overwritten.

Returns result of converting as integer value:

0 - converting OK

1 - can't open HTML file, please check an input path

2 - can't create PDF file, please check an output path

3 - converting error, to solves this issue we advice you to email us: pdfmetamorphosis@sautinsoft.com

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            if (p != null)
            {
                int result = p.HtmlToPdfConvertFile(@"http://www.sautinsoft.com/help/html-to-rtf/net/help/htmlsamples/sample1.htm", @"d:\test.pdf");
                if (result == 0)
                    System.Diagnostics.Process.Start(@"d:\test.pdf");
                else
                    System.Console.WriteLine("Converting error");              
            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()

            If p IsNot Nothing Then
                Dim result As Integer = p.HtmlToPdfConvertFile("http://www.sautinsoft.com/help/html-to-rtf/net/help/htmlsamples/sample1.htm", "d:\test.pdf")
                If result = 0 Then
                    System.Diagnostics.Process.Start("d:\test.pdf")
                Else
                    System.Console.WriteLine("Converting error")
                End If
            End If

byte[] HtmlToPdfConvertFileToByte(string rtfFile) - this method takes path or ULR to HTML file and returns a PDF document as bytes array.

Returns PDF document as byte array. Returns null if converting failed.

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            if (p != null)
            {
                p.PageStyle.PageNumFormat = "Page {page} of {numpages}";
                byte[] pdf = p.HtmlToPdfConvertFileToByte(@"http://www.sautinsoft.com/help/html-to-rtf/net/help/htmlsamples/pic.htm");

                if (pdf != null)
                {
                    //save to PDF file
                    FileStream fs = new FileStream(@"d:\test.pdf", FileMode.Create, FileAccess.Write);
                    fs.Write(pdf, 0, pdf.Length);
                    fs.Close();
                }               

            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()

            If p IsNot Nothing Then
                p.PageStyle.PageNumFormat = "Page {page} of {numpages}"
                Dim pdf() As Byte = p.HtmlToPdfConvertFileToByte("http://www.sautinsoft.com/help/html-to-rtf/net/help/htmlsamples/pic.htm")

                If pdf IsNot Nothing Then
                    'save to PDF file
                    Dim fs As New FileStream("d:\test.pdf", FileMode.Create, FileAccess.Write)
                    fs.Write(pdf, 0, pdf.Length)
                    fs.Close()
                End If
            End If

byte[] HtmlToPdfConvertStringToByte(byte[] rtfBytes) - this method takes a HTML string and returns a PDF document as bytes array.

Method returns 'null' in case of converting failed.

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            string htmlPath = @"d:\pic.htm";
            string pdfPath = @"d:\pic.pdf";           
            string htmlString = "";

            if (p != null)
            {

                //1. Get HTML content from file
                FileStream fo = new FileStream(htmlPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                byte[] arb = new byte[(int)fo.Length];
                try
                {
                    fo.Read(arb, 0, (int)fo.Length);
                    fo.Close();
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    htmlString =  encoding.GetString(arb);
                }
                catch
                {
                    System.Console.WriteLine("An error occured during reading HTML file!");
                }
                //2. Converting HTML to PDF
                //specify BaseUrl to help converter find a full path for relative images, CSS

                p.HtmlOptions.BaseUrl = Path.GetDirectoryName(htmlPath);
                byte[] pdf = p.HtmlToPdfConvertStringToByte(htmlString);

                if (pdf != null)
                {
                    //3. Save to PDF file
                    FileStream fs = new FileStream(pdfPath, FileMode.Create, FileAccess.Write);
                    fs.Write(pdf, 0, pdf.Length);
                    fs.Close();
                }
                else
                {
                    System.Console.WriteLine("An error occured during converting HTML to PDF!");
                }               
            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()
            Dim htmlPath As String = "d:\pic.htm"
            Dim pdfPath As String = "d:\pic.pdf"
            Dim htmlString As String = ""

            If p IsNot Nothing Then

                '1. Get HTML content from file
                Dim fo As New FileStream(htmlPath, FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim arb(CInt(Fix(fo.Length)) - 1) As Byte
                Try
                    fo.Read(arb, 0, CInt(Fix(fo.Length)))
                    fo.Close()
                    Dim encoding As New System.Text.ASCIIEncoding()
                    htmlString = encoding.GetString(arb)
                Catch
                    System.Console.WriteLine("An error occured during reading HTML file!")
                End Try
                '2. Converting HTML to PDF
                'specify BaseUrl to help converter find a full path for relative images, CSS

                p.HtmlOptions.BaseUrl = Path.GetDirectoryName(htmlPath)
                Dim pdf() As Byte = p.HtmlToPdfConvertStringToByte(htmlString)

                If pdf IsNot Nothing Then
                    '3. Save to PDF file
                    Dim fs As New FileStream(pdfPath, FileMode.Create, FileAccess.Write)
                    fs.Write(pdf, 0, pdf.Length)
                    fs.Close()
                Else
                    System.Console.WriteLine("An error occured during converting HTML to PDF!")
                End If
            End If

int HtmlToPdfConvertStringToFile(string htmlString, string pdfFile) - this method takes HTML string and path to output PDF file.

Creates a new PDF file, if PDF is already exist it will be overwritten.

Returns result of converting as integer value:

0 - converting OK

1 - can't open RTF file, please check an input path

2 - can't create PDF file, please check an output path

3 - converting error, to solves this issue we advice you to email us: pdfmetamorphosis@sautinsoft.com

Example C#:

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            string htmlPath = @"d:\pic.htm";
            string pdfPath = @"d:\pic.pdf";           
            string htmlString = "";

            if (p != null)
            {

                //1. Get HTML content from file
                FileStream fo = new FileStream(htmlPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                byte[] arb = new byte[(int)fo.Length];
                try
                {
                    fo.Read(arb, 0, (int)fo.Length);
                    fo.Close();
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    htmlString =  encoding.GetString(arb);
                }
                catch
                {
                    System.Console.WriteLine("An error occured during reading HTML file!");
                }
                //2. Converting HTML to PDF file
                //specify BaseUrl to help converter find a full path for relative images, CSS

                p.HtmlOptions.BaseUrl = Path.GetDirectoryName(htmlPath);
                int result = p.HtmlToPdfConvertStringToFile(htmlString,pdfPath);

                if (result==0)
                {
                    System.Diagnostics.Process.Start(pdfPath);
                }
                else
                {
                    System.Console.WriteLine("An error occured during converting HTML to PDF!");
                }               
            }

Example VB:

            Dim p As New SautinSoft.PdfMetamorphosis()
            Dim htmlPath As String = "d:\pic.htm"
            Dim pdfPath As String = "d:\pic.pdf"
            Dim htmlString As String = ""

            If p IsNot Nothing Then

                '1. Get HTML content from file
                Dim fo As New FileStream(htmlPath, FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim arb(CInt(Fix(fo.Length)) - 1) As Byte
                Try
                    fo.Read(arb, 0, CInt(Fix(fo.Length)))
                    fo.Close()
                    Dim encoding As New System.Text.ASCIIEncoding()
                    htmlString = encoding.GetString(arb)
                Catch
                    System.Console.WriteLine("An error occured during reading HTML file!")
                End Try
                '2. Converting HTML to PDF file
                'specify BaseUrl to help converter find a full path for relative images, CSS

                p.HtmlOptions.BaseUrl = Path.GetDirectoryName(htmlPath)
                Dim result As Integer = p.HtmlToPdfConvertStringToFile(htmlString,pdfPath)

                If result=0 Then
                    System.Diagnostics.Process.Start(pdfPath)
                Else
                    System.Console.WriteLine("An error occured during converting HTML to PDF!")
                End If
            End If


int SplitPDF(string SourceFile, string OutputPath) - this method splits file SourceFile to some PDF files into directory OutputPath. The files each have contains one page of Source File. The OutputPath will contain files with number equal to count of pages in the SourceFile.

int MergePDF(string[] Files, string DestFile)- this method merges all PDF files from Files array to new file DestFile.


FontFace - default font face
Possible values: TimesNewRoman, Helvetica, Courier, Auto.
Default value: Auto

Example: p.TextStyle.FontFace.Auto();


Example:
p.TextStyle.FontFace.Helvetica();

FontSize - default font size
Possible values: Any size, 0 - Auto
Default value: 0 or Auto

Example: p.TextStyle.FontSize = 0;

Example: p.TextStyle.FontSize = 12;

 

TextAlignment - default page alignment
Possible values:
Left, Center, Right, Justify, Auto.
Default value: Auto
Example:
p.TextStyle.TextAligment.Auto();

Example: p.TextStyle.TextAligment.Left();

FontColor - keep font color as in HTML

Possible values: Any size, 0 - Auto
Default value: 0 or Auto

Example: p.TextStyle.FontColor.Auto();

Example: p.TextStyle.FontColor.SetRGB(0,0,0);

PageSize - select page size

Possible values: A3, A4, A5, A6, B5, B5Jis, B5Iso, Folio, Statement, Letter, Legal, Executive, Oficio2, Auto
Default value: Auto
Example: p.PageStyle.PageSize.Legal();
or
p.PageStyle.PageSize.Widthmm(240.5);
p.PageStyle.PageSize.HeightInch(14.0);

PageOrientation - select page orientation: Portrait or Landscape

Possible values: Portrait, Landscape, Auto
Default value: Auto
Example: p.PageStyle.PageOrientation.Landscape();

pageMarginLeft, pageMarginRight, pageMarginTop, pageMarginBottom - set page margins

Possible values: any value in inches or mm
Default values: Auto;

Example:
p.PageStyle.PageMarginLeft.Inch(1.5);
p.PageStyle.PageMarginRight.mm(20);

PageNumFormat - page number format

Possible values: any string value with keywords
Default values: empty string;

Example:
p.PageStyle.PageNumFormat = "";
p.PageStyle.PageNumFormat = "{none}";

p.PageStyle.PageNumFormat = "{page} - {numpages}";
p.PageStyle.PageNumFormat = "Page {page} of {numpages}";

Notes:
The string PageStyle.PageNumFormat may consists of any symbols and keywords:
   {none} - page number doesn't visible;
   {page} - page number;
   {numpages} - total pages.
If value is empty then same as in Rtf file.

Header - put text in PDF page header (unlimited symbols max)

Possible values: any string in RTF or Text format
Default value: ""
Example:
p.HtmlOptions.Header = "Page Header Example ";

p.HtmlOptions.Header = "page Header Example";
p.HtmlOptions.Header
= "{\b Bold page Header Example}";
p.HtmlOptions.Header
= "{\b\i Bold Italic page Header Example}";
p.HtmlOptions.Header
= "{\qc Centered page Header Example}";

How to insert HTML file with images in header or footer?

You can insert even complete HTML file with images and tables inside header and footer. But at first you have to convert it to RTF.
This a C# sample:

To convert HTML to RTF use another our component the HTML-to-RTF Pro .Net DLL: http://www.sautinsoft.com/components/htmltortf_pro_net.zip

// create an object of SautinSoft.HtmlToRtf
SautinSoft.HtmlToRtf.Converter h = new SautinSoft.HtmlToRtf.Converter();

//prepare header and footer with company logo
h.RtfParts = SautinSoft.HtmlToRtf.eRtfParts.RtfBody;

p.HtmlOptions.Header = h.ConvertString("<table width=\"100%\" border=\"0\">"+
"<tr>" +
"<td width=\"200\"><img src=\"d:\\logo.gif\" width=\"200\" height=\"100\"></td>"+
"<td><div align=\"center\"><font color=\"#0099FF\" size=\"4\">Some</font><em> text</em> in <strong>header</strong></div></td>"+
"</tr>"+
"</table>");
p.HtmlOptions.Footer = h.ConvertString("<table width=\"100%\" border=\"0\">"+
"<tr>" +
"<td width=\"200\"><img src=\"d:\\logo.gif\" width=\"100\" height=\"50\"></td>"+
"<td><div align=\"center\"><font color=\"#0099FF\" size=\"4\">Some</font><em> text</em> in <strong>footer</strong></div></td>"+
"</tr>"+
"</table>");


Footer - put text in PDF page footer (unlimited symbols max)

Possible values: any string in RTF or Text format
Default value: ""
Example:
p.HtmlOptions.Header = "Page Footer Example ";

BaseUrl - specify folder where HTML document refers (only for methods HtmlToPdfComvertString and HtmlToPdfConvertStringToFile)

Possible values: directory
Default value: ""
Example:
p.HtmlOptions.BaseUrl = "d:\HTML\Images\";


The 'BaseUrl' path is directory where the original Html document was stored, to convert all relative paths to .css and images into
full paths.

Please specify the absolute path in 'p.BaseUrl', it has to start with drive like a "D:\...", or "C:\"
for example:

p.BaseUrl = @"d:\my webs\";

So if converter will meet "<img src='/nReports/Uploads/Images/School.jpg'/>" it will try find the image 'School.jpg' at:

d:\my webs\nReports\Uploads\Images\School.jpg

Or another example:

p.BaseUrl = @"d:\my webs\";

if converter will meet "<img src='../Uploads/Images/School.jpg'/>" it will try to find the image 'School.jpg' at:

d:\Uploads\Images\School.jpg

Serial - This property is required for activation full version. After purchasing you will get the full version and license key. Use it for activation. The trial version doesn't support this property.

Possible values: any value in key
Default values: "";

Example:
p.Serial = "0000000000";

ErrorTrace - this parameter helps to find detailed information about appeared error. This is standard object of System.Exception class.

Example:
string issue = p.ErrorTrace.Message;

Copyright © 2002-2010, SautinSoft™. All rights reserved.