123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import UIKit
- import PDFGenerator
- class SampleTableViewController: UITableViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- self.tableView.contentInset = UIEdgeInsets(top: 100.0, left: 0.0, bottom: 0.0, right: 0.0)
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
-
- @objc fileprivate func generatePDF() {
- do {
- let dst = NSHomeDirectory() + "/sample_tblview.pdf"
- try PDFGenerator.generate(self.tableView, to: dst)
- openPDFViewer(dst)
- } catch let error {
- print(error)
- }
-
- }
- fileprivate func openPDFViewer(_ pdfPath: String) {
- let url = URL(fileURLWithPath: pdfPath)
- let storyboard = UIStoryboard(name: "PDFPreviewVC", bundle: nil)
- let vc = storyboard.instantiateInitialViewController() as! PDFPreviewVC
- vc.setupWithURL(url)
- present(vc, animated: true, completion: nil)
- }
-
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 3
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 10
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SampleTableViewCell
- cell.leftLabel.text = "\((indexPath as NSIndexPath).section)-\((indexPath as NSIndexPath).row)cell"
- cell.rightLabel.text = "sample"
- return cell
- }
-
- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
- return "section\(section)"
- }
-
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- generatePDF()
- }
-
-
-
-
-
-
- }
|