Skip to content

Instantly share code, notes, and snippets.

View saurabhkpatel's full-sized avatar
🎯
Focusing

Saurabh Patel saurabhkpatel

🎯
Focusing
View GitHub Profile
@imrvshah
imrvshah / EditPDF.swift
Created February 16, 2017 19:55
Edit PDF: Create a PDF with only selected pages in Swift 3.0
func createNewPDF() {
let pdfURL = NSURL(fileURLWithPath: self.selectedFile.fileURL); // URL of the existing PDF
if let pdf:CGPDFDocument = CGPDFDocument(pdfURL as CFURL) { // Create a PDF Document
let _newURL = "\(documentFolderPath)/\(self.selectedFile.name)"; // New URL to save editable PDF
let _url = NSURL(fileURLWithPath: _newURL)
var _mediaBox:CGRect = CGRect(x: 0, y: 0, width: pageWidth, height: pageHeight); // mediabox which will set the height and width of page
let _writeContext = CGContext(_url, mediaBox: &_mediaBox, nil) // get the context
//Run a loop to the number of pages you want