Convert HTML to PDF in your Xamarin Applications
Winnovative HTML to PDF Client for .NET is a component of the Winnovative Client Library for .NET
which can be easily integrated in any type of Xamarin application for iOS, Android and macOS to convert HTML documents to PDF, raster images or SVG vector images.
The HTML to PDF is a powerful tool helping you to instantly create nicely formatted and easily maintainable PDF documents from HTML pages.
The client library offers in general the same features, quality and API as the regular HTML to PDF Library for .NET.
Before starting to use the client library for .NET in your applications you first have to install the Winnovative Server as described in the sections below.
The converter offers full support for HTML5, CSS3, JavaScript, SVG, Web Fonts,
page breaks control with CSS and from API, automatically repeated HTML table header and footer,
live URLs and internal links, automatically generated hierarchical bookmarks and table of contents,
PDF fillable forms, creation of digitally signed and password protected PDF documents.
Winnovative Client Library for .NET includes also under the same namespace the API for the Word to PDF, Excel to PDF, PDF to Text, PDF to Image, PDF to HTML and PDF Images Extractor
components from Winnovative PDF Toolkit PRO.
Compatibility
Winnovative Client Library for .NET is compatible with any platform which supports .NET Standard 2.0 and above or .NET Framework 4.0 and above, including:
- .NET Core 7, 6, 5, .NET Standard 2.0 (and above)
- .NET Framework 4.8.1, 4.7.2, 4.6.1, 4.0 (and above)
- Windows, Linux, macOS
- Azure, Azure App Service and Azure Functions
- Xamarin for iOS, macOS and Android
- Universal Windows Platform (UWP)
- Web, Console and Desktop applications
Software Download
Winnovative Client Libraries
Winnovative HTML to PDF for Xamarin ZIP package contains the product binaries consisting in Winnovative Client Library for .NET Core assembly,
demo Visual Studio projects with full C# code for Xamarin applications for iOS, Android and macOS, the library documentation in CHM format.
Winnovative Server
Before starting to use the Winnovative HTML to PDF Client for .NET in your applications you first have to install the Winnovative Server.
The server can be installed as Azure Cloud Service Worker Role, Azure Cloud Service Web Role, Azure Service Fabric Application,
IIS ASP.NET Web Application or Windows Service.
Winnovative Server package contains the server files and detailed installation instructions for each platform.
Getting Started
After the Winnovative Server was installed, you are ready to use the Winnovative Client Library for .NET in your applications. You can quickly start with
the demo applications from the Demo folder of this package or you can integrate the library in your own project.
To start with your own project, first add a reference to
Winnovative.Client NuGet package. Alternatively you can reference the WinnovativeClient_NetCore.dll library directly
from the Bin folder of the client library ZIP package.
After the reference to library was added to your project you are now ready to start writing code to convert HTML to PDF in your .NET application
C# Code Samples
Copy the C# code lines from the section below to use the HTML to PDF Converter component to create a PDF document from a web page or from a HTML string and save
the resulted PDF to a memory buffer for further processing, to a PDF file or send it to browser for download in ASP.NET applications.
The server IP address is assigned during server installation and it can be omitted from HtmlToPdfConverter constructor if the server was installed on the localhost IP address 127.0.0.1 .
There are also variants of the constructor accepting an URL instead of IP address if the server was installed as a web service in Azure or in IIS.
At the top of your C# source file add the using WinnovativeClient; statement to make available the Winnovative Client API for your .NET application.
// add this using statement at the top of your C# file
using WinnovativeClient;
To convert in your Xamarin application for iOS a HTML string to a PDF document in a memory buffer, save it to a file and open that file a in PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
using System;
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from Winnovative !", null);
// write the memory buffer to a PDF file
string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string htmlToPdfFile = System.IO.Path.Combine(documentsFolder, "HtmlToMemory.pdf");
System.IO.File.WriteAllBytes(htmlToPdfFile, htmlToPdfBuffer);
// open the PDF document in the default PDF viewer
UIDocumentInteractionController pdfViewer = UIDocumentInteractionController.FromUrl(Foundation.NSUrl.FromFilename(htmlToPdfFile));
pdfViewer.PresentOpenInMenu(this.View.Frame, this.View, true);
To convert in your Xamarin application for iOS an URL to a PDF document in a memory buffer, save it to a file and open that file in a PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
using System;
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert an URL to a memory buffer
string htmlPageURL = "http://www.winnovative-software.com";
byte[] urlToPdfBuffer = converter.ConvertUrl(htmlPageURL);
// write the memory buffer to a PDF file
string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string urlToPdfFile = System.IO.Path.Combine(documentsFolder, "UrlToMemory.pdf");
System.IO.File.WriteAllBytes(urlToPdfFile, urlToPdfBuffer);
// open the PDF document in the default PDF viewer
UIDocumentInteractionController pdfViewer = UIDocumentInteractionController.FromUrl(Foundation.NSUrl.FromFilename(urlToPdfFile));
pdfViewer.PresentOpenInMenu(this.View.Frame, this.View, true);
To convert in your Xamarin application for Android a HTML string to a PDF document in a memory buffer, save it to a file and open that file a in PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from Winnovative !", null);
// write the memory buffer to a PDF file
string documentsFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
string htmlToPdfFile = System.IO.Path.Combine(documentsFolder, "HtmlToMemory.pdf");
System.IO.File.WriteAllBytes(htmlToPdfFile, htmlToPdfBuffer);
// open the PDF document in the default PDF viewer
Android.Net.Uri uri = Android.Net.Uri.Parse("content://" + htmlToPdfFile);
Intent intent = new Intent(Intent.ActionView, uri);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.GrantReadUriPermission);
this.ApplicationContext.StartActivity(intent);
To convert in your Xamarin application for Android an URL to a PDF document in a memory buffer, save it to a file and open that file in a PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert an URL to a memory buffer
string htmlPageURL = "http://www.winnovative-software.com";
byte[] urlToPdfBuffer = converter.ConvertUrl(htmlPageURL);
// write the memory buffer to a PDF file
string documentsFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
string urlToPdfFile = System.IO.Path.Combine(documentsFolder, "UrlToMemory.pdf");
System.IO.File.WriteAllBytes(urlToPdfFile, urlToPdfBuffer);
// open the PDF document in the default PDF viewer
Android.Net.Uri uri = Android.Net.Uri.Parse("content://" + urlToPdfFile);
Intent intent = new Intent(Intent.ActionView, uri);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.GrantReadUriPermission);
this.ApplicationContext.StartActivity(intent);
To convert in your Xamarin application for macOS a HTML string to a PDF document in a memory buffer, save it to a file and open that file a in PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from Winnovative !", null);
// write the memory buffer to a PDF file
string htmlToPdfFile = "HtmlToMemory.pdf";
System.IO.File.WriteAllBytes(htmlToPdfFile, htmlToPdfBuffer);
// open the PDF document in the default PDF viewer
System.Diagnostics.Process.Start(htmlToPdfFile);
To convert in your Xamarin application for macOS an URL to a PDF document in a memory buffer, save it to a file and open that file in a PDF viewer you can use the C# code below.
// create the converter object in your code where you want to run conversion
// change the serverIP value if the server was installed on a remote machine
string serverIP = "127.0.0.1";
HtmlToPdfConverter converter = new HtmlToPdfConverter(serverIP);
// convert an URL to a memory buffer
string htmlPageURL = "http://www.winnovative-software.com";
byte[] urlToPdfBuffer = converter.ConvertUrl(htmlPageURL);
// write the memory buffer to a PDF file
string urlToPdfFile = "UrlToMemory.pdf";
System.IO.File.WriteAllBytes(urlToPdfFile, urlToPdfBuffer);
// open the PDF document in the default PDF viewer
System.Diagnostics.Process.Start(urlToPdfFile);