Example code is for an older version of WebGrabber, newer code is available.
// Copyright (c) 2021 ActivePDF, Inc.
// ActivePDF WebGrabber WBE 2010
// Example generated 03/01/21
using System;
// Make sure to add the ActivePDF product .NET DLL(s) to your application.
// .NET DLL(s) are typically found in the products 'bin' folder.
class Examples
{
public static void Example()
{
string strPath;
int intDoPrint;
strPath = System.AppDomain.CurrentDomain.BaseDirectory;
// Instantiate Object
APWebGrbNET.APWebGrabber oWG = new APWebGrbNET.APWebGrabber();
// Proxy settings in order to access external URL's
oWG.ProxyPortHTTP = "80";
oWG.ProxyServerHTTP = "192.168.1.5";
oWG.ProxyServerUserName = "john.doe";
oWG.ProxyServerPassword = "xxxxxxxx";
// Enable extra logging - c:\windows\activepdf\logs
// Logging should be disabled during production
oWG.Debug = true;
// Fast web view
oWG.LinearizeDocument = true;
// Time to wait for conversion to complete (in seconds)
oWG.Timeout = 30;
// Margins (Top, Bottom, Left, Right) 1.0 = 1"
oWG.SetMargins(0.75f, 0.75f, 0.75f, 0.75f);
// 0 = Portrait, 1 = Landscape
oWG.Orientation = 0;
// Convert HTML fields to PDF fields
oWG.PreserveButtons = false;
oWG.PreserveCheckBoxes = false;
oWG.PreserveDropDowns = false;
oWG.PreserveRadioButtons = false;
oWG.PreserveTextBoxes = false;
// Convert links
oWG.PreserveLinks = true;
// Enable flash conversion
oWG.EmbedFlash = true;
// PDF output location and filename
oWG.OutputDirectory = strPath;
oWG.NewDocumentName = "proxy.pdf";
// Save the HTML text into a file before conversion
oWG.HTMLTextToFile = true;
// HTML to convert
oWG.CreateFromHTMLText = "<html><body>";
oWG.CreateFromHTMLText = "Hello World!";
oWG.CreateFromHTMLText = "</body></html>";
// Perform the HTML to PDF conversion
intDoPrint = oWG.DoPrint("127.0.0.1", 54545);
if (intDoPrint != 0)
{
ErrorHandler("DoPrint", intDoPrint);
}
// Cleans up all internal string variables used during conversion
// By default variables are deleted 3 minutes after the conversion
oWG.CleanUp("127.0.0.1", 54545);
// Release Object
oWG = null;
// Process Complete
WriteResults("Done!");
}
// Error Handling
public static void ErrorHandler(string strMethod, object rtnCode)
{
WriteResults(strMethod + " error: " + rtnCode.ToString());
}
// Write output data
public static void WriteResults(string content)
{
// Choose where to write out results
// Debug output
//System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content);
// Console
Console.WriteLine(content);
// Log file
//using (System.IO.TextWriter writer = new System.IO.StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + "application.log", true))
//{
// writer.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content);
//}
}
}