' Copyright (c) 2021 ActivePDF, Inc. ' ActivePDF WebGrabber 2016 ' Example generated 03/04/21 Imports 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. Public Class Examples Sub Example() Dim strPath As String, results As WebGrabberDK.Results.WebGrabberResult strPath = AppDomain.CurrentDomain.BaseDirectory ' Instantiate Object Dim oWG As APWebGrabber.WebGrabber = New APWebGrabber.WebGrabber() ' Set the quality options for the created PDF (IE engine only) ' For custom settings to take effect set the configuration to custom oWG.PredefinedSetting = ADK.PostScript.PredefinedConfiguration.Custom ' Specifies if ASCII85 encoding should be applied to binary streams oWG.ASCIIEncode = true ' Automatically control the page orientation based on text flow oWG.AutoRotate = true ' Specifies if CMYK colors should be converted to RGB oWG.ConvertCMYKToRGB = true ' Set the DPI for the created PDF oWG.Resolution = 300.0 ' Color Image Quality Settings oWG.ColorImageDownsampleThreshold = 1 oWG.ColorImageDownsampleType = ADK.PostScript.Images.DownsampleOption.None oWG.ColorImageFilter = ADK.PostScript.Images.CompressionOption.FlateEncode oWG.ColorImageResolution = 72 ' Gray Image Quality Settings oWG.GrayImageDownsampleThreshold = 1 oWG.GrayImageDownsampleType = ADK.PostScript.Images.DownsampleOption.None oWG.GrayImageFilter = ADK.PostScript.Images.CompressionOption.FlateEncode oWG.GrayImageResolution = 72 ' Monochrome Image Quality Settings oWG.MonoImageDownsampleThreshold = 1 oWG.MonoImageDownsampleType = ADK.PostScript.Images.DownsampleOption.None oWG.MonoImageFilter = ADK.PostScript.Images.MonochromeCompression.FlateEncode oWG.MonoImageResolution = 72 ' Enable extra logging (logging should only be used while troubleshooting) ' C:\ProgramData\activePDF\Logs\ oWG.Debug = true ' Fast web view oWG.LinearizePDF = true ' Time to wait for conversion to complete (in seconds) ' Set the amount of time before a request will time out oWG.TimeoutSpan = new TimeSpan(0, 0, 40) ' Margins (Top, Bottom, Left, Right) 1.0 = 1" oWG.SetMargins(0.75, 0.75, 0.75, 0.75) ' 0 = Portrait, 1 = Landscape oWG.Orientation = 0 ' Rendering engine used for the HTML ' 0 = Native, 1 = IE oWG.EngineToUse = APWebGrabberInterface.ConversionEngine.IE ' Convert the HTML background (IE engine only) oWG.PrintBackground = true ' PDF output location and filename oWG.OutputDirectory = strPath oWG.NewDocumentName = "quality.pdf" ' HTML to convert ' Examples: ' http://domain.com/path/file.aspx ' c:\folder\file.html oWG.URL = "http://examples.activepdf.com/samples/doc" ' Perform the HTML to PDF conversion results = oWG.ConvertToPDF() If results.WebGrabberStatus <> WebGrabberDK.Results.WebGrabberStatus.Success Then ErrorHandler("ConvertToPDF", results, results.WebGrabberStatus.ToString()) End If ' Release Object oWG = Nothing ' Process Complete WriteResults("Done!") End Sub ' Error Handling Sub ErrorHandler(ByVal strMethod As String, ByVal results As ADK.Results.Result, ByVal errorStatus As String) WriteResults("Error with " + strMethod) WriteResults(errorStatus) WriteResults(results.Details) If results.Origin.Function <> strMethod Then WriteResults(results.Origin.Class + "." + results.Origin.Function) End If If Not results.ResultException Is Nothing Then ' To view the stack trace on an exception uncomment the line below 'WriteResults(results.ResultException.StackTrace) End If Environment.Exit(1) End Sub ' Write output data Sub WriteResults(content As String) ' Choose where to write out results ' Debug output 'System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content) ' Console Console.WriteLine(content) ' Log file 'Using tw = New System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory & "application.log", True) ' tw.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content) 'End Using End Sub End Class