PDFDrawingView is a lightweight PDF Viewer that has built in functionality for drawing.
- Create a PDF Document using PDFKit.
- Import using CocoaPods or download from here.
- For CocoaPods, here is an example PodFile
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
source "https://github.com/jrosen081/PDFDrawingView.git"
target 'YOUR_TARGET_ID' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for drawSecure
pod 'DrawingPDF'
end
- Use the constructor method.
letpdfDrawer=PDFDrawingView(frame: backgroundView.bounds, document: documentPDF, style:.vertical, delegate:self) //Creates an instance of the view with the PDF being displayed verticallyIt is that simple.
A sample project is included to show how to use the PDFDrawingView.
- Normal Drawing
- Highlighting
- Erasing
- Adding text boxes and being able to move and resize them.
- Moving different lines and zooming with the lasso tool.
- Apple Pencil compatible, with force changing the lines being drawn
- The PDF can be displayed either vertically or horizontally.
- Making a new PDF with the drawing on it.
- There is a struct which has all of the options.
publicstructDrawingKeys{publicstaticletdraw="draw"publicstaticletscroll="scroll"publicstaticlethighlight="highlight"publicstaticlettext="text"publicstaticleterase="erase"publicstaticletlasso="lasso"}- Here is how to tell the view what to do
pdfDrawer.drawingKey =PDFDrawingView.DrawingKeys.draw //Will have the view draw- To change the color of drawing and highlighting, do the following:
pdfDrawer.drawingColor =UIColor.red //Changes the drawing color to red
pdfDrawer.highlightColor =UIColor.yellow //Changes the highlight color to yellow- There is an enum that has the options
publicenumDrawingStyle{case vertical
case horizontal
}- Pass in the style into the constructor.
- It displays the PDF vertically by default if you do not give it a value
- There is a method in PDFDrawingView that will return the data for the PDF
letpdfData=self.pdfDrawer.createPDF()- If you then want to save it locally, use the built-in method for PDFDocuments
letupdatedDocument=PDFDocument(data: pdfData)
updatedDocument?.write(to:"SAMPLE_PATH")- The page has changed
- The view was created
extensionDrawViewController:PDFDelegate{func scrolled(to page:Int){self.currentPageNumber = page
}func viewWasCreated(){doSomething()}}