The following VB.NET example demonstrates how to generate PDF from a webpage and then send the resultant output as an e-mail attachment.
NOTE: Refer to KB #10687 for instructions on how to reference WebGrabber in .NET.
NOTE: This example is available in other codes. You may select from the Code Sample list above to display the download link for the example in the language appropriate for your environment.
This file is required:
ConvertandEmail.vb - Class file detail provided below.
Click here to download this example:
Imports APServerNET
Imports APWebGrbNET
Public Class ConvertAndEmail
Public Sub exEmail()
' Define Variables
' EngineToUse (1=IE, 0=Native)
Dim intEngine As Integer = 1
' URL format: "http://www.activepdf.com" or "file://folder/file.htm"
Dim strURL As String = "http://www.activepdf.com/support/knowledgebase/view.cfm?kb=11687&code=vb.net"
' Timeout for various calls
Dim intTimeout As Integer = 60
' For local machine use these defaults
Dim strIP As String = "127.0.0.1"
Dim longPort As Long = 64320
' Instantiate Objects
Dim SVR As APServerNET.APServer = New APServerNET.APServer
Dim WG As APWebGrbNET.APWebGrabber = New APWebGrbNET.APWebGrabber
' Set activePDF Server properties
SVR.OutputDirectory = Application.StartupPath
SVR.PDFTimeout = intTimeout
' Must call before DoPrint to pass server settings to WG
WG.Prt2DiskSettings = SVR.ToString()
' Set WebGrabber properties
WG.EngineToUse = intEngine
WG.URL = strURL
WG.Timeout = intTimeout
WG.PrinterTimeout = intTimeout
If intEngine = 0 Then
WG.PrintBackgroundColors = 1
WG.TopBottomMargin = 150
WG.LeftRightMargin = 150
End If
' Set Email options
WG.SMTPServer = "255.255.255.255"
WG.EMailTo = "John Doe <johndoe@webgrabbertest.com>"
WG.EMailNameFrom = "John Doe"
WG.EMailIDFrom = "<johndoe@webgrabbertest.com>"
WG.EMailSubject = "WebGrabber Convert and Email Test"
WG.EMailText = "The converted PDF should be attached to this email."
' Start the conversion process
Dim lngDoPrintRtn As Long = WG.DoPrint(strIP, longPort)
If lngDoPrintRtn <> 0 Then
MsgBox("'DoPrint' failed with a '" & lngDoPrintRtn & "'" & vbCrLf & "KB article on Return codes:" & vbCrLf & "http://www.activepdf.com/support/kb/?id=10033&tk=ts", MsgBoxStyle.Critical, "Convert and Email Status")
Else
' Wait for conversion result
Dim strWaitRtn As String = WG.Wait(strIP, longPort, intTimeout, "")
If strWaitRtn <> "019" Then
MsgBox("'Wait' failed with a '" & strWaitRtn & "'" & vbCrLf & "KB article on Return codes:" & vbCrLf & "http://www.activepdf.com/support/kb/?id=10033&tk=ts", MsgBoxStyle.Critical, "Convert and Email Status")
End If
End If
' Run WG CleanUp
WG.CleanUp(strIP, longPort)
' Clear Objects
WG = Nothing
SVR = Nothing
' Done
MsgBox("Finished", MsgBoxStyle.Information, "Convert and Email Status")
The information in this article is for the use of activePDF Customers and Evaluation Users Only. No part of this document may be transmitted or reproduced without the express written consent of activePDF.