Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Create PDF and Email
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF and Email
This example is the version from Wed, 14th Sep 2021.
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF and Email
This example is the version from Wed, 14th Sep 2021.
Project "Create PDF and Email.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
// output all messages on the console:
System.DebugLog str(ErrorCode)+": "+ErrorMessage
// and display dialog:
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon=MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Continue"
d.CancelButton.Visible=True //show the Cancel button
// a warning or an error?
if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then
// if user decided to ignore, we'll ignore
if IgnoreWarnings then Return 0
d.Message="A warning occurred while processing your PDF code."
// we add a third button to display all warnings
d.AlternateActionButton.Caption = "Ignore warnings"
d.AlternateActionButton.Visible = true
else
d.Message="An error occurred while processing your PDF code."
end if
d.Explanation = str(ErrorCode)+": "+ErrorMessage
b=d.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case d.ActionButton
Return 0 // ignore
Case d.AlternateActionButton
IgnoreWarnings = true
Return 0 // ignore
Case d.CancelButton
Return -1 // stop
End select
End EventHandler
Property IgnoreWarnings As Boolean
End Class
Class MainWindow Inherits Window
Control SendButton Inherits PushButton
ControlInstance SendButton Inherits PushButton
EventHandler Sub Action()
me.Enabled = false
run
End EventHandler
End Control
Control Result Inherits Label
ControlInstance Result Inherits Label
End Control
Control Server Inherits TextField
ControlInstance Server Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control Username Inherits TextField
ControlInstance Username Inherits TextField
End Control
Control Passwort Inherits TextField
ControlInstance Passwort Inherits TextField
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control content Inherits TextArea
ControlInstance content Inherits TextArea
End Control
Control ToName Inherits TextField
ControlInstance ToName Inherits TextField
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control FromName Inherits TextField
ControlInstance FromName Inherits TextField
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control Subject Inherits TextField
ControlInstance Subject Inherits TextField
End Control
Control sock Inherits SMTPSocket
ControlInstance sock Inherits SMTPSocket
EventHandler Sub ConnectionEstablished(greeting as string)
dim s as string = "Connection estalished: "+greeting
System.DebugLog s
result.Text = s
End EventHandler
EventHandler Sub Error()
if sent then
// ignore
else
dim s as string = "Error: "+str(me.LastErrorCode)
System.DebugLog s
result.Text = s
end if
SendButton.Enabled = true
End EventHandler
EventHandler Sub MailSent()
dim s as string = "Mail sent."
System.DebugLog s
result.Text = s
sent = true
End EventHandler
EventHandler Sub MessageSent(Email as EmailMessage)
dim s as string = "Message sent."
System.DebugLog s
result.Text = s
End EventHandler
EventHandler Sub ServerError(ErrorID as integer, ErrorMessage as string, Email as EmailMessage)
dim s as string ="Server error "+str(ErrorID)+": "+ErrorMessage
System.DebugLog s
result.Text = s
End EventHandler
End Control
Function CreatePDF() As string
dim pdf as new MyDynapdfMBS
dim d as new date
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
// create in memory
call pdf.CreateNewPDF nil
call pdf.SetDocInfo pdf.kdiSubject, "My first Xojo output"
call pdf.SetDocInfo pdf.kdiProducer, "Xojo test application"
call pdf.SetDocInfo pdf.kdiTitle, "My first Xojo output"
// We want to use top-down coordinates
call pdf.SetPageCoords pdf.kpcTopDown
call pdf.Append
call pdf.SetFont "Times", pdf.kfsItalic, 40.0, true, pdf.kcpUnicode
call pdf.WriteFText pdf.ktaCenter, "My first Xojo output!"
call pdf.SetFont "Times", pdf.kfsItalic, 20.0, true, pdf.kcpUnicode
call pdf.WriteText 50.0, 180.0, "File created: " + d.LongDate
call pdf.EndPage
call pdf.CloseFile
// get PDF buffer
Return pdf.GetBuffer
End Function
Sub Run()
// we store stuff in variables here to avoid the ThreadAccessingUIException
dim PDFData as string = CreatePDF
dim em as new EmailMessage
em.AddRecipient ToName.text
em.FromAddress = FromName.text.ConvertEncoding(Encodings.WindowsLatin1)
em.Subject = Subject.text.ConvertEncoding(Encodings.WindowsLatin1)
em.BodyPlainText = content.text.ConvertEncoding(Encodings.WindowsLatin1)
em.Headers.AppendHeader "Mime-Version", "1.0"
em.Headers.AppendHeader "Content-type", "text/plain; charset=iso-8859-1"
em.Headers.AppendHeader "Content-Transfer-Encoding", "8bit"
em.Headers.AppendHeader "Content-Language", "en-US"
em.Headers.AppendHeader "X-Mailer", "Xojo Test Mailer"
'em.Headers.AppendHeader "Reply-To", "some@mailadress.com"
dim a as new EmailAttachment
a.Data = EncodeBase64(PDFData)
a.ContentEncoding = "base64"
a.MIMEType = "application/pdf"
a.Name = "report.pdf"
em.Attachments.Append a
sent = false
sock.Address = server.Text
sock.Username = Username.Text
sock.Password = Passwort.Text
sock.Messages.Append em
sock.SendMail
End Sub
Property sent As Boolean
End Class
End Project
See also:
- /DynaPDF/Create Fields with JavaScript Actions
- /DynaPDF/Create PDF
- /DynaPDF/Create PDF with Annotations
- /DynaPDF/Create PDF with Circle
- /DynaPDF/Create PDF with Circle Text
- /DynaPDF/Create PDF with DeviceN Colorspace
- /DynaPDF/Create PDF with named destination
- /DynaPDF/Create PDF with restrictions web
- /DynaPDF/Create PDF with vertical text
- /DynaPDF/Create Previews for folder
The items on this page are in the following plugins: MBS DynaPDF Plugin.
