PDF Annotations#
Annotations#
Annotations includes functionality for drawing, text markup and placing objects on a PDF document.
App Kit provides the following sets:
- Document Drawing
Freehand ink drawing
Line
Rectangle
Ellipse
Polygon
Polyline
- Document Text
Highlight
Underline
Squiggle
Strikethrough
- Document Placement
Note
Textbox
Stamp
Attachment
Link
Note
You should not set annotation modes on a document until the document has loaded, therefore ensure to add any API calls for annotation methods after listening for the document loaded event.
Document Drawing Annotations#
Document text annotations depend on a “Drawing Annotation Mode” being activated. The following API allows for control over setting this mode.
Setting the Drawing Annotation Mode#
This is as simple as setting the annotating mode to a given “Drawing Annotation Mode” type on your MuPDFDKBasicDocumentViewController
instance. To turn off the mode set the annotating mode to MuPDFDKAnnotatingMode_None
.
Drawing mode enumeration#
|
Description |
---|---|
|
Freehand ink |
|
Line |
|
Squares & Rectangles |
|
Circles & Ovals |
|
Polygon |
|
Polyline |
The following code toggles the freehand ink drawing mode on and off and might serve as the handler for one of the buttons in your UI.
if basicDocVc.annotatingMode == MuPDFDKAnnotatingMode_Ink {
basicDocVc.annotatingMode = MuPDFDKAnnotatingMode_None
} else {
basicDocVc.annotatingMode = MuPDFDKAnnotatingMode_Ink
}
if (basicDocVc.annotatingMode == MuPDFDKAnnotatingMode_Ink) {
basicDocVc.annotatingMode = MuPDFDKAnnotatingMode_None;
}
else {
basicDocVc.annotatingMode = MuPDFDKAnnotatingMode_Ink;
}
When a “Drawing Annotation Mode” is disabled, the annotation is saved to the document.
Styling Drawing Annotations#
Drawing annotations can be styled as follows:
Opacity#
To set & get annotation opacity, access the annotationOpacity
value as a Float
.
basicDocVc.annotationOpacity = 1.0
basicDocVc.annotationOpacity = 1.0;
Line Thickness#
To set & get line thickness, access the annotationStrokeThickness
value as a CGFloat
.
basicDocVc.annotationStrokeThickness = 10
basicDocVc.annotationStrokeThickness = 10;
Line Color#
To set & get line color, access the annotationStrokeColor
value as a UIColor
.
basicDocVc.annotationStrokeColor = .green
basicDocVc.annotationStrokeColor = [UIColor green];
Line Endings#
Line endings are only supported for the MuPDFDKAnnotatingMode_Line
annotation. They can be set & get by accessing the annotationLineHeadStyle
& annotationLineTailStyle
properties.
basicDocVc.annotationLineHeadStyle = ARDKLineEndStyle_Circle
basicDocVc.annotationLineTailStyle = ARDKLineEndStyle_ClosedArrow
basicDocVc.annotationLineHeadStyle = ARDKLineEndStyle_Circle;
basicDocVc.annotationLineTailStyle = ARDKLineEndStyle_ClosedArrow;
Line ending enumeration#
|
Description |
---|---|
|
None |
|
Butt |
|
Slash |
|
Cirle |
|
Diamond |
|
Open arrow |
|
Right pointing open arrow |
|
Square |
|
Closed arrow |
|
Right pointing closed arrow |
Document Text Annotations#
Document text annotations depend on a “Text Annotation Mode” being activated. The following API allows for control over setting this mode.
Setting the Text Annotation Mode#
This is as simple as setting the annotating mode to a given “Text Annotation Mode” type on your MuPDFDKBasicDocumentViewController
instance. To turn off the mode set the annotating mode to MuPDFDKAnnotatingMode_None
.
Text mode enumeration#
|
Description |
---|---|
|
Highlight text |
|
Underline text |
|
Squiggle text |
|
Strikethrough text |
When a “Text Annotation Mode” is active, the user can select text and apply the text annotations accordingly.
Document Placement Annotations#
Document text annotations depend on a “Placement Annotation Mode” being activated. The following API allows for control over setting this mode.
Setting the Placement Annotation Mode#
This is as simple as setting the annotating mode to a given “Placement Annotation Mode” type on your MuPDFDKBasicDocumentViewController
instance. To turn off the mode set the annotating mode to MuPDFDKAnnotatingMode_None
.
Placement mode enumeration#
|
Description |
---|---|
|
Note |
|
Free text |
|
Stamp |
|
File attachment |
|
Link |
When a “Placement Annotation Mode” is active, the user can tap on the document to create the placement annotation. In-built UI will then handle the anootation creation and manipulation.
Getting the Annotation Mode#
Access the annotatingMode
variable on your MuPDFDKBasicDocumentViewController
instance to find out the current mode.
let mode:MuPDFDKAnnotatingMode = documentViewController.annotatingMode
MuPDFDKAnnotatingMode mode = self.docViewController.annotatingMode;
De-selecting Annotations#
Essentially all annotations are treated the same as simply selections once they have been selected by a user. This selection can then be cleared (de-selected) by calling the clearSelection()
method against the MuPDFDKDoc
instance within MuPDFDKBasicDocumentViewController
.
let myDoc:MuPDFDKDoc? = basicDocVc?.session.doc as! MuPDFDKDoc
myDoc?.clearSelection()
MuPDFDKDoc *myDoc = (MuPDFDKDoc *)basicDocVc.session.doc;
[myDoc clearSelection];
Without an annotation being currently selected, calling clearSelection()
will have no effect.
Deleting Annotations#
Selections can be removed (deleted) by calling the deleteSelectedAnnotation()
method against the MuPDFDKDoc
instance within MuPDFDKBasicDocumentViewController
.
func deleteDocumentSelection() {
let myDoc:MuPDFDKDoc? = basicDocVc?.session.doc as! MuPDFDKDoc
myDoc?.deleteSelectedAnnotation()
}
-(void)deleteDocumentSelection {
MuPDFDKDoc *myDoc = (MuPDFDKDoc *)basicDocVc.session.doc;
[myDoc deleteSelectedAnnotation];
}
Without an annotation being currently selected, calling deleteSelectedAnnotation()
will have no effect.
Targetting Document Areas#
Sometimes in order to focus an annotation, or to suggest an area to annotate, a developer may wish to highlight areas in a document and/or jump to a specific area of interest in a document. There are two API calls available to assist with this.
Outlining an Area#
To draw outlines on a document page use outlineArea
.
basicDocVc.session.doc.outlineArea(<rect>, onPage: <page>)
[basicDocVc.session.doc outlineArea:<rect> onPage:<page>];
Showing an Area#
To show an area on a document page use showArea
.
basicDocVc.showArea(<rect>, onPage: <page>)
[basicDocVc.showArea:<rect> onPage:<page>];
This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, CA 94129, USA, for further information.