Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Object Actions
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Object Actions
This example is the version from Sat, 19th Jan 2018.
Project "Object Actions.rbp"
FileTypes
Filetype text
Filetype icc
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() dim pdf as new MyDynapdfMBS pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License // We create the output file later if no error occurred. call pdf.CreateNewPDF(nil) // import all call pdf.SetImportFlags BitwiseOr(pdf.kifImportAll, pdf.kifImportAsPage) dim filePath as FolderItem=FindFile("dynapdf_help.pdf") if (pdf.OpenImportFile(filePath, pdf.kptOpen, "") < 0) then msgbox "Input file """+filePath.Name+""" not found!" quit end if call pdf.ImportPDFFile(1, 1.0, 1.0) call pdf.CloseImportFile MainWindow.run 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
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 List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer) dim v as Variant = me.RowTag(row) if v = nil then Return if v isa DynaPDFObjActionsMBS then dim o as DynaPDFObjActionsMBS = v List.AddRow "Action", str(o.Action) List.AddRow "ActionType", str(o.ActionType)+ " "+GetActionTypeString(o.ActionType) if o.Events = nil then List.AddRow "Events", "none" else List.AddFolder "Events" List.RowTag(List.LastIndex) = o.Events end if Return end if if v isa DynaPDFObjEventMBS then dim o as DynaPDFObjEventMBS = v List.AddRow "Action", str(o.Action) List.AddRow "ActionType", str(o.ActionType)+ " "+GetActionTypeString(o.ActionType) List.AddRow "ObjEvent", str(o.ObjEvent) if o.NextObject = nil then List.AddRow "Events", "" else List.AddFolder "NextObject" List.RowTag(List.LastIndex) = o.NextObject end if Return end if if v isa DynaPDFBookmarkMBS then dim o as DynaPDFBookmarkMBS = v List.AddRow "DestType", str(o.DestType) List.AddRow "Title", o.Title List.AddRow "DestPage", str(o.DestPage) List.AddRow "Parent", str(o.Parent) List.AddRow "Style", str(o.Style) dim Actions as DynaPDFObjActionsMBS dim r as integer = pdf.GetObjActions(pdf.kotBookmark, o.Handle, Actions) if r > 0 then List.AddFolder "Bookmark Object Actions", str(r) List.RowTag(List.LastIndex) = actions end if return end if if v isa DynaPDFPageMBS then dim o as DynaPDFPageMBS = v List.AddRow "Page", str(o.Page) List.AddRow "Orientation", str(o.Orientation) dim Actions as DynaPDFObjActionsMBS dim r as integer = pdf.GetObjActions(pdf.kotPage, o.Page, Actions) if r > 0 then List.AddFolder "Page Object Actions", str(r) List.RowTag(List.LastIndex) = actions end if return end if if v isa DynaPDFAnnotationExMBS then dim o as DynaPDFAnnotationExMBS = v List.AddRow "Type", str(o.Type) List.AddRow "Content", o.Content List.AddRow "CreateDate", o.CreateDate List.AddRow "Subject", o.Subject List.AddRow "Subtype", o.Subtype dim Actions as DynaPDFObjActionsMBS dim r as integer = pdf.GetObjActions(pdf.kotAnnotation, o.Handle, Actions) if r > 0 then List.AddFolder "Annotation Object Actions", str(r) List.RowTag(List.LastIndex) = actions end if return end if if v isa DynaPDFFieldExMBS then dim o as DynaPDFFieldExMBS = v List.AddRow "FieldName", o.FieldName List.AddRow "FieldType", str(o.FieldType) List.AddRow "Value", o.Value List.AddRow "ExpValue", o.ExpValue List.AddRow "ToolTip", o.ToolTip List.AddRow "PageNum", str(o.PageNum) dim Actions as DynaPDFObjActionsMBS dim r as integer = pdf.GetObjActions(pdf.kotField, o.Handle, Actions) if r > 0 then List.AddFolder "Field Object Actions", str(r) List.RowTag(List.LastIndex) = actions end if return end if break // unhandled type? End EventHandler
End Control
Function GetActionTypeString(n as integer) As string Select case n case DynaPDFMBS.katURI return "URI" case DynaPDFMBS.katTransition return "Transition" case DynaPDFMBS.katThread return "Thread" case DynaPDFMBS.katSubmit return "Submit" case DynaPDFMBS.katSound return "Sound" case DynaPDFMBS.katSetOCGState return "SetOCGState" case DynaPDFMBS.katRichMediaExec return "RichMediaExec" case DynaPDFMBS.katReset return "Reset" case DynaPDFMBS.katRendition return "Rendition" case DynaPDFMBS.katNamed return "Named" case DynaPDFMBS.katMovie return "Movie" case DynaPDFMBS.katLaunch return "Launch" case DynaPDFMBS.katJavaScript return "JavaScript" case DynaPDFMBS.katImportData return "ImportData" case DynaPDFMBS.katHide return "Hide" case DynaPDFMBS.katGoToR return "GoToR" case DynaPDFMBS.katGoToE return "GoToE" case DynaPDFMBS.katGoTo3DView return "GoTo3DView" case DynaPDFMBS.katGoTo return "GoTo" else return "?" end Select End Function
Sub Run(p as MyDynaPDFMBS) const HideWhenNoActions = true pdf = p dim Actions as DynaPDFObjActionsMBS dim pages as integer = pdf.GetPageCount for i as integer = 1 to pages dim a as DynaPDFPageMBS = pdf.GetPage(i) if (HideWhenNoActions = false) or (pdf.GetObjActions(pdf.kotPage, i, Actions) > 0) then List.AddFolder "Page", str(i) List.RowTag(List.LastIndex) = a end if next dim annots as integer = pdf.GetAnnotCount-1 for i as integer = 0 to annots dim a as DynaPDFAnnotationExMBS = pdf.GetAnnotEx(i) if (HideWhenNoActions = false) or (pdf.GetObjActions(pdf.kotAnnotation, i, Actions) > 0) then List.AddFolder "Annotation", str(i) List.RowTag(List.LastIndex) = a end if next dim fields as integer = pdf.GetFieldCount-1 for i as integer = 0 to fields dim a as DynaPDFFieldExMBS = pdf.GetFieldEx(i) if (HideWhenNoActions = false) or (pdf.GetObjActions(pdf.kotField, i, Actions) > 0) then List.AddFolder "Field", str(i) List.RowTag(List.LastIndex) = a end if next dim bookmarks as integer = pdf.GetBookmarkCount-1 for i as integer = 0 to bookmarks dim a as DynaPDFBookmarkMBS = pdf.GetBookmark(i) if (HideWhenNoActions = false) or (pdf.GetObjActions(pdf.kotBookmark, i, Actions) > 0) then List.AddFolder "Bookmark",str(i) List.RowTag(List.LastIndex) = a end if next dim r as integer = pdf.GetObjActions(pdf.kotCatalog, 0, Actions) if r > 0 then List.AddFolder "Catalog Object Actions", str(r) List.RowTag(List.LastIndex) = actions end if End Sub
Property PDF As MyDynaPDFMBS
End Class
Module UtilModule
Sub AddFolder(extends l as listbox, key as string, value as string) l.AddFolder key l.cell(l.LastIndex, 1) = value End Sub
End Module
End Project

Feedback, Comments & Corrections

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




Links
MBS Xojo Chart Plugins