Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/Search and show PDF files
Required plugins for this example: MBS DynaPDF Plugin, MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Raster/Search and show PDF files
This example is the version from Sun, 21th Oct 2017.
Project "Search and show PDF files.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if TargetMachO then // ok else MsgBox "This example works only on Mac OS X as we use Spotlight to find PDF files." quit end if End EventHandler
End Class
Class MainWindow Inherits Window
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if pageCount<=PageIndex then // load next if UBound(files)<0 then Return dim n as integer = (UBound(files)+1)*rnd file = files(n) files.Remove n // close last pdf call pdf.CloseImportFile call pdf.FreePDF // clear memory, but keep object System.DebugLog "Load "+file.AbsolutePath // create new one call pdf.CreateNewPDF(nil) call pdf.SetImportFlags(pdf.kifImportAsPage) call pdf.OpenImportFile(file, 0, "") PageCount = pdf.GetPageCount PageIndex = 0 end if // show all pages 'PageIndex = PageIndex + 1 // show one random page PageIndex = random.InRange(1, pageCount) pageCount = 0 // trigger load of next PDF on the next run // import only the page we need call pdf.Append call pdf.ImportPageEx(PageIndex, 1.0, 1.0) call pdf.EndPage // render page as picture dim t as integer = ticks dim pic as Picture = pdf.RenderPagePicture(pdf.GetPageCount) // new imported page is the newest page t = ticks - t if t>10 then System.DebugLog str(t)+" ticks for "+file.AbsolutePath end if if pic = nil then System.DebugLog "no picture for "+file.AbsolutePath else dim x as integer = (Width - pic.Width)*rnd dim y as integer = (Height - pic.Height)*rnd Graphics.DrawPicture pic, x, y end if End EventHandler
End Control
EventHandler Sub Close() if q<>nil then // need MacOSX Plugin for MDQuery. q.stop q=nil end if End EventHandler
EventHandler Sub Open() Random = new Random pdf = new MyDynaPDFMBS // Needs MBS MacOSX Plugin q=new MyQuery("kMDItemContentType=""com.adobe.pdf""") if q.Handle=0 then MsgBox "Failed to create query" else if q.Execute(q.kMDQueryWantsUpdates) then 'ok else MsgBox "Failed to run query" end if end if self.Maximize End EventHandler
Sub Add(path as string) if path = "" then Return dim file as FolderItem = GetFolderItem(Path, folderitem.PathTypeShell) files.Append file Title = str(UBound(files)+1)+" PDF files" Exception e End Sub
Property PageIndex As Integer
Property file As FolderItem
Property files() As FolderItem
Property pageCount As Integer
Property pdf As MyDynaPDFMBS
Property q As MyQuery
Property random As Random
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
Class MyQuery Inherits MDQueryMBS
EventHandler Sub Progress(AddedItems() as MDItemMBS, ChangedItems() as MDItemMBS, RemovedItems() as MDItemMBS) for each it as MDItemMBS in AddedItems MainWindow.Add it.path next End EventHandler
EventHandler Sub Update(AddedItems() as MDItemMBS, ChangedItems() as MDItemMBS, RemovedItems() as MDItemMBS) for each it as MDItemMBS in AddedItems MainWindow.Add it.path next End EventHandler
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 Return 0 // ignore End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project

Feedback, Comments & Corrections

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

MBS FileMaker blog