Image Picker


PSPDFKit uses PSPDFImagePickerController, which is a subclass of UIImage​Picker​Controller, to select an image from your device to use. This can either be an image from the photo library or use the camera to take a new picture. PSPDFImagePickerController is currently used when adding an image annotation to the document by tapping the image annotation button in the annotation toolbar, and when adding a new page in the document editor by selecting the image option for the page background.

Image Editor

The image picker also includes an image editor, which is automatically shown after an image has been selected. The image editor allows you to zoom, crop, and rotate an image, allowing you to only use a specific part of an image. Showing the image editor can be restricted, to use the selected image as is, by disabling shouldShowImageEditor.

Image Editor

Image Quality

When adding an image annotation, and select an image with a large size, you will be presented with options to select the image size. This can be customized using allowedImageQualities.

Delegate

To get notified of image selections or when editing finished, you can implement PSPDFImagePickerControllerDelegate and set imageDelegate. This can be done by using a subclass of PSPDFImagePickerController, so that this is used for all presentations of PSPDFImagePickerController without having to set imageDelegate again.

Copy
1
2
3
4
5
6
7
8
9
10
class ImagePickerController: PSPDFImagePickerController, PSPDFImagePickerControllerDelegate {
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        imageDelegate = self
    }

    func imagePickerController(_ picker: PSPDFImagePickerController, didFinishWith image: UIImage, andInfo info: [String : Any]) {
        // Do something
    }
}
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@interface PSCImagePickerController : PSPDFImagePickerController <PSPDFImagePickerControllerDelegate> @end

@implementation PSCImagePickerController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        self.imageDelegate = self;
    }
    return self;
}

- (void)imagePickerController:(PSPDFImagePickerController *)picker didFinishWithImage:(UIImage *)image andInfo:(NSDictionary<NSString *, id> *)info {
    // Do something
}

@end

And don't forget to override the class with your own subclass:

Copy
1
2
3
let configuration = PSPDFConfiguration { builder in
    builder.overrideClass(PSPDFImagePickerController.self, with: ImagePickerController.self)
}
Copy
1
2
3
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder: ^(PSPDFConfigurationBuilder *builder) {
    [builder overrideClass:PSPDFImagePickerController.class withClass:PSCImagePickerController.class];
}];
Was this page helpful? We're happy to answer any questions.