// Copyright (c) 2021 ActivePDF, Inc. // ActivePDF WebGrabber 2016 // Example generated 01/26/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; WebGrabberDK.Results.WebGrabberResult results; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APWebGrabber.WebGrabber oWG = new APWebGrabber.WebGrabber(); // Add an email oWG.AddEMail(); // Set server information oWG.SetSMTPInfo("0.0.0.0", 25); oWG.SetSMTPCredentials("john.doe", "activePDF", "asdfasdf"); // Set email addresses oWG.SetSenderInfo("John Doe", "john.doe@asdidlwenra.com"); oWG.SetReplyToInfo("John Doe", "john.doe@asdidlwenra.com"); oWG.SetRecipientInfo("Jane Doe", "jane.doe@asdidlwenra.com"); oWG.AddToCC("Jim Doe", "jim.doe@asdidlwenra.com"); oWG.AddToBcc("Janice Doe", "janice.doe@asdidlwenra.com"); // Subject and Body oWG.EMailSubject = "PDF Delivery from activePDF"; oWG.SetEMailBody("<html><body style='background-color: #EEE; padding: 4px;'>Here is your PDF!</body></html>", true); // Attachments - Binary attachments can be added with AddEMailBinaryAttachment oWG.AddEMailAttachment(strPath + "x.pdf"); // Other email options oWG.EMailReadReceipt = false; oWG.EMailAttachOutput = true; // 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.75f, 0.75f, 0.75f, 0.75f); // 0 = Portrait, 1 = Landscape oWG.Orientation = 0; // Rendering engine used for the HTML // 0 = Native, 1 = IE oWG.EngineToUse = APWebGrabberInterface.ConversionEngine.Native; // Convert HTML fields to PDF fields oWG.PreserveButtons = false; oWG.PreserveCheckBoxes = false; oWG.PreserveDropDowns = false; oWG.PreserveRadioButtons = false; oWG.PreserveTextBoxes = false; // Convert links oWG.GenerateLinks = APWebGrabberInterface.LinkStyle.Both; // Convert h tags into bookmarks oWG.GenerateBookmarks = true; // Enable flash conversion oWG.EmbedFlash = 1; // PDF output location and filename oWG.OutputDirectory = strPath; oWG.NewDocumentName = "email.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) { ErrorHandler("ConvertToPDF", results, results.WebGrabberStatus.ToString()); } // If running multiple conversions in one instance: // One email can be removed before the next conversion oWG.RemoveEMail("john.doe@activepdf.com"); // An attachment can be removed oWG.ClearEMailAttachments(); // or all emails can be removed oWG.ClearEMails(); // Release Object oWG = null; // Process Complete WriteResults("Done!"); } // Error Handling public static void ErrorHandler(string strMethod, ADK.Results.Result results, string errorStatus) { WriteResults("Error with " + strMethod); WriteResults(errorStatus); WriteResults(results.Details); if (results.Origin.Function != strMethod) { WriteResults(results.Origin.Class + "." + results.Origin.Function); } if (results.ResultException != null) { // To view the stack trace on an exception uncomment the line below //WriteResults(results.ResultException.StackTrace); } Environment.Exit(1); } // 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); //} } }