6.7 to 6.8 Tools framework migration

6.8 introduces a number of improvements in the Tools.framework. The nature of these improvements are such that both PDFNet.framework and Tools.framework must be updated simultaneously. Additionally, some minor code changes in your app may be required.

Sections 1 and 2 apply if your app implements any of the delegate methods listed in the first table, with section 2 applying only if you are using Swift.

Section 3 applies if you have customized the tools source code. As always, we recommend using a diff tool (such as FileMerge) to merge your customizations into the new version.

If you have any questions or comments, please do not hesitate to contact support.

1. Tools.framework protocol changes

In order to reduce coupling and better communicate the relationships between objects, the tools protocols have been renamed and reorganized, as explained below. If you are using a customized version of the tools framework, it will need to be updated to reflect these changes, explained below.

Previously, the protocols used by Tools.framework were declared in PDFNet.framework's PTPDFViewCtrl.h. In 6.8, PDFNet.framework only declares a single tool-related protocol, PTTool, which has been simplified to include only events emitted PTPDFViewCtrl, with all other methods moved into PTToolSwitching. The other protocols that were previously declared in PTPDFViewCtrl.h have been moved into Tools.framework.

Additionally, all protocol methods have been updated to include the sending object as the first parameter when this was not already the case.

Table of protocol reorganization:

6.7 Name

6.7 Location

6.8 Name

6.8 Location

PTToolCommon

PDFViewCtrl.h

PTTool

PDFViewCtrl.h

PTTool

PDFViewCtrl.h

PTToolSwitching

ToolManager.h

PTPDFViewCtrlToolManager

PDFViewCtrl.h

PTToolManager

ToolManager.h

ToolManagerDelegate

ToolManager.h

ToolManagerDelegate

ToolManager.h

Please see the tools protocols guide for a description of each of the protocols in 6.8.

2. Swift support in Tools.framework

The Tools.framework in 6.8 is now annotated with nullability annotations for use from Swift. Parameter and return types explicitly indicate whether the value is permitted to be nil.

Previously, parameter and return types from Tools were imported by Swift as implicitly unwrapped optionals. Implicitly unwrapped optionals are safe to use when the value is non-null but can trigger a runtime error if accessed with a value of nil.

For the majority of methods in the 6.8 version of Tools.framework the parameters and return types are non-null. Updating your project to use the new method signatures involves replacing implicitly unwrapped optionals with optionals or non-optional types. No change is required for Objective-C code.

Example

For 6.7 and before, an implementation of the AnnotationToolbarDelegate protocol in a view controller may have been:

sh

1extension ViewController : AnnotationToolbarDelegate {
2
3 // Implicitly unwrapped optional method parameter.
4 func annotationToolbarDidCancel(_ annotationToolbar: AnnotationToolbar!) {
5 if annotationToolbar != nil {
6 // annotationToolbar contains a value.
7 }
8
9 let tool: PanTool! = PanTool(pdfViewCtrl: self.pdfViewCtrl)
10 if tool != nil {
11 // tool contains a value.
12 }
13 }
14
15}

With 6.8 the code can be simplified:

sh

1extension ViewController : AnnotationToolbarDelegate {
2
3 // Non-optional method parameter.
4 func annotationToolbarDidCancel(_ annotationToolbar: AnnotationToolbar) {
5 // annotationToolbar contains a value.
6
7 let tool = PanTool(pdfViewCtrl: self.pdfViewCtrl)
8 // tool contains a value.
9 }
10
11}

Updating to the 6.8 version of Tools.framework yields shorter and safer Swift code.

Resources

Nullability and Optionals

3. Tools.framework properties and view attachment

In 6.7 and earlier, the tools made use of many ivars. In 6.8 these ivars have, where appropriate, been turned into properties. For example 6.7's m_pdfViewCtrl is now self.pdfViewCtrl in 6.8.

In 6.7 and earlier, tools attached views to the PTPDFViewCtrl ivar ContainerView, e.g.:

sh

1[m_pdfViewCtrl->ContainerView addSubview:selectionRectContainerView];```
2
3In 6.8, `PTPDViewCtrl` has a new overlay view property, `toolOverlayView`, which should now be used instead, e.g.:

[self.pdfViewCtrl.toolOverlayView addSubview:self.selectionRectContainerView];```

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales