Winnovative client library allows you to easily convert in just a few lines of code PDF documents to HTML documents. The PDF to HTML Converter object of PdfToHtmlConverter type can be initialized with the TCP/IP address of the server or with the HTTP URL address of the server, function of the Winnovative Server type you have installed.
TCP/IP Server. If you installed the Winnovative Server in an Azure Cloud Service Worker Role, in an in an Azure Service Fabric Application or in a Windows Service on a remote Windows machine you can use the PdfToHtmlConverterPdfToHtmlConverter(String, UInt32) constructor which takes as parameters the server IP address and the TCP port.
HTTP Server. If you installed the Winnovative Server in an Azure Cloud Service Web Role or in an IIS ASP.NET Web Application you can use the PdfToHtmlConverterPdfToHtmlConverter(Boolean, String) constructor which takes as parameters a flag to be set on true to indicate the usage of a HTTP service and the HTTP Server URL string as the second parameter.
The PDF to HTML Converter allows you select the page range to convert and to specify the resolution and the zoom level of the resulted HTML content. These features of the PDF to HTML converter are exemplified in the code sample below. The full Visual Studio demo project for ASP.NET Web Forms or MVC is available in product package you can download from website.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnovativeClient;
namespace PdfToHtmlClientDemo
{
public partial class Default : System.Web.UI.Page
{
protected void convertPdfToHtmlButton_Click(object sender, EventArgs e)
{
// Get the server options
string serverIP = textBoxServerIP.Text;
uint serverPort = uint.Parse(textBoxServerPort.Text);
string servicePassword = textBoxServicePassword.Text;
bool useServicePassword = servicePassword.Length > 0;
bool useTcpService = radioButtonUseTcpService.Checked;
string webServiceUrl = textBoxWebServiceUrl.Text;
// the pdf file to convert
string pdfFilePath = filePathTextBox.Text.Trim();
if (pdfFilePath.Equals(String.Empty))
throw new Exception("Please choose a PDF file to convert");
// start page number
int startPageNumber = int.Parse(startPageTextBox.Text.Trim());
// end page number
// when it is 0 the extraction will continue up to the end of document
int endPageNumber = 0;
if (endPageTextBox.Text.Trim() != String.Empty)
endPageNumber = int.Parse(endPageTextBox.Text.Trim());
// Create the PDF to HTML converter object
PdfToHtmlConverter pdfToHtmlConverter = null;
if (useTcpService)
pdfToHtmlConverter = new PdfToHtmlConverter(serverIP, serverPort);
else
pdfToHtmlConverter = new PdfToHtmlConverter(true, webServiceUrl);
// Set optional service password
if (useServicePassword)
pdfToHtmlConverter.ServicePassword = servicePassword;
pdfToHtmlConverter.LicenseKey = "UtzN3cnM3c3dy9PN3c7M08zP08TExMTdzQ==";
// set the resolution of HTML images
pdfToHtmlConverter.Resolution = int.Parse(resolutionTextBox.Text);
// set the zoom of HTML content
pdfToHtmlConverter.Zoom = int.Parse(zoomTextBox.Text);
PdfPageHtml[] pdfPageHtmls = null;
try
{
// read the PDF file in a memory buffer
byte[] sourcePdfBytes = System.IO.File.ReadAllBytes(pdfFilePath);
// convert PDF pages in memory to an array of PdfPageHtml objects
pdfPageHtmls = pdfToHtmlConverter.ConvertPdfPagesToHtml(sourcePdfBytes, startPageNumber, endPageNumber);
}
catch (Exception ex)
{
// The conversion failed
throw new Exception(String.Format("An error occurred. {0}", ex.Message));
}
byte[] htmlBytes = null;
try
{
// get the HTML document for the first PDF page in range
htmlBytes = Encoding.UTF8.GetBytes(pdfPageHtmls[0].Html);
}
finally
{
// dispose the generated HTML documents
for (int i = 0; i < pdfPageHtmls.Length; i++)
pdfPageHtmls[i].Dispose();
}
Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=PdfPage.html; size={0}", htmlBytes.Length.ToString()));
Response.BinaryWrite(htmlBytes);
// End the HTTP response and stop the current page processing
Response.End();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filePathTextBox.Text = Server.MapPath("~/DemoFiles/Input/Demo.pdf");
Master.CollapseAll();
Master.ExpandNode("PDF_to_HTML");
Master.SelectNode("Getting_Started");
}
}
}
}