Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Combine PDF files with RBScript
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/Combine PDF files with RBScript
This example is the version from Thu, 6th Apr 2016.
Project "Combine PDF files with RBScript.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control RunButton Inherits PushButton
ControlInstance RunButton Inherits PushButton
EventHandler Sub Action() Init RbScript1.Context = context RbScript1.Source = TextArea1.text RbScript1.run End EventHandler
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control RbScript1 Inherits RbScript
ControlInstance RbScript1 Inherits RbScript
EventHandler Sub CompilerError(line As Integer, errorNumber As Integer, errorMsg As String) MsgBox "Compile Error "+str(errorNumber)+" in line "+str(line)+": "+errorMsg End EventHandler
EventHandler Sub Print(msg As String) MsgBox msg End EventHandler
EventHandler Sub RuntimeError(line As Integer, error As RuntimeException) MsgBox "Runtime in line "+str(line)+": "+Introspection.GetType(error).fullname+" "+error.Message End EventHandler
End Control
Sub init() dim pdf as new MyDynapdfMBS pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License call pdf.SetImportFlags(pdf.kifImportAsPage + pdf.kifImportAll) Context = new ScriptContext(pdf) End Sub
Property Context As ScriptContext
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
MyFileTypes
Filetype application/pdf
End MyFileTypes
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 ScriptContext
Function Child(path as string, name as string) As string dim f as FolderItem = GetFolderItem(path, FolderItem.PathTypeShell) dim g as FolderItem = f.Child(name) Return g.ShellPath Exception u as UnsupportedFormatException // invalid path? End Function
Function CloseFile() As Boolean return pdf.CloseFile End Function
Function CloseImportFile() As Boolean Return pdf.CloseImportFile End Function
Sub Constructor(p as MyDynaPDFMBS) pdf = p End Sub
Function DesktopPath() As string Return SpecialFolder.Desktop.ShellPath End Function
Function GetPageCount() As integer Return pdf.GetPageCount End Function
Function ImportPDFFile(DestPageNumber as Integer) As integer return pdf.ImportPDFFile(DestPageNumber) End Function
Sub Launch(path as string) dim f as FolderItem = GetFolderItem(path, FolderItem.PathTypeShell) f.launch Exception u as UnsupportedFormatException // invalid path? End Sub
Function OpenImportFile(path as string) As integer dim f as FolderItem = GetFolderItem(path, FolderItem.PathTypeShell) Return pdf.OpenImportFile(F) Exception u as UnsupportedFormatException Return -1 // invalid path? End Function
Function StartNewPDF(path as string) As Boolean dim f as FolderItem = GetFolderItem(path, FolderItem.PathTypeShell) return pdf.CreateNewPDF(f) Exception u as UnsupportedFormatException Return false // invalid path? End Function
Property Private pdf As MyDynaPDFMBS
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 PDF Plugins