|
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. |
||||||||||||||||
|
|
|||||||||||||||
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#:
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 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
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 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 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 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
Example: p.TextStyle.FontFace.Auto();
FontSize - default font size Example: p.TextStyle.FontSize
= 0; Example: p.TextStyle.FontSize = 12;
TextAlignment - default page alignment Example: p.TextStyle.TextAligment.Left(); FontColor - keep font color as in HTML Example: p.TextStyle.FontColor.Auto(); Example: p.TextStyle.FontColor.SetRGB(0,0,0); PageSize - select page size PageOrientation - select page orientation: Portrait or Landscape pageMarginLeft,
pageMarginRight, pageMarginTop, pageMarginBottom -
set page margins Example: PageNumFormat - page number format Example: Header - put text in PDF page header (unlimited symbols max) p.HtmlOptions.Header = "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. 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 p.HtmlOptions.Header = h.ConvertString("<table width=\"100%\" border=\"0\">"+ Footer - put text in PDF page footer (unlimited symbols max) BaseUrl - specify folder where HTML document refers (only for methods HtmlToPdfComvertString
and HtmlToPdfConvertStringToFile)
Please specify the absolute path in 'p.BaseUrl', it has to start with drive like a "D:\...", or "C:\" 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. Example: |
||||||||||||||||
| Copyright © 2002-2010, SautinSoft™. All rights reserved. | ||||||||||||||||