title: Create a paginated PDF—Mac OS X
body: <p>I am making a Mac app (in Swift 3 using Xcode 8, Beta 5) with which the user can make a long note and export it as a PDF. </p>
  
  <p>To create this PDF, I am using Cocoa's <code>dataWithPDF:</code> method with the following code:</p>
  
  <pre><code>do {
     // define bounds of PDF as the note text view
     let rect: NSRect = self.noteTextView.bounds
     // create the file path for the PDF
     if let dir = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true).first {
          // add the note title to path
          let path = NSURL(fileURLWithPath: dir).appendingPathComponent("ExportedNote.pdf")
          // Create a PDF of the noteTextView and write it to the created filepath
          try self.noteTextView.dataWithPDF(inside: rect).write(to: path!)  
     } else {
          print("Path format incorrect.") // never happens to me
     }
  
  } catch _ {
      print("something went wrong.") // never happens to me
  }
  </code></pre>
  
  <p>This completely works, but there's one problem: the PDF goes only on one page, which means the page gets really long when there's a lot of text in the note. How can I force the PDF to go onto as many letter-size pages as it needs, either while my app is exporting the PDF or right after?</p>