Example: /PDFKit/Search and Highlight/Search and Highlight

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/PDFKit/Search and Highlight/Search and Highlight


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /PDFKit/Search and Highlight/Search and Highlight

This example is the version from Thu, 6th Apr 2016.

Project "Search and Highlight.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "削除"
Const kFileQuit = "終了"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim i,c as integer dim f as FolderItem = FindFile("test.pdf") if not f.Exists then MsgBox "Please put test.pdf on desktop." quit end if dim p as new PDFDocumentMBS(f) if p.pageCount=0 then MsgBox "Failed to load the PDF." quit end if const NSCaseInsensitiveSearch=1 dim options as integer = NSCaseInsensitiveSearch dim sa() as PDFSelectionMBS = p.findString("Plugin", options) if ubound(sa) < 0 then MsgBox "no item found." else MsgBox str(ubound(sa)+1)+" items found." end if // take first selection dim s as PDFSelectionMBS = sa(0) // extend to whole words s.extendSelectionAtEnd(0) s.extendSelectionAtStart(0) // get text? dim t as string= s.stringValue // what page is that? Dim pages() As PDFPageMBS = s.pages() dim page as PDFPageMBS = pages(0) // Rectangle on page? dim bounds as NSRectMBS = s.boundsForPage(page) MsgBox t + " at position "+Format(bounds.X,"0.00")+"/"+Format(bounds.Y,"0.00")+" with size "+Format(bounds.Width,"0.00")+"/"+Format(bounds.Height,"0.00") // make annotation for that recatnlge dim annotation As new PDFAnnotationMarkupMBS(bounds.X,bounds.Y,bounds.Width,bounds.Height) annotation.markupType = PDFAnnotationMarkupMBS.kPDFMarkupTypeHighlight annotation.userName= "" annotation.colorValue = NSColorMBS.magentaColor.colorWithAlphaComponent(0.5) // add annotation to the page page.addAnnotation(annotation) // and save dim destfile as FolderItem= SpecialFolder.Desktop.Child("sample.pdf") //file saved if p.write(destfile) then destfile.Launch else MsgBox "Failed to write PDF file." end if quit 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
MenuBar MainMenuBar
MenuItem FileMenu = "ファイル"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "編集"
MenuItem EditUndo = "取り消す"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "カット"
MenuItem EditCopy = "コピー"
MenuItem EditPaste = "貼り付け"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "すべてを選択"
End MenuBar
End Project

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


💬 Ask a question or report a problem