Class HtmlToPdfResult
Represents the result of html to PDF conversion.
Inheritance
Implements
Namespace: Syncfusion.Pdf.HtmlToPdf
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class HtmlToPdfResult : Object, IDisposable
Remarks
This API is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Constructors
HtmlToPdfResult()
Declaration
public HtmlToPdfResult()
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
HtmlToPdfResult(Image[], ArrayList, ArrayList, ArrayList)
Initializes a new instance of the HtmlToPdfResult class.
Declaration
public HtmlToPdfResult(Image[] image, ArrayList pageBreaks, ArrayList anchors, ArrayList documentLinks)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Image[] | image | The image. |
System.Collections.ArrayList | pageBreaks | The page breaks. |
System.Collections.ArrayList | anchors | The anchors. |
System.Collections.ArrayList | documentLinks | The document links. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
HtmlToPdfResult(Image[], ArrayList, ArrayList, ArrayList, ArrayList, ArrayList, ArrayList)
Initializes a new instance of the HtmlToPdfResult class.
Declaration
public HtmlToPdfResult(Image[] image, ArrayList pageBreaks, ArrayList anchors, ArrayList documentLinks, ArrayList inputElements, ArrayList selectElements, ArrayList buttonElements)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Image[] | image | The image. |
System.Collections.ArrayList | pageBreaks | The page breaks. |
System.Collections.ArrayList | anchors | The anchors. |
System.Collections.ArrayList | documentLinks | The document links. |
System.Collections.ArrayList | inputElements | The input elements. |
System.Collections.ArrayList | selectElements | The select elements. |
System.Collections.ArrayList | buttonElements | The button elements. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
HtmlToPdfResult(Stream)
Declaration
public HtmlToPdfResult(Stream docStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | docStream |
Remarks
This API is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Properties
Images
Returns the image array after the conversion.
Declaration
public Image[] Images { get; }
Property Value
Type | Description |
---|---|
System.Drawing.Image[] | The images. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.Images[0] as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.Images[0].Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.Images(0), Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.Images(0).Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Location
Gets or set the location.
Declaration
public PointF Location { get; set; }
Property Value
Type |
---|
System.Drawing.PointF |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Set the location.
result.Location = new PointF(100, 100);
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Set the location.
result.Location = New PointF(100, 100);
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
MetafileTransparency
Gets or set the metafile transparency.
Declaration
public float MetafileTransparency { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Set transparency.
result.MetafileTransparency = 0.5f;
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Set transparency.
result.MetafileTransparency = 0.5F
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Quality
Handles the quality of Bitmap images in HTML.
Declaration
public long Quality { set; }
Property Value
Type |
---|
System.Int64 |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Set image quality.
result.Quality = 50;
//Render the PdfMetafile in the PDF document
result.Render(page, new PdfLayoutFormat());
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Set image quality.
result.Quality = 50
'Render the PdfMetafile in the PDF document
result.Render(page, New PdfLayoutFormat())
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
RenderedImage
Gets the rendered image.
Declaration
public Image RenderedImage { get; }
Property Value
Type | Description |
---|---|
System.Drawing.Image | The rendered image. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Methods
Render(PdfDocument)
Draw the rendered HTML image to the PDF document
Declaration
public void Render(PdfDocument document)
Parameters
Type | Name | Description |
---|---|---|
PdfDocument | document | The PDF document where the output should be drawn. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Render the PdfMetafile in the PDF document
result.Render(doc);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Render the PdfMetafile in the PDF document
result.Render(doc)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Render(PdfPageBase, PdfLayoutFormat)
Draw the rendered HTML image to the PDF document
Declaration
public void Render(PdfPageBase page, PdfLayoutFormat format)
Parameters
Type | Name | Description |
---|---|---|
PdfPageBase | page | The page where the output will draw. |
PdfLayoutFormat | format | The Metafile layout format. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Render the PdfMetafile in the PDF document
result.Render(page, format);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Render the PdfMetafile in the PDF document
result.Render(page, format)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)
Render(PdfPageBase, PdfLayoutFormat, out PdfLayoutResult)
Draw the rendered HTML image to the PDF document
Declaration
public void Render(PdfPageBase page, PdfLayoutFormat format, out PdfLayoutResult result)
Parameters
Type | Name | Description |
---|---|---|
PdfPageBase | page | The page where the output will draw. |
PdfLayoutFormat | format | The Metafile layout format. |
PdfLayoutResult | result | The Metafile layout result |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
//Create new PDF document
PdfDocument doc = new PdfDocument();
//Add a new page
page = doc.Pages.Add();
//Set the dimension of the PDF page
float width = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
float height = -1f;
//Initialize HTML to PDF converter
using (Syncfusion.HtmlConverter.HtmlConverter html = new Syncfusion.HtmlConverter.HtmlConverter())
{
//Convert the URL
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);
if (result != null)
{
//Get the HTML as PdfMetafile
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Formatting options
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
//Create new PDF layout result.
PdfLayoutResult layoutResult;
//Render the PdfMetafile in the PDF document
result.Render(page, format, out layoutResult);
}
}
//Save the PDF
doc.Save(@"Output.pdf");
//Close the PDF
doc.Close(true);
'Create new PDF document
Dim doc As New PdfDocument()
'Add a new page
page = doc.Pages.Add()
'Set the dimension of the PDF page
Dim width As Single = New PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)
Dim height As Single = -1F
'Initialize HTML to PDF converter
Using html As New Syncfusion.HtmlConverter.HtmlConverter()
'Convert the URL
Dim result As HtmlToPdfResult = html.Convert("http://www.syncfusion.com", ImageType.Metafile, CInt(width), CInt(height), AspectRatio.KeepWidth)
If result IsNot Nothing Then
'Get the HTML as PdfMetafile
Dim mf As New PdfMetafile(TryCast(result.RenderedImage, Metafile))
'Formatting options
Dim format As New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = False
format.SplitImages = False
'Create new PDF layout result.
Dim layoutResult As PdfLayoutResult
'Render the PdfMetafile in the PDF document
result.Render(page, format, layoutResult)
End If
End Using
'Save the PDF
doc.Save("Output.pdf")
'Close the PDF
doc.Close(True)