Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Web Edition/Cards
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Web Edition/Cards
This example is the version from Thu, 6th Apr 2016.
Project "Cards.rbp"
Class App Inherits WebApplication
EventHandler Sub Open() // Please provide your own Cards folder with files: // thumb*.jpg for little thumbnails of pictures // pic*.jpg for actual pictures // back*.jpg for backgrounds as thumbnail pictures // back*.pdf for actual backgrounds as PDF // back*small.pdf for actual backgrounds as PDF with lower resolution dim f as FolderItem = FindFile("Cards") while not f.Exists if f.parent.parent = nil then print "Failed to find Cards folder" break quit end if f = f.parent.parent.Child("Cards") wend Thumbnails.Append new WebPicture(Picture.Open(f.Child("thumb1.jpg")), Picture.FormatJPEG) Thumbnails.Append new WebPicture(Picture.Open(f.Child("thumb2.jpg")), Picture.FormatJPEG) Thumbnails.Append new WebPicture(Picture.Open(f.Child("thumb3.jpg")), Picture.FormatJPEG) Thumbnails.Append new WebPicture(Picture.Open(f.Child("thumb4.jpg")), Picture.FormatJPEG) pictureFiles.Append f.Child("pic1.jpg") pictureFiles.Append f.Child("pic2.jpg") pictureFiles.Append f.Child("pic3.jpg") pictureFiles.Append f.Child("pic4.jpg") BackPictures.Append new WebPicture(Picture.Open(f.Child("back1.jpg")), Picture.FormatJPEG) BackPictures.Append new WebPicture(Picture.Open(f.Child("back2.jpg")), Picture.FormatJPEG) BackPictures.Append new WebPicture(Picture.Open(f.Child("back3.jpg")), Picture.FormatJPEG) BackPictures.Append new WebPicture(Picture.Open(f.Child("back4.jpg")), Picture.FormatJPEG) backs.Append f.Child("back1.pdf") backs.Append f.Child("back2.pdf") backs.Append f.Child("back3.pdf") backs.Append f.Child("back4.pdf") backsmall.Append f.Child("back1small.pdf") backsmall.Append f.Child("back2small.pdf") backsmall.Append f.Child("back3small.pdf") backsmall.Append f.Child("back4small.pdf") End EventHandler
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Property BackPictures() As WebPicture
Property Backs() As folderitem
Property Thumbnails() As WebPicture
Property backsmall() As folderitem
Property pictureFiles() As folderitem
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
End Class
Class WebPage1 Inherits WebPage
Control Button1 Inherits WebButton
ControlInstance Button1 Inherits WebButton
EventHandler Sub Action() dim pdf as new MyDynapdfMBS create pdf CurrentFile = new WebFile CurrentFile.Filename = "test.pdf" CurrentFile.MIMEType = "application/pdf" CurrentFile.Data = pdf.GetBuffer HTMLViewer1.URL = CurrentFile.URL info.Text = Format(lenb(CurrentFile.Data)/1024, "0")+" KB" End EventHandler
End Control
Control HTMLViewer1 Inherits WebHTMLViewer
ControlInstance HTMLViewer1 Inherits WebHTMLViewer
End Control
Control Button2 Inherits WebButton
ControlInstance Button2 Inherits WebButton
EventHandler Sub Action() dim pdf as new MyDynapdfMBS create pdf CurrentFile = new WebFile CurrentFile.Filename = "test.pdf" CurrentFile.MIMEType = "application/pdf" CurrentFile.Data = pdf.GetBuffer CurrentFile.ForceDownload = true info.Text = Format(lenb(CurrentFile.Data)/1024, "0")+" KB" showurl(CurrentFile.url) End EventHandler
End Control
Control Label1 Inherits WebLabel
ControlInstance Label1 Inherits WebLabel
End Control
Control TextField1 Inherits WebTextField
ControlInstance TextField1 Inherits WebTextField
End Control
Control Label2 Inherits WebLabel
ControlInstance Label2 Inherits WebLabel
End Control
Control PreviewImage Inherits WebImageView
ControlInstance PreviewImage Inherits WebImageView
End Control
Control RadioImage Inherits WebRadioGroup
ControlInstance RadioImage Inherits WebRadioGroup
EventHandler Sub SelectionChanged() dim n as integer = val(me.SelectedTag) PreviewImage.Picture = app.Thumbnails(n) End EventHandler
End Control
Control Label3 Inherits WebLabel
ControlInstance Label3 Inherits WebLabel
End Control
Control RadioBack Inherits WebRadioGroup
ControlInstance RadioBack Inherits WebRadioGroup
EventHandler Sub SelectionChanged() dim n as integer = val(me.SelectedTag) PreviewBack.Picture = app.BackPictures(n) End EventHandler
End Control
Control PreviewBack Inherits WebImageView
ControlInstance PreviewBack Inherits WebImageView
End Control
Control Label4 Inherits WebLabel
ControlInstance Label4 Inherits WebLabel
End Control
Control TextField2 Inherits WebTextField
ControlInstance TextField2 Inherits WebTextField
End Control
Control Label5 Inherits WebLabel
ControlInstance Label5 Inherits WebLabel
End Control
Control CheckBox1 Inherits WebCheckBox
ControlInstance CheckBox1 Inherits WebCheckBox
End Control
Control info Inherits WebLabel
ControlInstance info Inherits WebLabel
End Control
Control Label6 Inherits WebLabel
ControlInstance Label6 Inherits WebLabel
End Control
Control Link1 Inherits WebLink
ControlInstance Link1 Inherits WebLink
End Control
EventHandler Sub Open() PreviewBack.Picture = app.BackPictures(0) PreviewImage.Picture = app.Thumbnails(0) End EventHandler
Sub Create(pdf as dynaPDFMBS) dim d as new date dim f as FolderItem = SpecialFolder.Desktop.Child("Create PDF.pdf") pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License call pdf.CreateNewPDF nil call pdf.SetDocInfo pdf.kdiSubject, "My first REAL Studio output" call pdf.SetDocInfo pdf.kdiProducer, "REAL Studio test application" call pdf.SetDocInfo pdf.kdiTitle, "My first REAL Studio output" dim file as folderitem if CheckBox1.Value then // reduce quality call pdf.SetJPEGQuality(50) call pdf.SetResolution(100) call pdf.SetCompressionFilter(pdf.kcfJPEG) call pdf.SetSaveNewImageFormat(true) file = app.backsmall(val(RadioBack.SelectedTag)) else // maximum quality call pdf.SetJPEGQuality(80) call pdf.SetResolution(300) call pdf.SetCompressionFilter(pdf.kcfFlate) call pdf.SetSaveNewImageFormat(false) file = app.Backs(val(RadioBack.SelectedTag)) end if // We want to use top-down coordinates call pdf.OpenImportFile(file, 0, "") call pdf.ImportPDFFile(1, 1.0, 1.0) call pdf.EditPage(1) call pdf.SetFont "Times", pdf.kfsItalic, 30.0, true, pdf.kcp1252 call pdf.SetTextRect 0, 750, pdf.GetPageWidth, 100 call pdf.WriteFText pdf.ktaCenter, TextField1.Text call pdf.SetFont "Times", pdf.kfsItalic, 30.0, true, pdf.kcp1252 call pdf.SetTextRect 0, 130, pdf.GetPageWidth, 100 call pdf.WriteFText pdf.ktaCenter, TextField2.Text dim picfile as folderitem = app.pictureFiles(val(RadioImage.SelectedTag)) dim w as Double = 500 dim h as Double = 375 dim x as Double = (pdf.getpagewidth-w)/2 dim y as Double = (pdf.getpageheight-h)/2 call pdf.InsertImageEx(x,y,w,h, picfile, 1) call pdf.SetFont "Times", pdf.kfsNone, 10.0, true, pdf.kcp1252 call pdf.WriteText 20.0, 20.0, d.LongDate+" "+d.LongTime+", Made with REAL Studio Web Edition and MBS DynaPDF Plugin." call pdf.EndPage call pdf.CloseFile End Sub
Property CurrentFile As WebFile
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 WebPage1.MsgBox ErrorMessage Return 0 // ignore End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS DynaPDF Plugin.




Links
MBS Xojo Plugins