Skip to content

ClassicalDude/pdfView-Freedraw

Repository files navigation

pdfView Freedraw - Free Draw for iOS and iPadOS PDFKit

PDFFreedrawGestureRecognizer is a subclass of UIGestureRecognizer. It allows you to use a pen, a highlighter and an eraser on a PDFView page. It optimizes performance by using a CAShapeLayer for drawing the annotation on screen, and applies an ink-type PDFAnnotation to the page only when touchesEnded is called.

The class includes an undo manager and an eraser that can be used on all types of PDF annotations - including ones not created by the class.

Special features include the ability to snap roughly-drawn ovals into perfect ovals, and a precise eraser for ink-type annotations (rather than just erasing the whole annotation in one go). Please note that non ink-type annotations (stamps, widgets, etc.) are deleted as wholes.

Requirements

  • OS: The demo app can run on iOS or iPadOS 11 or higher. The xcframework can also be used on macOS through catalyst.
  • PDF document loaded through PDFKit.

Installation

  • You can explore the functionality by downloading the entire project and testing the app.
  • An xcframework is available at the release page. It is compiled for physical devices, simulator and catalyst.
  • A swift package of the compiled xcframework is available. To add the package to your project, use the address https://github.com/ClassicalDude/pdfView-Freedraw and enter the branch SPM.
  • Using the source code in your project is possible, but can prove tricky because of dependencies, which are pre-compiled into the xcframework. Please refer to this guide if you wish to include the source code in your project.

When manually embedding the xcframework in your project, you must go the General tab of the target's settings and add it to the Frameworks, Libraries and Embedded Content section. Make sure you choose to embed and sign it:

After that you can add import PDFFreedraw to the relevant class in your project.

Usage

Please consult the ViewController.swift file, which documents all of the options and best practices. If you plan to use this framework with SwiftUI, you can consult the comment here.

Credit

The precise eraser for ink-type annotations is made possible by using the ClippingBezier library from Adam Wulf.