Platforms to show: All Mac Windows Linux Cross-Platform

Back to PDFPageMBS class.

PDFPageMBS.addAnnotation(annotation as PDFAnnotationMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Methods allowing annotations to be added.

PDFPageMBS.annotationAtPoint(x as single, y as single) as PDFAnnotationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Hit-testing method returns the annotation at point (or nil if none).

The point is in page-space.

PDFPageMBS.annotations as PDFAnnotationMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an array containing the page's annotations.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim doc as new PDFDocumentMBS(f)
dim page as PDFPageMBS = doc.pageAtIndex(0)
dim annotations(-1) as PDFAnnotationMBS = page.annotations

// show a msgbox with the types of all annotations
dim types(-1) as string

for each a as PDFAnnotationMBS in annotations
types.Append a.type
next

MsgBox Join(types)

The elements of the array will most likely be typed to subclasses of the PDFAnnotation class.

Available in Mac OS X v10.4 and later.

PDFPageMBS.boundsForBox(box as Integer) as NSRectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
property PDFKit MBS PDFKit Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the bounds for the specified PDF display box.

The PDFDisplayBox enumeration defines the various box types.

Note that only the media box is required for a PDF. If you request the bounds for the crop box, but the PDF does not include a crop box, the bounds for the media box are returned instead. If you request the bounds for other box types, and the PDF does not includes these types, the bounds for the crop box are returned instead.

The coordinates for the box are in page space, so you might need to transform the points if the page has a rotation on it. Also, note that the bounds boundsForBox returns are intersected with the page's media box.

boundsForBox throws a range exception if box is not in range.
(Read and Write computed property)

Some examples using this property:

PDFPageMBS.CalcTransformForBox(box as Integer) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 12.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
An utility function to calculate the transform needed to draw into a page.

Returns NSAffineTransformMBS object.

PDFPageMBS.characterBoundsAtIndex(index as Integer) as NSRectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the bounds in page-space of the character at index.

In the unlikely event that more than one character are at the specified point, only the first character encountered is returned.

PDFPageMBS.characterIndexAtPoint(x as single, y as single) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the index of the character at point (in page space).

Returns -1 if no character at point.

PDFPageMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
The constructor to create a custom PDF page.
Example
dim doc as new PDFDocumentMBS
dim page as PDFPageMBS
dim f as FolderItem

page=new MyPDFPageMBS

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

doc.insertPage page,0

f=SpecialFolder.Desktop.Child("test.pdf")

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

You draw the content using drawRect event.

See also:

PDFPageMBS.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 PDFPage handle.

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

See also:

PDFPageMBS.Constructor(image as NSImageMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a PDFPage for the NSImage passed in.

An easy way to create a PDFPage from an image to add to a PDFDocument.

Mac OS X 10.5 only.

See also:

PDFPageMBS.copy as PDFPageMBS

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 page object.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
dim p as new PDFDocumentMBS(f)

// make a new PDF
dim c as new PDFDocumentMBS

// get first page
dim page as PDFPageMBS = p.pageAtIndex(0)

// add copy of page to new pdf
c.insertPage page.copy, 0

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

PDFPageMBS.Destructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 15.0 ✅ Yes ❌ No ❌ No ✅ Yes All
The destructor.

PDFPageMBS.Draw(g as NSGraphicsMBS, box as Integer = 0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 12.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Draws PDF page into graphics environment.

Use kPDFDisplay*Box constants for box parameter.

PDFPageMBS.drawWithBox(box as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 9.6 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Draws the page within the specified box.

This method takes into account the page rotation and draws clipped to the specified box. If the page is set to display annotations, this method also draws them. This method does not clear the background. To clear the background before drawing, use NSRectFill with NSColor set (typically) to white.

PDFPageMBS.removeAnnotation(annotation as PDFAnnotationMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Methods allowing annotations to be removed.

PDFPageMBS.Render(dpi as Double = 72.0, box as Integer = 0, background as NSColorMBS = nil) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 10.3 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Renders a PDF Page into an image.
Example
dim f as FolderItem = GetFolderItem("Castles.pdf")
dim doc as new PDFDocumentMBS(f)
dim page as PDFPageMBS = doc.pageAtIndex(0)
dim image as NSImageMBS = page.Render

Backdrop = image.CopyPicture

dpi: The resolution you want to have on the image. Default 72.0. To get a scaled image with factor x, pass 72.0*x.
box: The display box. Use one of the kPDFDisplayBox* constants.
background: optional NSColorMBS object to fill the background before drawing the PDF. This will affect only PDFs with transparent background.

Returns nil on any error.

Version 11.1pr8 adds code here to handle rotation better.
Due to bugs in Apple’s PDFKit you may see memory leaks with JPEG data from PDF pages (seen in macOS 10.12).

PDFPageMBS.selectionForLineAtPoint(left as single, top 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
Given a point in page-space, returns a selection representing a whole line at that point.

May return nil if no character (and by extension no line) under point.

PDFPageMBS.selectionForRange(position as Integer, length 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
Given a range, returns a selection representing text within that range.
Example
dim MyPDFView as PDFViewMBS // your view

dim doc as PDFDocumentMBS = MyPDFView.document
dim page as PDFPageMBS = doc.pageAtIndex(0)
dim sel as PDFSelectionMBS = page.selectionForRange(0,5)
MyPDFView.currentSelection = sel

Will raise an exception if the range length is zero or if the range is outside the range of the characters on the page.

PDFPageMBS.selectionForRect(left as single, top as single, width as single, height 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
Given a rect in page-space, returns a selection representing enclosed text on page.

PDFPageMBS.selectionForWordAtPoint(left as single, top 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
Given a point in page-space, returns a selection representing a whole word at that point.

May return nil if no character (and by extension no word) under point.

PDFPageMBS.selectionFromPointToPoint(startleft as single, starttop as single, endleft as single, endtop 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 between startPt and endPt.

Point are sorted first top to bottom, left to right.

PDFPageMBS.thumbnailOfSize(size as NSSizeMBS, box as integer) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Convenience function that returns an image of this page, with annotations, that fits the given size.

Note that the produced image is "size to fit": it retains the original page aspect-ratio. The size you give may not match the size of the returned image, but the returned image is guaranteed to be equal or less.

Available in macOS 10.13 or newer.

PDFPageMBS.transformContextForBox(box as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 8.0 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Given a display box, will transform the current context to take into account the rotation of the page as well as the origin of the box with repect to the page's base coordinates system.

This is a convenient method to call from within drawPage or from within the draw method a PDFAnnotation subclass.

Mac OS X 10.5 only.

Some examples using this method:

PDFPageMBS.transformForBox(box as integer) as variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PDFKit MBS PDFKit Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
This transform correctly rotates and offsets based on the given page's rotation property and the display box type.

Available in macOS 10.13 or newer.

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


The biggest plugin in space...