Platforms to show: All Mac Windows Linux Cross-Platform
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/Show Javascript
This example is the version from Mon, 3rd May 2020.
Project "Show Javascript.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument()
dim f as FolderItem = GetOpenFolderItem(FileTypes1.Pdf)
if f<>Nil then
OpenDocument f
end if
End EventHandler
EventHandler Sub OpenDocument(item As FolderItem)
dim w as new MainWindow
w.run item
w.show
End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change()
if me.ListIndex = -1 then
TextArea1.Text = ""
else
TextArea1.Text = me.RowTag(me.ListIndex)
end if
End EventHandler
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Sub ShowAction(p as DynaPDFMBS, Action as integer, LabelText as string, FieldName as string = "")
Dim a As DynaPDFJavaScriptActionMBS = p.GetJavaScriptActionEx(Action)
If a <> Nil Then
list.AddRow LabelText, FieldName, Str(Action)
List.RowTag(list.LastIndex) = a.Script
// look for more...
While a.NextAction <> -1
a = p.GetJavaScriptActionEx(a.NextAction)
If a <> Nil Then
list.AddRow LabelText, FieldName, Str(a.NextAction)
List.RowTag(list.LastIndex) = a.Script
Else
Exit While // end of list
End If
Wend
Else
Break // error?
End If
End Sub
Sub run(file as FolderItem)
Title = file.DisplayName
dim p as new MyDynapdfMBS
p.SetLicenseKey "Lite" // For this example you can use Lite, Pro or Enterprise License
call p.CreateNewPDF(nil)
// Skip anything that is not required
call p.SetImportFlags p.kifImportAll+p.kifImportAsPage
// From which PDF file do you want to extract the images?
call p.OpenImportFile(file, p.kptOpen, "")
// import pages
call p.ImportPDFFile(1, 1.0, 1.0)
call p.CloseImportFile
// lookup all links
dim u as integer = p.GetJavaScriptCount-1
for i as integer = 0 to u
dim name as string = p.GetJavaScriptName(i)
dim code as string = p.GetJavaScriptEx(name)
list.AddRow Str(i), name
List.RowTag(list.LastIndex) = code
next
// check fields
u = p.GetFieldCount-1
For i As Integer = 0 To u
Dim f As DynaPDFFieldExMBS = p.GetFieldEx(i)
If f = Nil Then
Break // error?
Else
Dim Action As Integer = f.Action
Dim ActionType As Integer = f.ActionType
If action <> -1 Then
ShowAction p, action, "Field "+Str(i)+" action", f.FieldName
End If
Dim e As DynaPDFObjEventMBS = f.Events
While e <> Nil
action = e.Action
ActionType = f.ActionType
If action <> -1 Then
ShowAction p, action, "Field "+Str(i)+" event", f.FieldName
End If
e = e.NextObject
Wend
End If
Next
// check pages
u = p.GetPageCount
For i As Integer = 1 To u
Dim f As DynaPDFObjActionsMBS
Dim r As Integer = p.GetObjActions(p.kotPage, i, f)
If r > 0 Then
If f <> Nil then
Dim Action As Integer = f.Action
Dim ActionType As Integer = f.ActionType
If action <> -1 Then
ShowAction p, action, "Page "+Str(i)+" action"
End If
End If
Dim e As DynaPDFObjEventMBS = f.Events
While e <> Nil
Dim Action As Integer = e.Action
Dim ActionType As Integer = e.ActionType
If action <> -1 Then
ShowAction p, action, "Page "+Str(i)+" event"
End If
e = e.NextObject
Wend
end if
Next
// check annotations
u = p.GetAnnotCount-1
For i As Integer = 0 To u
Dim f As DynaPDFObjActionsMBS
Dim r As Integer = p.GetObjActions(p.kotAnnotation, i, f)
If r > 0 Then
If f <> Nil Then
Dim Action As Integer = f.Action
Dim ActionType As Integer = f.ActionType
If action <> -1 Then
ShowAction p, action, "Annotation "+Str(i)+" action"
End If
End If
Dim e As DynaPDFObjEventMBS = f.Events
While e <> Nil
Dim Action As Integer = e.Action
Dim ActionType As Integer = e.ActionType
If action <> -1 Then
ShowAction p, action, "Annotation "+Str(i)+" event"
End If
e = e.NextObject
Wend
End If
Next
// check bookmark
u = p.GetBookmarkCount-1
For i As Integer = 0 To u
Dim f As DynaPDFObjActionsMBS
Dim r As Integer = p.GetObjActions(p.kotBookmark, i, f)
If r > 0 Then
If f <> Nil Then
Dim Action As Integer = f.Action
Dim ActionType As Integer = f.ActionType
If action <> -1 Then
ShowAction p, action, "Bookmark "+Str(i)+" action"
End If
End If
Dim e As DynaPDFObjEventMBS = f.Events
While e <> Nil
Dim Action As Integer = e.Action
Dim ActionType As Integer = e.ActionType
If action <> -1 Then
ShowAction p, action, "Bookmark "+Str(i)+" event"
End If
e = e.NextObject
Wend
End If
Next
// check catalog
If True Then
Dim f As DynaPDFObjActionsMBS
Dim r As Integer = p.GetObjActions(p.kotCatalog, 0, f)
If r > 0 Then
If f <> Nil Then
Dim Action As Integer = f.Action
Dim ActionType As Integer = f.ActionType
If action <> -1 Then
ShowAction p, action, "Catalog action"
End If
End If
Dim e As DynaPDFObjEventMBS = f.Events
While e <> Nil
Dim Action As Integer = e.Action
Dim ActionType As Integer = e.ActionType
If action <> -1 Then
ShowAction p, action, "Catalog event"
End If
e = e.NextObject
Wend
End If
End If
End Sub
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
FileTypes1
Filetype application/pdf
End FileTypes1
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
End Project
See also:
The items on this page are in the following plugins: MBS DynaPDF Plugin.