Platforms to show: All Mac Windows Linux Cross-Platform

Back to PDFDocumentMBS class.

PDFDocumentMBS.appendPage(page as PDFPageMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 14.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Appends a page to the document.

PDFDocumentMBS.beginFindString(text as string, options as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Begins a find, searching the document for string.

Search results are handled via a DidFindMatch event in the delegate. Supported options are: NSCaseInsensitiveSearch, NSLiteralSearch, and NSBackwardsSearch.

PDFDocumentMBS.beginFindStrings(texts() as string, options as integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Like beginFindString but it accepts an array of strings to search for.

PDFDocumentMBS.cancelFindString

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Method to cancel a search.

Can be called from a user method being serviced by a find notification.

PDFDocumentMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor to create a new pdf document in memory.
Example
dim doc as new PDFDocumentMBS // new empty document
dim page as new PDFPageMBS // new empty page

doc.Creator="Xojo"
doc.Title="Test file"

doc.insertPage page,0

dim f as FolderItem=SpecialFolder.Desktop.Child("test.pdf")

if doc.write(f) then
f.launch
end if

See also:

PDFDocumentMBS.Constructor(data as memoryblock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor to create a new pdf document based on a string.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim b as BinaryStream = f.OpenAsBinaryFile(false)
dim s as string = b.Read(b.Length)

dim doc as new PDFDocumentMBS(s)

MsgBox doc.Title

See also:

PDFDocumentMBS.Constructor(data as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor to create a new pdf document based on a string.

See also:

PDFDocumentMBS.Constructor(file as folderitem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor to create a new pdf document based on a file.
Example
dim p as PDFDocumentMBS
dim f as FolderItem

f=SpecialFolder.Desktop.Child("test.pdf")
p=new PDFDocumentMBS(f)

MsgBox "Text from first page:"+EndOfLine+EndOfLine+p.pageAtIndex(0).stringValue

See also:

PDFDocumentMBS.Constructor(Handle as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 20.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new object based on a given PDFDocument handle.

Please pass in a non zero handle which points to a PDFDocument object.
For use with declares.

See also:

PDFDocumentMBS.copy as PDFDocumentMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of the document object.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim p as new PDFDocumentMBS(f)

// make a copy
dim c as PDFDocumentMBS = p.copy

// remove second page
c.removePageAtIndex 1

// c has one page less
MsgBox str(p.pageCount)+" "+str(c.pageCount)

For Mac OS X 10.7 and newer this function uses the framework function.
For Mac OS X 10.6 and older this function uses our own copy function to duplicate the document.

PDFDocumentMBS.dataRepresentation(QuartzFilter as Variant = nil) as memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Methods to record the current state of the PDFDocument as data string.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim doc as new PDFDocumentMBS(f)

dim o as FolderItem = SpecialFolder.Desktop.Child("out.pdf")
dim b as BinaryStream = o.CreateBinaryFile("")

b.Write doc.dataRepresentation

Optional for Mac OS X 10.6, you can pass a QuartzFilterMBS object to use that filter here.

Looks like newer macOS versions like 10.14 or later ignore the quartz filter.

PDFDocumentMBS.documentAttributes as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
property PDFKit MBS PDFKit Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
The PDF meta data as a Xojo Dictionary object.

Returns a dictionary with PDF metadata. Metadata is optional for PDF's and so some of the keys may be missing or the entire dictionary may be empty.
(Read and Write computed property)

PDFDocumentMBS.exchangePageAtIndexWithPageAtIndex(indexA as Integer, indexB as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Exchanges the two pages with the given index.

Index is zero based.

PDFDocumentMBS.findString(text as string, options as Integer) as PDFSelectionMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Searches entire document for string and returns an array of PDFSelections representing all instances found.
Example
dim p as PDFDocumentMBS
dim f as FolderItem
dim sa() as PDFSelectionMBS
dim i,c as Integer
dim s as PDFSelectionMBS

const NSCaseInsensitiveSearch=1

f=SpecialFolder.Desktop.Child("test.pdf")
p=new PDFDocumentMBS(f)

if p.pageCount=0 then
MsgBox "Failed to load the PDF."
Return
end if

sa=p.findString("Plugin",NSCaseInsensitiveSearch)

if ubound(sa)<0 then
MsgBox "no item found."
else
MsgBox str(ubound(sa)+1)+" items found."
end if

s=sa(0)
s.extendSelectionAtEnd(50)
s.extendSelectionAtStart(50)

MsgBox s.stringValue // shows a bit more text before and after the location found

May return an empty array if nothing is found.
Returns nil on any error.

Supported options are:
NSCaseInsensitiveSearch, NSLiteralSearch, and NSBackwardsSearch.

PDFDocumentMBS.findStringFromSelection(text as string, selection as PDFSelectionMBS, options as Integer) as PDFSelectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Searches for only the next instance of string beginning after the last character of selection with options (or preceding the first character of the selection if NSBackwardsSearch is specified as a search option).

Returns next instance as a PDFSelection or nil if the end of the document is reached. Supported options are: NSCaseInsensitiveSearch, NSLiteralSearch, and NSBackwardsSearch. Passing in nil for selection will start the search from the beginning of the document (or end if NSBackwardsSearch is specified).

PDFDocumentMBS.indexForPage(page as PDFPageMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Given a PDFPage, returns the pages index within the document.

Indicees are zero-based.

PDFDocumentMBS.insertPage(page as PDFPageMBS, index as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Inserts a page in the pdf on the given index.
Example
dim file1,file2,file3,destfile as FolderItem
dim page1,page2,page3 as PDFPageMBS
dim doc1,doc2 as PDFDocumentMBS
dim img as NSImageMBS
dim doc as PDFDocumentMBS

file1=SpecialFolder.Desktop.Child("test1.pdf")
file2=SpecialFolder.Desktop.Child("test2.pdf")
file3=SpecialFolder.Desktop.Child("logo.jpg")

doc1=new PDFDocumentMBS(file1)
doc2=new PDFDocumentMBS(file2)

MsgBox str(doc1.pageCount)

img=new NSImageMBS(file3)

Backdrop=img.CopyPicture

page1=new PDFPageMBS(img)
page2=doc1.pageAtIndex(0)
page3=doc2.pageAtIndex(0)

doc=new PDFDocumentMBS
doc.insertPage page1,0
doc.insertPage page2,1
doc.insertPage page3,2

destfile=SpecialFolder.Desktop.Child("test.pdf")
call doc.write(destfile)

Index is zero based.

Some examples using this method:

PDFDocumentMBS.Keywords as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Array of Strings containing document keywords.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim doc as new PDFDocumentMBS(f)
MsgBox join(doc.Keywords)

PDFDocumentMBS.outlineItemForSelection(selection as PDFSelectionMBS) as PDFOutlineMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Given a PDFSelection, this method returns the child outline item the selection most closely falls beneath.

Since a selection may span multiple outline items, only the point representing the first character of the PDFSelection is considered. Typically, outline's indicate things like chapters for the PDF. Therefore, this method would help you identify the chapter the selection falls within.

For some PDFs this method returns nil.

PDFDocumentMBS.pageAtIndex(index as Integer) as PDFPageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a PDFPage object representing the page at index.
Example
dim p as PDFDocumentMBS
dim f as FolderItem

f=SpecialFolder.Desktop.Child("test.pdf")
p=new PDFDocumentMBS(f)

MsgBox "Text from first page:"+EndOfLine+EndOfLine+p.pageAtIndex(0).stringValue

Will raise an exception if index is out of bounds. Indicees are zero-based.

Some examples using this method:

PDFDocumentMBS.PrintOperation(PrintInfo as Variant, AutoRotate as boolean = true, scalingMode as Integer = 0) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 14.3 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Creates print operation for PDF document.
Example
// select a PDF
dim f as FolderItem = GetOpenFolderItem("")
if f = nil then Return

// open PDF
dim doc as new PDFDocumentMBS(f)

// define some print setting via PrintInfo
dim PrintInfo as new NSPrintInfoMBS

// start print operation
dim printOperation as NSPrintOperationMBS = doc.PrintOperation(printinfo)

printOperation.showsPrintPanel = true
printOperation.showsProgressPanel = true

call printOperation.runOperation

Returns NSPrintOperationMBS object.

PDFDocumentMBS.removePageAtIndex(index as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes a page in the pdf on the given index.

Index is zero based.

Some examples using this method:

PDFDocumentMBS.selectionForEntireDocument as PDFSelectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a selection representing text for the entire document.

PDFDocumentMBS.selectionFromPage(StartPage as PDFPageMBS, StartCharacterIndex as Integer, EndPage as PDFPageMBS, EndCharacterIndex as Integer) as PDFSelectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a selection representing text from page startPage and point StartCharacterIndex to page endPage and to point EndCharacterIndex on that page.

Start and end page can be the same.

See also:

PDFDocumentMBS.selectionFromPage(StartPage as PDFPageMBS, StartPointX as single, StartPointY as single, EndPage as PDFPageMBS, EndPointX as single, EndPointY as single) as PDFSelectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a selection representing text from page startPage and point startPt to page endPage and to point endPt on that page.

Points are in page-space and relative to their respective pages. Start and end page can be the same (and are then equivalent to calling selectionFromPointToPoint).

See also:

PDFDocumentMBS.SetDelegate(d as PDFDocumentDelegateMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
If a PDFDocument has a delegate, delegate methods may be called for this document.

PDFDocumentMBS.SetKeywords(keywords() as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the array of strings containing document keywords.

PDFDocumentMBS.unlockWithPassword(password as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Unlocks an encrypted PDF with the given password.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim doc as new PDFDocumentMBS(f)

if doc.unlockWithPassword("mypassword") then
MsgBox "OK"
end if

Means of passing in a password to unlock encrypted PDF's. Calling unlockWithPassword will attempt to unlock the PDF. If successful, a DidUnlockDocument event is sent to the delegate. You cannot "re-lock" a PDF by passing in a bogus password. Returns true if the document is now unlocked, false otherwise (isLocked = false).

PDFDocumentMBS.write(file as folderitem, QuartzFilter as Variant = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Methods to record the current state of the PDFDocument as a file.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim doc as new PDFDocumentMBS(f)

// modify here

dim o as FolderItem = SpecialFolder.Desktop.Child("testout.pdf")
call doc.write(o)

Returns true on success and false on failure.

There is a bug known in Mac OS X 10.4 that this function may return true even if the saving failed. So you may prefer to check the file whether it exists after write.

Optional for Mac OS X 10.6, you can pass a QuartzFilterMBS object to use that filter here.

Looks like newer macOS versions like 10.14 or later ignore the quartz filter.

PDFDocumentMBS.writeWithOptions(file as folderitem, options as dictionary) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 19.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Writes PDF to file with options.

Returns true on success and false on failure.

Some keys to use include:
CGPDFContextMBS.kCGPDFContextUserPassword
CGPDFContextMBS.kCGPDFContextTitle
CGPDFContextMBS.kCGPDFContextSubject
CGPDFContextMBS.kCGPDFContextOwnerPassword
CGPDFContextMBS.kCGPDFContextOutputIntents
CGPDFContextMBS.kCGPDFContextOutputIntent
CGPDFContextMBS.kCGPDFContextKeywords
CGPDFContextMBS.kCGPDFContextEncryptionKeyLength
CGPDFContextMBS.kCGPDFContextCreator
CGPDFContextMBS.kCGPDFContextAuthor
CGPDFContextMBS.kCGPDFContextAllowsPrinting
CGPDFContextMBS.kCGPDFContextAllowsCopying

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


The biggest plugin in space...