Class HtmlToPdf
IronPdf.HtmlToPdf allows any web page or Html 'snippet' to be turned into a PDF document.
Inheritance
Implements
Inherited Members
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public class HtmlToPdf : IDisposable
Constructors
HtmlToPdf()
The IronPdf.HtmlToPdf allows developers to create PDF files from any web page or Html Snippet
Declaration
public HtmlToPdf()
HtmlToPdf(PdfPrintOptions)
Declaration
public HtmlToPdf(PdfPrintOptions PrintOptions)
Parameters
Type | Name | Description |
---|---|---|
PdfPrintOptions | PrintOptions | Sets PDF output options such as paper-size, DPI, headers and footers using an instance of the IronPdf.PdfPrintOptions Class. |
Fields
LoginCredentials
An instance of the HttpLoginCredentials class. Allows developers to specify login credentials using Windows, Linux or Html Forms based authentication. This allows PDFs to be printed, even if they reside on private Intranets, Extranets or within 'login' areas of websites.
Declaration
public HttpLoginCredentials LoginCredentials
Field Value
Type | Description |
---|---|
HttpLoginCredentials |
PrintOptions
An instance of the PdfPrintOptions class. Sets PDF output options such as Paper-Size, DPI, Headers and Footers.
Declaration
public PdfPrintOptions PrintOptions
Field Value
Type | Description |
---|---|
PdfPrintOptions |
Methods
Dispose()
Releases resources
Declaration
public void Dispose()
Finalize()
Finalizer
Declaration
protected void Finalize()
RenderHtmlAsPdf(String, String, String)
Creates a PDF file from an Html string, and returns it as an IronPdf.PdfDocument
Declaration
public PdfDocument RenderHtmlAsPdf(string Html, string BaseUrlOrPath, string Proxy = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | The Html to be rendered as a PDF. |
System.String | BaseUrlOrPath | Setting the BaseUrlOrPath property gives the relative context for hyper-links, images, CSS and JavaScript files. |
System.String | Proxy | Specifies an Http proxy server. Use the pattern: http(s)://user-name:password@host:port |
Returns
Type | Description |
---|---|
PdfDocument |
Examples
HtmlToPdf myHtmlToPdf = new IronPdf.HtmlToPdf();
myHtmlToPdf.RenderHtmlAsPdf("<p>html</p>").SaveAs(@"Path\File.Pdf");
RenderHtmlAsPdf(String, Uri, String)
Creates a PDF file from an Html string, and returns it as an IronPdf.PdfDocument
Declaration
public PdfDocument RenderHtmlAsPdf(string Html, Uri BaseUrl = null, string Proxy = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | The Html to be rendered as a PDF. |
System.Uri | BaseUrl | Setting the BaseURL property gives the relative context for hyper-links, images, CSS and JavaScript files. |
System.String | Proxy | Specifies an Http proxy server. Use the pattern: http(s)://user-name:password@host:port |
Returns
Type | Description |
---|---|
PdfDocument |
Examples
HtmlToPdf myHtmlToPdf = new IronPdf.HtmlToPdf();
myHtmlToPdf.RenderHtmlAsPdf("<p>html</p>").SaveAs(@"Path\File.Pdf");
RenderHtmlAsPdfAsync(String, Uri)
Renders any Html string as PDF asynchronously.
Declaration
public Task<PdfDocument> RenderHtmlAsPdfAsync(string Html, Uri BaseUrl = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | Html to be turned into a PDF. |
System.Uri | BaseUrl | Setting the BaseURL property gives the Html a relative for content links such as hyper-links, images, CSS and JavaScript files. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
RenderHTMLFileAsPdf(String)
Renders an HTML file as PDF binary data.
Declaration
public PdfDocument RenderHTMLFileAsPdf(string FilePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | FilePath | Path to an Html file. |
Returns
Type | Description |
---|---|
PdfDocument |
RenderHTMLFileAsPdfAsync(String)
Renders an HTML file as PDF asynchronously.
Declaration
public Task<PdfDocument> RenderHTMLFileAsPdfAsync(string FilePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | FilePath | File path to the HTML document. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
RenderUrlAsPdf(String)
Renders the URL as PDF binary data.
Declaration
public PdfDocument RenderUrlAsPdf(string UrlOrPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | UrlOrPath | A url or file path. |
Returns
Type | Description |
---|---|
PdfDocument |
RenderUrlAsPdf(Uri)
Renders the URL as PDF binary data.
Declaration
public PdfDocument RenderUrlAsPdf(Uri Url)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | Url | An absolute Uri. Points to the Html document to be rendered as a PDF. |
Returns
Type | Description |
---|---|
PdfDocument |
Examples
HtmlToPdf myHtmlToPdf = new IronPdf.HtmlToPdf(); Uri myUri = new Uri("http://www.example.com");
myHtmlToPdf.RenderUrlAsPdf(myUri).SaveAs(@"Path\File.Pdf");
RenderUrlAsPdfAsync(Uri)
Renders any URL as a PDF asynchronously.
Declaration
public Task<PdfDocument> RenderUrlAsPdfAsync(Uri Url)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | Url | The Absolute Uri of the Html document to be rendered. CSS, JavaScript and Images in that document will also be rendered. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
StaticRenderHtmlAsPdf(String, PdfPrintOptions)
Static version of the RenderHtmlAsPdf(String, String, String) function. Renders any Html strings into a PDF document.
Declaration
public static PdfDocument StaticRenderHtmlAsPdf(string Html, PdfPrintOptions PrintOptions)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | Html to be turned into a PDF. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderHtmlAsPdf(String, String, PdfPrintOptions, String)
Static version of the RenderHtmlAsPdf(String, String, String) function. Renders any Html strings into a PDF document.
Declaration
public static PdfDocument StaticRenderHtmlAsPdf(string Html, string BaseUrlOrPath, PdfPrintOptions PrintOptions = null, string Proxy = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | Html to be turned into a PDF. |
System.String | BaseUrlOrPath | Setting the BaseUrlOrPath property gives the Html a relative for content links such as hyper-links, images, CSS and JavaScript files. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
System.String | Proxy | Specifies an Http proxy server. Use the pattern: http(s)://user-name:password@host:port/ |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderHtmlAsPdf(String, Uri, PdfPrintOptions, String)
Static version of the RenderHtmlAsPdf(String, Uri, String) function. Renders any Html strings into a PDF document.
Declaration
public static PdfDocument StaticRenderHtmlAsPdf(string Html, Uri BaseUrl = null, PdfPrintOptions PrintOptions = null, string Proxy = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | Html to be turned into a PDF. |
System.Uri | BaseUrl | Setting the BaseURL property gives the Html a relative for content links such as hyper-links, images, CSS and JavaScript files. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
System.String | Proxy | Specifies an Http proxy server. Use the pattern: http(s)://user-name:password@host:port/ |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderHtmlAsPdfAsync(String, String, PdfPrintOptions)
Static asynchronous method that renders an HTML file as PDF.
Declaration
public static Task<PdfDocument> StaticRenderHtmlAsPdfAsync(string Html, string BaseUrlOrPath = null, PdfPrintOptions PrintOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Html | The Html to be rendered as a PDF. |
System.String | BaseUrlOrPath | Setting the BaseUrlOrPath property gives the relative context for hyper-links, images, CSS and JavaScript files. |
PdfPrintOptions | PrintOptions | Sets PDF output options such as paper-size, DPI, headers and footers using an instance of the IronPdf.PdfPrintOptions Class. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
StaticRenderHTMLFileAsPdf(String, PdfPrintOptions)
Renders an HTML file as PDF binary data.
Declaration
public static PdfDocument StaticRenderHTMLFileAsPdf(string FilePath, PdfPrintOptions PrintOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | FilePath | Path to an Html file. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderHTMLFileAsPdfAsync(String, PdfPrintOptions)
Static asynchronous method that renders an HTML file as PDF.
Declaration
public static Task<PdfDocument> StaticRenderHTMLFileAsPdfAsync(string FilePath, PdfPrintOptions PrintOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | FilePath | File path to the HTML document. |
PdfPrintOptions | PrintOptions | Sets PDF output options such as paper-size, DPI, headers and footers using an instance of the IronPdf.PdfPrintOptions Class. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
StaticRenderUrlAsPdf(String, PdfPrintOptions, HttpLoginCredentials)
Static version of the RenderUrlAsPdf(String) function. Renders all Html and assets at a given Url into a PDF file.
Declaration
public static PdfDocument StaticRenderUrlAsPdf(string UrlOrPath, PdfPrintOptions PrintOptions = null, HttpLoginCredentials LoginCredentials = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | UrlOrPath | An absolute Url or file path. Points to the Html document to be rendered as a PDF. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
HttpLoginCredentials | LoginCredentials | Instance of HttpLoginCredentials. Optional login credentials for Windows, Linux and Html Form login environments. |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderUrlAsPdf(Uri, PdfPrintOptions, HttpLoginCredentials)
Static version of the RenderUrlAsPdf(Uri) function. Renders all Html and assets at a given Url into a PDF file.
Declaration
public static PdfDocument StaticRenderUrlAsPdf(Uri Url, PdfPrintOptions PrintOptions = null, HttpLoginCredentials LoginCredentials = null)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | Url | An absolute Uri. Points to the Html document to be rendered as a PDF. |
PdfPrintOptions | PrintOptions | Instance of PdfPrintOptions. Optional print options and settings. |
HttpLoginCredentials | LoginCredentials | Instance of HttpLoginCredentials. Optional login credentials for Windows, Linux and Html Form login environments. |
Returns
Type | Description |
---|---|
PdfDocument |
StaticRenderUrlAsPdfAsync(String, PdfPrintOptions)
Static asynchronous method that renders a URL as PDF.
Declaration
public static Task<PdfDocument> StaticRenderUrlAsPdfAsync(string Url, PdfPrintOptions PrintOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | Url | URL to be turned into a PDF. |
PdfPrintOptions | PrintOptions | Sets PDF output options such as paper-size, DPI, headers and footers using an instance of the IronPdf.PdfPrintOptions Class. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |
StaticRenderUrlAsPdfAsync(Uri, PdfPrintOptions)
Static asynchronous method that renders a URL as PDF.
Declaration
public static Task<PdfDocument> StaticRenderUrlAsPdfAsync(Uri Url, PdfPrintOptions PrintOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | Url | URL to be turned into a PDF. |
PdfPrintOptions | PrintOptions | Sets PDF output options such as paper-size, DPI, headers and footers using an instance of the IronPdf.PdfPrintOptions Class. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<PdfDocument> | Task of type PdfDocument |