Looking to convert HTML to PDF, or perhaps URLs to PDF, but you aren't sure where to start? ActivePDF's WebGrabber PDF SDK makes it so easy, even someone with minimal coding knowledge can use it. WebGrabber is the .NET developer tool that converts webpages or raw HTML files into PDF documents.
Consistent, reliable, and accurate, WebGrabber generates high-quality, compact PDF files from HTML or URLs using a familiar standards-based language.
But, rather than tell you how easy it is to use, we'll show you.
First and foremost, you can't expect to convert HTML to PDF without the necessary hardware and software. Luckily, the requirements are pretty low.
The following software is required:
The minimum hardware requirements are:
After verifying you have the appropriate software and hardware, there's one more vital piece to the puzzle: ActivePDF's WebGrabber. Our WebGrabber enables rapid, high quality, and server-based HTML to PDF conversion. It's dead simple to use, and best of all, you can download a free, single developer trial that includes unlimited assistance.
Once downloaded, you'll go through a typical installation phase:
From there, you can select IE to enable it's use as a rendering engine (we'll cover this more later) by doing the following:
The code used in this tutorial will be C# since it's widely adopted by corporations both large and small, but WebGrabber works with VB.NET, VBS, ASP, PHP, CF, and Ruby as well. If you want to see how to convert HTML to PDF in those languages take a look at some of the code examples on our site.
Now at this point, you may be saying: "But I thought you said 6 easy steps! Code isn't easy!". But, as you'll soon see, WebGrabber was made to be as simple to use as possible. The PDF API calls you'll be adding to your application are simple and straightforward. So, let's dive right in.
For starters, you'll need to add ActivePDF's .net DLL(s) to your app and instantiate the object. By default, the .NET Assembly can be found at http://documentation.activepdf.com/webgrabber_api/Content/d_appendix/Instantiation.html.
using System;
class Examples
{
public static void Example()
{
string strPath;
WebGrabberDK.Results.WebGrabberResult results;
strPath = System.AppDomain.CurrentDomain.BaseDirectory;
APWebGrabber.WebGrabber oWG = new APWebGrabber.WebGrabber();
}
}
WebGrabber offers two rendering engines for your choosing, each with pros and cons that enable you to either optimize for performance or for quality of the rendering. You can use IE or our own native engine. Before we tell you how to pick each, let's first go over which is best for your application:
The Native Engine is WebGrabber's default, built-in rendering engine. It is designed to provide the best print output.
Pros
Cons
The IE Engine instantiates Internet Explorer for rendering. In general, anything rendered by Internet Explorer will appear in your output PDF.
Pros
Cons
Choosing which engine to use is simple with the command below:
// Rendering engine used for the HTML
// Native = APWebGrabberInterface.ConversionEngine.Native; IE = APWebGrabberInterface.ConversionEngine.IE:
oWG.EngineToUse = APWebGrabberInterface.ConversionEngine.Native;
At this point, your app has loaded ActivePDF and you're ready to begin telling it what to output. This is done through several simple API calls. We've listed the most commonly used ones below:
// true = enable, false = disable
oWG.Debug = true;
// true - enable, false = disable
oWG.LinearizePDF = true;
// (hours, minutes, seconds)
oWG.TimeoutSpan = new TimeSpan(0, 0, 40);
// (Top, Bottom, Left, Right) and 1.0 = 1"
oWG.SetMargins(0.75f, 0.75f, 0.75f, 0.75f);
// 0 = Portrait, 1 = Landscape
oWG.Orientation = 0;
// true = enable, false = disable
oWG.PrintBackground = true;
oWG.OutputDirectory = strPath;
oWG.NewDocumentName = "example.pdf";
Choosing what HTML you wish to convert is incredibly easy! First you must decide whether you wish to convert a URL or HTMLText. We'll cover both below:
To convert from a URL, you simply need to add the oWG.URL call to your application. You can choose both file locations, like: "c:\folder\file.html", and locations from the web, such as "http://domain.com/path/file.aspx". Used in your app, it'll appear like this:
oWG.URL = "http://examples.activepdf.com/samples/doc";
Converting from HTMLText is a little more difficult, but can still be done in only 4 lines of code. There are two major steps that need to be considered. First is whether or not to save the HTML text into a file before conversion. This is done with the following API call:
// true = enable, false = disable
oWG.HTMLTextToFile = true;
From there, you simply need to specify the HTML to convert:
oWG.CreateFromHTMLText = "<html><body>";
oWG.CreateFromHTMLText = "Hello World!";
oWG.CreateFromHTMLText = "</body></html>";
Next, you need to perform the HTML to PDF conversion. No worries, WebGrabber will do all the heavy lifting for you. Simply add the following code to your app and you'll be good to go:
results = oWG.ConvertToPDF();
if (results.WebGrabberStatus != WebGrabberDK.Results.WebGrabberStatus.Success)
{
ErrorHandler("ConvertToPDF", results, results.WebGrabberStatus.ToString());
}
oWG = null;
WriteResults("Done!");
}
And there you have it. You now have everything you need to convert HTML to PDF!
ActivePDF's support is unsurpassed. And those aren't our words, they're our customers! If you still need help converting HTML to a secure PDF File, reach out to our technology advisers and we'll answer your questions, find solutions, and give you a greater turnaround time than any other company can.
Subscribe now!