diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift
index b39b99b..cecdade 100644
--- a/Demo/AppDelegate.swift
+++ b/Demo/AppDelegate.swift
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
diff --git a/Demo/Base.lproj/Main.storyboard b/Demo/Base.lproj/Main.storyboard
deleted file mode 100644
index 315d749..0000000
--- a/Demo/Base.lproj/Main.storyboard
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demo/PDFOutputViewController.swift b/Demo/Controllers/PDFOutputViewController.swift
similarity index 54%
rename from Demo/PDFOutputViewController.swift
rename to Demo/Controllers/PDFOutputViewController.swift
index f592cb5..bf1f82a 100644
--- a/Demo/PDFOutputViewController.swift
+++ b/Demo/Controllers/PDFOutputViewController.swift
@@ -22,29 +22,21 @@ class PDFOutputViewController: UIViewController {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
-
+
@IBAction func render(_: UIButton) {
let dst = NSHomeDirectory() + "/test.pdf"
try! PDFGenerator.generate(self.scrollView, to: dst)
openPDFViewer(dst)
}
-
+
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)
+ self.performSegue(withIdentifier: "PreviewVC", sender: pdfPath)
}
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+ if let pdfPreviewVC = segue.destination as? PDFPreviewVC, let pdfPath = sender as? String {
+ let url = URL(fileURLWithPath: pdfPath)
+ pdfPreviewVC.setupWithURL(url)
+ }
}
- */
-
}
diff --git a/Demo/PDFPreviewVC.swift b/Demo/Controllers/PDFPreviewVC.swift
similarity index 73%
rename from Demo/PDFPreviewVC.swift
rename to Demo/Controllers/PDFPreviewVC.swift
index b91e651..4674b86 100644
--- a/Demo/PDFPreviewVC.swift
+++ b/Demo/Controllers/PDFPreviewVC.swift
@@ -7,10 +7,11 @@
//
import UIKit
+import WebKit
class PDFPreviewVC: UIViewController {
-
- @IBOutlet fileprivate weak var webView: UIWebView!
+
+ @IBOutlet fileprivate weak var webView: WKWebView!
var url: URL!
override func viewDidLoad() {
super.viewDidLoad()
@@ -18,20 +19,19 @@ class PDFPreviewVC: UIViewController {
req.timeoutInterval = 60.0
req.cachePolicy = .reloadIgnoringLocalAndRemoteCacheData
- webView.scalesPageToFit = true
- webView.loadRequest(req as URLRequest)
+ // webView.scalesPageToFit = true
+ webView.load(req as URLRequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
-
- @objc @IBAction fileprivate func close(_ sender: AnyObject!) {
+
+ @IBAction fileprivate func close(_ sender: AnyObject!) {
dismiss(animated: true, completion: nil)
}
-
+
func setupWithURL(_ url: URL) {
self.url = url
}
-
}
diff --git a/Demo/Controllers/SampleTableViewController.swift b/Demo/Controllers/SampleTableViewController.swift
new file mode 100644
index 0000000..2cfbd7d
--- /dev/null
+++ b/Demo/Controllers/SampleTableViewController.swift
@@ -0,0 +1,59 @@
+//
+// SampleTableViewController.swift
+// PDFGenerator
+//
+// Created by Suguru Kishimoto on 2016/02/27.
+//
+//
+
+import UIKit
+import PDFGenerator
+
+class SampleTableViewController: UITableViewController {
+ @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) {
+ self.performSegue(withIdentifier: "PreviewVC", sender: pdfPath)
+ }
+
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+ if let pdfPreviewVC = segue.destination as? PDFPreviewVC, let pdfPath = sender as? String {
+ let url = URL(fileURLWithPath: pdfPath)
+ pdfPreviewVC.setupWithURL(url)
+ }
+ }
+
+ // MARK: - Table view data source
+
+ 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()
+ }
+}
diff --git a/Demo/ViewController.swift b/Demo/Controllers/ViewController.swift
similarity index 65%
rename from Demo/ViewController.swift
rename to Demo/Controllers/ViewController.swift
index f605bfb..3c36053 100644
--- a/Demo/ViewController.swift
+++ b/Demo/Controllers/ViewController.swift
@@ -10,28 +10,18 @@ import UIKit
import PDFGenerator
class ViewController: UIViewController {
-
- fileprivate var outputAsData: Bool = false
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
+ fileprivate var outputAsData: Bool = false
fileprivate func getImagePath(_ number: Int) -> String {
return Bundle.main.path(forResource: "sample_\(number)", ofType: "jpg")!
}
-
+
fileprivate func getDestinationPath(_ number: Int) -> String {
return NSHomeDirectory() + "/sample\(number).pdf"
}
-
- @objc @IBAction fileprivate func generateSamplePDFFromViews(_ sender: AnyObject?) {
+
+ @IBAction fileprivate func generateSamplePDFFromViews(_ sender: AnyObject?) {
let v1 = UIScrollView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
let v2 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
let v3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
@@ -39,7 +29,7 @@ class ViewController: UIViewController {
v1.contentSize = CGSize(width: 100, height: 100)
v2.backgroundColor = UIColor.green
v3.backgroundColor = UIColor.blue
-
+
do {
let dst = getDestinationPath(1)
if outputAsData {
@@ -53,8 +43,8 @@ class ViewController: UIViewController {
print(e)
}
}
-
- @objc @IBAction fileprivate func generateSamplePDFFromImages(_ sender: AnyObject?) {
+
+ @IBAction fileprivate func generateSamplePDFFromImages(_ sender: AnyObject?) {
let dst = getDestinationPath(2)
autoreleasepool {
do {
@@ -74,8 +64,8 @@ class ViewController: UIViewController {
}
}
}
-
- @objc @IBAction fileprivate func generateSamplePDFFromImagePaths(_ sender: AnyObject?) {
+
+ @IBAction fileprivate func generateSamplePDFFromImagePaths(_ sender: AnyObject?) {
do {
let dst = getDestinationPath(3)
var imagePaths = [String]()
@@ -93,13 +83,13 @@ class ViewController: UIViewController {
print(e)
}
}
-
- @objc @IBAction fileprivate func generateSamplePDFFromPages(_ sender: AnyObject?) {
+
+ @IBAction fileprivate func generateSamplePDFFromPages(_ sender: AnyObject?) {
let v1 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
v1.backgroundColor = UIColor.red
let v2 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
v2.backgroundColor = UIColor.green
-
+
let page1 = PDFPage.view(v1)
let page2 = PDFPage.view(v2)
let page3 = PDFPage.whitePage(CGSize(width: 200, height: 100))
@@ -117,35 +107,17 @@ class ViewController: UIViewController {
openPDFViewer(dst)
} catch let e {
print(e)
-
}
}
-
- @objc @IBAction fileprivate func generatePDFFromStackedScrollView(_: AnyObject?) {
- let storyboard = UIStoryboard(name: "PDFOutput", bundle: nil)
- let vc = storyboard.instantiateInitialViewController()!
-
- present(vc, animated: true, completion: nil)
- }
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)
+ self.performSegue(withIdentifier: "PreviewVC", sender: pdfPath)
}
- @objc @IBAction fileprivate func goSampleTableView(_ sender: AnyObject?) {
- let storyboard = UIStoryboard(name: "SampleTableViewController", bundle: nil)
- let vc = storyboard.instantiateInitialViewController() as! SampleTableViewController
- present(vc, animated: true, completion: nil)
- }
-
- @objc @IBAction fileprivate func goSampleWebView(_ sender: AnyObject?) {
- let storyboard = UIStoryboard(name: "WebViewController", bundle: nil)
- let vc = storyboard.instantiateInitialViewController() as! WebViewController
- present(vc, animated: true, completion: nil)
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+ if let pdfPreviewVC = segue.destination as? PDFPreviewVC, let pdfPath = sender as? String {
+ let url = URL(fileURLWithPath: pdfPath)
+ pdfPreviewVC.setupWithURL(url)
+ }
}
-
}
diff --git a/Demo/Controllers/WebViewController.swift b/Demo/Controllers/WebViewController.swift
new file mode 100644
index 0000000..c1ac626
--- /dev/null
+++ b/Demo/Controllers/WebViewController.swift
@@ -0,0 +1,44 @@
+//
+// WebViewController.swift
+// PDFGenerator
+//
+// Created by Suguru Kishimoto on 2016/03/23.
+//
+//
+
+import UIKit
+import WebKit
+import PDFGenerator
+
+class WebViewController: UIViewController {
+
+ @IBOutlet fileprivate weak var webView: WKWebView!
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+ let req = NSMutableURLRequest(url: URL(string: "http://www.yahoo.co.jp")!, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 60)
+ webView.load(req as URLRequest)
+ }
+
+ @IBAction func generatePDF() {
+ do {
+ let dst = NSHomeDirectory() + "/sample_tblview.pdf"
+ try PDFGenerator.generate(webView, to: dst)
+ openPDFViewer(dst)
+ } catch let error {
+ print(error)
+ }
+
+ }
+
+ fileprivate func openPDFViewer(_ pdfPath: String) {
+ self.performSegue(withIdentifier: "PreviewVC", sender: pdfPath)
+ }
+
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+ if let pdfPreviewVC = segue.destination as? PDFPreviewVC, let pdfPath = sender as? String {
+ let url = URL(fileURLWithPath: pdfPath)
+ pdfPreviewVC.setupWithURL(url)
+ }
+ }
+}
diff --git a/Demo/PDFOutput.storyboard b/Demo/PDFOutput.storyboard
deleted file mode 100644
index 21bd276..0000000
--- a/Demo/PDFOutput.storyboard
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demo/PDFPreviewVC.storyboard b/Demo/PDFPreviewVC.storyboard
deleted file mode 100644
index 855bc67..0000000
--- a/Demo/PDFPreviewVC.storyboard
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demo/SampleTableViewController.storyboard b/Demo/SampleTableViewController.storyboard
deleted file mode 100644
index 013c3c2..0000000
--- a/Demo/SampleTableViewController.storyboard
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demo/SampleTableViewController.swift b/Demo/SampleTableViewController.swift
deleted file mode 100644
index 57127d7..0000000
--- a/Demo/SampleTableViewController.swift
+++ /dev/null
@@ -1,112 +0,0 @@
-//
-// SampleTableViewController.swift
-// PDFGenerator
-//
-// Created by Suguru Kishimoto on 2016/02/27.
-//
-//
-
-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)
- }
-
- // MARK: - Table view data source
-
- 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()
- }
-
- /*
- // Override to support conditional editing of the table view.
- override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
- // Return false if you do not want the specified item to be editable.
- return true
- }
- */
-
- /*
- // Override to support editing the table view.
- override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
- if editingStyle == .Delete {
- // Delete the row from the data source
- tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
- } else if editingStyle == .Insert {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- */
-
- /*
- // Override to support rearranging the table view.
- override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
-
- }
- */
-
- /*
- // Override to support conditional rearranging of the table view.
- override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
- // Return false if you do not want the item to be re-orderable.
- return true
- }
- */
-
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
-
-}
diff --git a/Demo/Base.lproj/LaunchScreen.storyboard b/Demo/Views/Base.lproj/LaunchScreen.storyboard
similarity index 63%
rename from Demo/Base.lproj/LaunchScreen.storyboard
rename to Demo/Views/Base.lproj/LaunchScreen.storyboard
index 2e721e1..4cb718c 100644
--- a/Demo/Base.lproj/LaunchScreen.storyboard
+++ b/Demo/Views/Base.lproj/LaunchScreen.storyboard
@@ -1,7 +1,10 @@
-
-
+
+
+
-
+
+
+
@@ -13,10 +16,9 @@
-
+
-
-
+
diff --git a/Demo/Views/Base.lproj/Main.storyboard b/Demo/Views/Base.lproj/Main.storyboard
new file mode 100644
index 0000000..147ec64
--- /dev/null
+++ b/Demo/Views/Base.lproj/Main.storyboard
@@ -0,0 +1,400 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Demo/SampleTableViewCell.swift b/Demo/Views/SampleTableViewCell.swift
similarity index 100%
rename from Demo/SampleTableViewCell.swift
rename to Demo/Views/SampleTableViewCell.swift
diff --git a/Demo/WebViewController.storyboard b/Demo/WebViewController.storyboard
deleted file mode 100644
index 62d0c60..0000000
--- a/Demo/WebViewController.storyboard
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demo/WebViewController.swift b/Demo/WebViewController.swift
deleted file mode 100644
index 45f89e8..0000000
--- a/Demo/WebViewController.swift
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-// WebViewController.swift
-// PDFGenerator
-//
-// Created by Suguru Kishimoto on 2016/03/23.
-//
-//
-
-import UIKit
-import WebKit
-import PDFGenerator
-
-class WebViewController: UIViewController {
-
- @IBOutlet fileprivate weak var webView: UIWebView!
-
- override func viewDidLoad() {
- super.viewDidLoad()
- let req = NSMutableURLRequest(url: URL(string: "http://www.yahoo.co.jp")!, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 60)
- webView.loadRequest(req as URLRequest)
- }
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
-
- @IBAction func generatePDF() {
- do {
- let dst = NSHomeDirectory() + "/sample_tblview.pdf"
- try PDFGenerator.generate(webView, 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)
- }
-
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
-
-}
diff --git a/PDFGenerator.podspec b/PDFGenerator.podspec
index ea8c3ae..039cbad 100644
--- a/PDFGenerator.podspec
+++ b/PDFGenerator.podspec
@@ -1,14 +1,16 @@
+# frozen_string_literal: true
+
Pod::Spec.new do |s|
- s.name = "PDFGenerator"
- s.version = "3.0.0"
- s.summary = "A simple PDF generator."
- s.homepage = "https://github.com/sgr-ksmt/PDFGenerator"
+ s.name = 'PDFGenerator'
+ s.version = '3.1.0'
+ s.summary = 'A simple PDF generator.'
+ s.homepage = 'https://github.com/sgr-ksmt/PDFGenerator'
# s.screenshots = ""
s.license = 'MIT'
- s.author = { "Suguru Kishimoto" => "melodydance.k.s@gmail.com" }
- s.source = { :git => "https://github.com/sgr-ksmt/PDFGenerator.git", :tag => s.version.to_s }
+ s.author = { 'Suguru Kishimoto' => 'melodydance.k.s@gmail.com' }
+ s.source = { git: 'https://github.com/sgr-ksmt/PDFGenerator.git', tag: s.version.to_s }
s.platform = :ios, '8.0'
- s.swift_version = '4.2'
- s.source_files = "PDFGenerator/**/*.{swift,h}"
- s.frameworks = 'WebKit'
+ s.swift_version = '4.2'
+ s.source_files = 'PDFGenerator/**/*.{swift,h}'
+ s.frameworks = 'WebKit'
end
diff --git a/PDFGenerator.xcodeproj/project.pbxproj b/PDFGenerator.xcodeproj/project.pbxproj
index 63e7a63..a666570 100644
--- a/PDFGenerator.xcodeproj/project.pbxproj
+++ b/PDFGenerator.xcodeproj/project.pbxproj
@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
4D2EB59B1C6A47CD007A87E7 /* PDFPageRenderable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D2EB59A1C6A47CD007A87E7 /* PDFPageRenderable.swift */; };
- 4D47525C1D50A47F00019645 /* PDFOutput.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D47525B1D50A47F00019645 /* PDFOutput.storyboard */; };
4D4F97931C63882F00108BEB /* PDFGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D4F97921C63882F00108BEB /* PDFGenerator.h */; settings = {ATTRIBUTES = (Public, ); }; };
4D4F979A1C63882F00108BEB /* PDFGenerator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D4F978F1C63882F00108BEB /* PDFGenerator.framework */; };
4D4F979F1C63882F00108BEB /* PDFGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4F979E1C63882F00108BEB /* PDFGeneratorTests.swift */; };
@@ -25,12 +24,10 @@
4D4F97D21C639CCB00108BEB /* sample_4.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4D4F97CC1C639CCB00108BEB /* sample_4.jpg */; };
4D4F97D31C639CCB00108BEB /* sample_5.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4D4F97CD1C639CCB00108BEB /* sample_5.jpg */; };
4D54FFEC1C65CFFD000A9036 /* PDFPreviewVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D54FFEB1C65CFFD000A9036 /* PDFPreviewVC.swift */; };
- 4D54FFEE1C65D008000A9036 /* PDFPreviewVC.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D54FFED1C65D008000A9036 /* PDFPreviewVC.storyboard */; };
4D7462BD1D43AEB50044FBBB /* PDFPasswordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D7462BC1D43AEB50044FBBB /* PDFPasswordTests.swift */; };
4D7A9A021D805C4D00475C2E /* PDFOutputViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D7A9A011D805C4D00475C2E /* PDFOutputViewController.swift */; };
4D85127A1D191BA4009EE05C /* PDFPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D8512791D191BA4009EE05C /* PDFPage.swift */; };
4D8A9A6C1D2FB65600007E4B /* PDFPassword.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D8A9A6B1D2FB65600007E4B /* PDFPassword.swift */; };
- 4D900B911C817444004034C2 /* SampleTableViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D900B901C817444004034C2 /* SampleTableViewController.storyboard */; };
4D900B931C8174B8004034C2 /* SampleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D900B921C8174B8004034C2 /* SampleTableViewController.swift */; };
4D900B951C817582004034C2 /* SampleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D900B941C817582004034C2 /* SampleTableViewCell.swift */; };
4DA8AC331D4350DE00F04F9D /* FilePathConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA8AC321D4350DE00F04F9D /* FilePathConvertible.swift */; };
@@ -40,7 +37,6 @@
4DD477E21D19449700D83D50 /* DPIType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD477E11D19449700D83D50 /* DPIType.swift */; };
4DDF14FE1D43A931004ADB0B /* DPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDF14FD1D43A931004ADB0B /* DPITests.swift */; };
4DF6DEB61CA2590900C97F30 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF6DEB51CA2590900C97F30 /* WebViewController.swift */; };
- 4DF6DEB81CA25A5A00C97F30 /* WebViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */; };
B45907781E44CC100063E596 /* PDFGenerator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D4F978F1C63882F00108BEB /* PDFGenerator.framework */; };
D47C1DBD21145ADC00AF7BAF /* PDFPagedScrollViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47C1DBC21145ADC00AF7BAF /* PDFPagedScrollViewConfiguration.swift */; };
/* End PBXBuildFile section */
@@ -65,7 +61,6 @@
/* Begin PBXFileReference section */
1618D283215B4CD6005A2CE9 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
4D2EB59A1C6A47CD007A87E7 /* PDFPageRenderable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFPageRenderable.swift; sourceTree = ""; };
- 4D47525B1D50A47F00019645 /* PDFOutput.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PDFOutput.storyboard; sourceTree = ""; };
4D4F978F1C63882F00108BEB /* PDFGenerator.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PDFGenerator.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4D4F97921C63882F00108BEB /* PDFGenerator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = PDFGenerator.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
4D4F97991C63882F00108BEB /* PDFGeneratorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PDFGeneratorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -86,12 +81,10 @@
4D4F97CC1C639CCB00108BEB /* sample_4.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = sample_4.jpg; sourceTree = ""; };
4D4F97CD1C639CCB00108BEB /* sample_5.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = sample_5.jpg; sourceTree = ""; };
4D54FFEB1C65CFFD000A9036 /* PDFPreviewVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PDFPreviewVC.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
- 4D54FFED1C65D008000A9036 /* PDFPreviewVC.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PDFPreviewVC.storyboard; sourceTree = ""; };
4D7462BC1D43AEB50044FBBB /* PDFPasswordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFPasswordTests.swift; sourceTree = ""; };
4D7A9A011D805C4D00475C2E /* PDFOutputViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFOutputViewController.swift; sourceTree = ""; };
4D8512791D191BA4009EE05C /* PDFPage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFPage.swift; sourceTree = ""; };
4D8A9A6B1D2FB65600007E4B /* PDFPassword.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFPassword.swift; sourceTree = ""; };
- 4D900B901C817444004034C2 /* SampleTableViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = SampleTableViewController.storyboard; sourceTree = ""; };
4D900B921C8174B8004034C2 /* SampleTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTableViewController.swift; sourceTree = ""; };
4D900B941C817582004034C2 /* SampleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTableViewCell.swift; sourceTree = ""; };
4DA8AC321D4350DE00F04F9D /* FilePathConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilePathConvertible.swift; sourceTree = ""; };
@@ -101,7 +94,6 @@
4DD477E11D19449700D83D50 /* DPIType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPIType.swift; sourceTree = ""; };
4DDF14FD1D43A931004ADB0B /* DPITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPITests.swift; sourceTree = ""; };
4DF6DEB51CA2590900C97F30 /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; };
- 4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = WebViewController.storyboard; sourceTree = ""; };
D47C1DBC21145ADC00AF7BAF /* PDFPagedScrollViewConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFPagedScrollViewConfiguration.swift; sourceTree = ""; };
/* End PBXFileReference section */
@@ -132,6 +124,28 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 148C591F237A202B001E239F /* Controllers */ = {
+ isa = PBXGroup;
+ children = (
+ 4D4F97B11C6388AA00108BEB /* ViewController.swift */,
+ 4D54FFEB1C65CFFD000A9036 /* PDFPreviewVC.swift */,
+ 4D900B921C8174B8004034C2 /* SampleTableViewController.swift */,
+ 4DF6DEB51CA2590900C97F30 /* WebViewController.swift */,
+ 4D7A9A011D805C4D00475C2E /* PDFOutputViewController.swift */,
+ );
+ path = Controllers;
+ sourceTree = "";
+ };
+ 148C5920237A2030001E239F /* Views */ = {
+ isa = PBXGroup;
+ children = (
+ 4D900B941C817582004034C2 /* SampleTableViewCell.swift */,
+ 4D4F97B81C6388AA00108BEB /* LaunchScreen.storyboard */,
+ 4D4F97B31C6388AA00108BEB /* Main.storyboard */,
+ );
+ path = Views;
+ sourceTree = "";
+ };
4D4F97851C63882F00108BEB = {
isa = PBXGroup;
children = (
@@ -185,22 +199,12 @@
4D4F97AE1C6388AA00108BEB /* Demo */ = {
isa = PBXGroup;
children = (
+ 148C5920237A2030001E239F /* Views */,
+ 148C591F237A202B001E239F /* Controllers */,
4D4F97C11C63966D00108BEB /* sample_images */,
4D4F97AF1C6388AA00108BEB /* AppDelegate.swift */,
- 4D4F97B11C6388AA00108BEB /* ViewController.swift */,
- 4D54FFEB1C65CFFD000A9036 /* PDFPreviewVC.swift */,
- 4D900B921C8174B8004034C2 /* SampleTableViewController.swift */,
- 4D900B941C817582004034C2 /* SampleTableViewCell.swift */,
- 4DF6DEB51CA2590900C97F30 /* WebViewController.swift */,
- 4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */,
- 4D900B901C817444004034C2 /* SampleTableViewController.storyboard */,
- 4D54FFED1C65D008000A9036 /* PDFPreviewVC.storyboard */,
- 4D4F97B31C6388AA00108BEB /* Main.storyboard */,
4D4F97B61C6388AA00108BEB /* Assets.xcassets */,
- 4D4F97B81C6388AA00108BEB /* LaunchScreen.storyboard */,
4D4F97BB1C6388AA00108BEB /* Info.plist */,
- 4D47525B1D50A47F00019645 /* PDFOutput.storyboard */,
- 4D7A9A011D805C4D00475C2E /* PDFOutputViewController.swift */,
);
path = Demo;
sourceTree = "";
@@ -320,7 +324,7 @@
};
buildConfigurationList = 4D4F97891C63882F00108BEB /* Build configuration list for PBXProject "PDFGenerator" */;
compatibilityVersion = "Xcode 3.2";
- developmentRegion = English;
+ developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@@ -358,16 +362,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 4DF6DEB81CA25A5A00C97F30 /* WebViewController.storyboard in Resources */,
4D4F97D31C639CCB00108BEB /* sample_5.jpg in Resources */,
4D4F97BA1C6388AA00108BEB /* LaunchScreen.storyboard in Resources */,
4D4F97CE1C639CCB00108BEB /* sample_0.jpg in Resources */,
4D4F97B71C6388AA00108BEB /* Assets.xcassets in Resources */,
- 4D47525C1D50A47F00019645 /* PDFOutput.storyboard in Resources */,
4D4F97CF1C639CCB00108BEB /* sample_1.jpg in Resources */,
4D4F97B51C6388AA00108BEB /* Main.storyboard in Resources */,
- 4D54FFEE1C65D008000A9036 /* PDFPreviewVC.storyboard in Resources */,
- 4D900B911C817444004034C2 /* SampleTableViewController.storyboard in Resources */,
4D4F97D01C639CCB00108BEB /* sample_2.jpg in Resources */,
4D4F97D21C639CCB00108BEB /* sample_4.jpg in Resources */,
4D4F97D11C639CCB00108BEB /* sample_3.jpg in Resources */,
@@ -598,7 +598,7 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
- SWIFT_VERSION = 4.2;
+ SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -618,7 +618,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
- SWIFT_VERSION = 4.2;
+ SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -629,7 +629,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.sgr-ksmt.PDFGeneratorTests";
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 4.2;
+ SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -640,7 +640,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.sgr-ksmt.PDFGeneratorTests";
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 4.2;
+ SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -652,7 +652,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.sgr-ksmt.Demo";
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 3.0;
+ SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -664,7 +664,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.github.sgr-ksmt.Demo";
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 3.0;
+ SWIFT_VERSION = 5.0;
};
name = Release;
};
diff --git a/PDFGenerator/DPIType.swift b/PDFGenerator/DPIType.swift
index f41dead..68accef 100644
--- a/PDFGenerator/DPIType.swift
+++ b/PDFGenerator/DPIType.swift
@@ -14,7 +14,7 @@ public enum DPIType {
case `default`
case dpi_300
case custom(CGFloat)
-
+
public var value: CGFloat {
switch self {
case .default:
@@ -27,7 +27,7 @@ public enum DPIType {
return DPIType.default.value
}
}
-
+
public var scaleFactor: CGFloat {
return self.value / DPIType.default.value
}
diff --git a/PDFGenerator/FilePathConvertible.swift b/PDFGenerator/FilePathConvertible.swift
index 396c079..13f7442 100644
--- a/PDFGenerator/FilePathConvertible.swift
+++ b/PDFGenerator/FilePathConvertible.swift
@@ -23,7 +23,7 @@ extension String: FilePathConvertible {
public var url: URL {
return URL(fileURLWithPath: self)
}
-
+
public var path: String {
return self
}
diff --git a/PDFGenerator/PDFGenerator.swift b/PDFGenerator/PDFGenerator.swift
index 3402b32..91444b8 100644
--- a/PDFGenerator/PDFGenerator.swift
+++ b/PDFGenerator/PDFGenerator.swift
@@ -12,10 +12,10 @@ import UIKit
/// PDFGenerator
public final class PDFGenerator {
fileprivate typealias Process = () throws -> Void
-
+
/// Avoid creating instance.
- fileprivate init() {}
-
+ fileprivate init() { }
+
/**
Generate from page object.
@@ -27,7 +27,7 @@ public final class PDFGenerator {
public class func generate(_ page: PDFPage, to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate([page], to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from page objects.
@@ -52,7 +52,7 @@ public final class PDFGenerator {
throw error
}
}
-
+
/**
Generate from view.
@@ -64,7 +64,7 @@ public final class PDFGenerator {
public class func generate(_ view: UIView, to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate([view], to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from views.
@@ -76,7 +76,7 @@ public final class PDFGenerator {
public class func generate(_ views: [UIView], to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate(PDFPage.pages(views), to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from image.
@@ -88,7 +88,7 @@ public final class PDFGenerator {
public class func generate(_ image: UIImage, to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate([image], to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from images.
@@ -112,7 +112,7 @@ public final class PDFGenerator {
public class func generate(_ imagePath: String, to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate([imagePath], to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from image paths.
@@ -124,7 +124,7 @@ public final class PDFGenerator {
public class func generate(_ imagePaths: [String], to path: FilePathConvertible, dpi: DPIType = .default, password: PDFPassword = "") throws {
try generate(PDFPage.pages(imagePaths), to: path, dpi: dpi, password: password)
}
-
+
/**
Generate from page object.
@@ -134,7 +134,7 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by page: PDFPage, dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: [page], dpi: dpi, password: password)
}
@@ -148,7 +148,7 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by pages: [PDFPage], dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
guard !pages.isEmpty else {
throw PDFGenerateError.emptyPage
@@ -165,7 +165,7 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by view: UIView, dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: [view], dpi: dpi, password: password)
}
@@ -179,11 +179,11 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
- public class func generated(by views: [UIView], dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
+
+ public class func generated(by views: [UIView], dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: PDFPage.pages(views), dpi: dpi, password: password)
}
-
+
/**
Generate from image.
@@ -193,7 +193,7 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by image: UIImage, dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: [image], dpi: dpi, password: password)
}
@@ -207,11 +207,11 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by images: [UIImage], dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: PDFPage.pages(images), dpi: dpi, password: password)
}
-
+
/**
Generate from image path.
@@ -221,11 +221,11 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by imagePath: String, dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: [imagePath], dpi: dpi, password: password)
}
-
+
/**
Generate from image paths.
@@ -235,7 +235,7 @@ public final class PDFGenerator {
- returns: PDF's binary data (NSData)
*/
-
+
public class func generated(by imagePaths: [String], dpi: DPIType = .default, password: PDFPassword = "") throws -> Data {
return try generated(by: PDFPage.pages(imagePaths), dpi: dpi, password: password)
}
@@ -247,7 +247,7 @@ public final class PDFGenerator {
private extension PDFGenerator {
class func render(_ page: PDFPage, dpi: DPIType) throws {
let scaleFactor = dpi.scaleFactor
-
+
try autoreleasepool {
switch page {
case .whitePage(let size):
@@ -269,18 +269,18 @@ private extension PDFGenerator {
}
}
}
-
+
class func render(_ pages: [PDFPage], dpi: DPIType) throws {
try pages.forEach { try render($0, dpi: dpi) }
}
-
+
class func render(to path: FilePathConvertible, password: PDFPassword, process: Process) rethrows {
try { try password.verify() }()
UIGraphicsBeginPDFContextToFile(path.path, .zero, password.toDocumentInfo())
try process()
UIGraphicsEndPDFContext()
}
-
+
class func rendered(with password: PDFPassword, process: Process) rethrows -> Data {
try { try password.verify() }()
let data = NSMutableData()
diff --git a/PDFGenerator/PDFPage.swift b/PDFGenerator/PDFPage.swift
index 5f38445..97ec28a 100644
--- a/PDFGenerator/PDFPage.swift
+++ b/PDFGenerator/PDFPage.swift
@@ -34,7 +34,7 @@ public enum PDFPage {
case binary(Data)
/// Image ref (CGImage)
case imageRef(CGImage)
-
+
/**
Convert views to PDFPage models.
@@ -45,7 +45,7 @@ public enum PDFPage {
static func pages(_ views: [UIView]) -> [PDFPage] {
return views.map { .view($0) }
}
-
+
/**
Convert images to PDFPage models.
@@ -56,7 +56,7 @@ public enum PDFPage {
static func pages(_ images: [UIImage]) -> [PDFPage] {
return images.map { .image($0) }
}
-
+
/**
Convert image path to PDFPage models.
@@ -67,7 +67,7 @@ public enum PDFPage {
static func pages(_ imagePaths: [String]) -> [PDFPage] {
return imagePaths.map { .imagePath($0) }
}
-
+
/**
Convert a scrollview into different pages with a given configuration
@@ -81,10 +81,10 @@ public enum PDFPage {
let contentSize = scrollView.contentSize
let height = contentSize.width / configuration.ratio.rawValue
let overlapPercentage = configuration.overlapPercentage > 0 && configuration.overlapPercentage < 1 ? configuration.overlapPercentage : 0
-
+
var currentOffset: CGFloat = 0
var areas: [CGRect] = []
-
+
while currentOffset < contentSize.height {
let area = CGRect(x: 0, y: currentOffset, width: contentSize.width, height: height)
areas.append(area)
@@ -96,7 +96,7 @@ public enum PDFPage {
/// PDF page size (pixel, 72dpi)
public struct PDFPageSize {
- fileprivate init() {}
+ fileprivate init() { }
/// A4
public static let A4 = CGSize(width: 595.0, height: 842.0)
/// A5
diff --git a/PDFGenerator/PDFPageRenderable.swift b/PDFGenerator/PDFPageRenderable.swift
index 362f748..85141e5 100644
--- a/PDFGenerator/PDFPageRenderable.swift
+++ b/PDFGenerator/PDFPageRenderable.swift
@@ -16,23 +16,22 @@ protocol PDFPageRenderable {
private extension UIScrollView {
typealias TempInfo = (frame: CGRect, offset: CGPoint, inset: UIEdgeInsets)
-
+
var tempInfo: TempInfo {
return (frame, contentOffset, contentInset)
}
-
+
func transformForRender() {
contentOffset = .zero
contentInset = UIEdgeInsets.zero
frame = CGRect(origin: .zero, size: contentSize)
}
-
+
func restore(_ info: TempInfo) {
frame = info.frame
contentOffset = info.offset
contentInset = info.inset
}
-
}
extension UIView: PDFPageRenderable {
@@ -40,7 +39,7 @@ extension UIView: PDFPageRenderable {
guard scaleFactor > 0.0 else {
throw PDFGenerateError.invalidScaleFactor
}
-
+
let size: CGSize
let origin: CGPoint
if let area = area {
@@ -50,7 +49,7 @@ extension UIView: PDFPageRenderable {
origin = .zero
size = getPageSize()
}
-
+
guard size.width > 0 && size.height > 0 else {
throw PDFGenerateError.zeroSizeView(self)
}
@@ -71,11 +70,11 @@ extension UIView: PDFPageRenderable {
completion(view)
}
}
-
+
func renderPDFPage(scaleFactor: CGFloat) throws {
try self.renderPDFPage(scaleFactor: scaleFactor, area: nil)
}
-
+
func renderPDFPage(scaleFactor: CGFloat, area: CGRect?) throws {
func renderScrollView(_ scrollView: UIScrollView, area: CGRect?) throws {
let tmp = scrollView.tempInfo
@@ -84,8 +83,8 @@ extension UIView: PDFPageRenderable {
scrollView.restore(tmp)
}
}
-
- if let webView = self as? UIWebView {
+
+ if let webView = self as? WKWebView {
try renderScrollView(webView.scrollView, area: area)
} else if let webView = self as? WKWebView {
try renderScrollView(webView.scrollView, area: area)
@@ -95,11 +94,9 @@ extension UIView: PDFPageRenderable {
try _render(self, scaleFactor: scaleFactor, area: area)
}
}
-
+
fileprivate func getPageSize() -> CGSize {
switch self {
- case (let webView as UIWebView):
- return webView.scrollView.contentSize
case (let webView as WKWebView):
return webView.scrollView.contentSize
case (let scrollView as UIScrollView):
@@ -141,7 +138,7 @@ extension UIImage: UIImageConvertible {
extension String: UIImageConvertible {
func asUIImage() throws -> UIImage {
- guard let image = UIImage(contentsOfFile: self) else{
+ guard let image = UIImage(contentsOfFile: self) else {
throw PDFGenerateError.imageLoadFailed(self)
}
return image
diff --git a/PDFGenerator/PDFPagedScrollViewConfiguration.swift b/PDFGenerator/PDFPagedScrollViewConfiguration.swift
index ca36a3b..6631678 100644
--- a/PDFGenerator/PDFPagedScrollViewConfiguration.swift
+++ b/PDFGenerator/PDFPagedScrollViewConfiguration.swift
@@ -10,18 +10,18 @@ import Foundation
public struct PDFPagedScrollViewConfiguration {
public let overlapPercentage: CGFloat
public let ratio: PageRatio
-
+
public init(overlapPercentage: CGFloat, ratio: PageRatio) {
self.overlapPercentage = overlapPercentage
self.ratio = ratio
}
-
+
public enum PageRatio {
case dinA3, dinA4, dinA5
case ansiA, ansiB, ansiC
case invoice, executive, legal, letter
case custom(CGFloat)
-
+
public var rawValue: CGFloat {
switch self {
case .dinA3: return 297.0 / 420.0
diff --git a/PDFGenerator/PDFPassword.swift b/PDFGenerator/PDFPassword.swift
index ede2c69..e1d2c37 100644
--- a/PDFGenerator/PDFPassword.swift
+++ b/PDFGenerator/PDFPassword.swift
@@ -14,16 +14,16 @@ public struct PDFPassword {
fileprivate static let PasswordLengthMax = 32
let userPassword: String
let ownerPassword: String
-
+
public init(user userPassword: String, owner ownerPassword: String) {
self.userPassword = userPassword
self.ownerPassword = ownerPassword
}
-
+
public init(_ password: String) {
self.init(user: password, owner: password)
}
-
+
func toDocumentInfo() -> [AnyHashable: Any] {
var info: [AnyHashable: Any] = [:]
if userPassword != type(of: self).NoPassword {
@@ -34,7 +34,7 @@ public struct PDFPassword {
}
return info
}
-
+
func verify() throws {
guard userPassword.canBeConverted(to: String.Encoding.ascii) else {
throw PDFGenerateError.invalidPassword(userPassword)
@@ -42,7 +42,7 @@ public struct PDFPassword {
guard userPassword.count <= type(of: self).PasswordLengthMax else {
throw PDFGenerateError.tooLongPassword(userPassword.count)
}
-
+
guard ownerPassword.canBeConverted(to: String.Encoding.ascii) else {
throw PDFGenerateError.invalidPassword(ownerPassword)
}
@@ -56,11 +56,11 @@ extension PDFPassword: ExpressibleByStringLiteral {
public init(unicodeScalarLiteral value: String) {
self.init(value)
}
-
+
public init(extendedGraphemeClusterLiteral value: String) {
self.init(value)
}
-
+
public init(stringLiteral value: String) {
self.init(value)
}
diff --git a/PDFGeneratorTests/FilePathConvertibleTests.swift b/PDFGeneratorTests/FilePathConvertibleTests.swift
index 4f42402..b7f061b 100644
--- a/PDFGeneratorTests/FilePathConvertibleTests.swift
+++ b/PDFGeneratorTests/FilePathConvertibleTests.swift
@@ -10,7 +10,7 @@ import XCTest
@testable import PDFGenerator
class FilePathConvertibleTests: XCTestCase {
-
+
func test() {
let p1: FilePathConvertible = ""
XCTAssertNotNil(p1.url)
diff --git a/PDFGeneratorTests/PDFGeneratorTests.swift b/PDFGeneratorTests/PDFGeneratorTests.swift
index 72413c0..edafd4c 100644
--- a/PDFGeneratorTests/PDFGeneratorTests.swift
+++ b/PDFGeneratorTests/PDFGeneratorTests.swift
@@ -13,11 +13,11 @@ class Mock {
struct ImageName {
static let testImage1 = "test_image1"
}
-
+
class func view(_ size: CGSize) -> UIView {
return UIView(frame: CGRect(origin: CGPoint.zero, size: size))
}
-
+
class func scrollView(_ size: CGSize) -> UIScrollView {
return { () -> UIScrollView in
let v = UIScrollView(frame: CGRect(origin: CGPoint.zero, size: size))
@@ -26,30 +26,30 @@ class Mock {
}()
}
- class func imagePath(_ name: String) -> String{
+ class func imagePath(_ name: String) -> String {
return Bundle(for: self).path(forResource: name, ofType: "png")!
}
-
+
class func image(_ name: String) -> UIImage {
return UIImage(contentsOfFile: imagePath(name))!
}
-
+
}
class PDFGeneratorTests: XCTestCase {
-
+
func isExistPDF(_ path: String) -> Bool {
return FileManager.default.fileExists(atPath: path)
}
-
+
func PDFDirectoryPath() -> String {
return NSHomeDirectory() + "/test/"
}
-
+
func PDFfilePath(_ fileName: String) -> String {
return PDFDirectoryPath() + "/\(fileName)"
}
-
+
override func setUp() {
super.setUp()
try! FileManager.default.createDirectory(
@@ -58,78 +58,78 @@ class PDFGeneratorTests: XCTestCase {
attributes: nil
)
}
-
+
override func tearDown() {
_ = try? FileManager.default.removeItem(atPath: PDFDirectoryPath())
super.tearDown()
}
-
+
// MARK: UIView -> PDF
func testViewToPDF() {
let view = Mock.view(CGSize(width: 100, height: 100))
let view2 = Mock.scrollView(CGSize(width: 100, height: 100))
-
+
let path1 = PDFfilePath("test_sample1.pdf")
_ = try? PDFGenerator.generate(view, to: path1)
XCTAssertTrue(isExistPDF(path1))
-
+
let path2 = PDFfilePath("hoge/test_sample2.pdf")
_ = try? PDFGenerator.generate(view, to: path2)
XCTAssertFalse(isExistPDF(path2))
-
+
let path3 = PDFfilePath("test_sample3.pdf")
_ = try? PDFGenerator.generate(view, to: path3)
XCTAssertTrue(isExistPDF(path3))
-
+
XCTAssertNotNil(try? PDFGenerator.generated(by: view))
XCTAssertNotNil(try? PDFGenerator.generated(by: [view]))
XCTAssertNotNil(try? PDFGenerator.generated(by: [view, view2]))
}
-
+
// MARK: UIImage -> PDF
func testImageToPDF() {
let image1 = Mock.image("test_image1")
let image2 = Mock.image("test_image1")
-
+
let path1 = PDFfilePath("test_sample1.pdf")
_ = try? PDFGenerator.generate(image1, to: path1)
XCTAssertTrue(isExistPDF(path1))
-
+
let path2 = PDFfilePath("hoge/test_sample2.pdf")
_ = try? PDFGenerator.generate(image1, to: path2)
XCTAssertFalse(isExistPDF(path2))
-
+
let path3 = PDFfilePath("test_sample3.pdf")
_ = try? PDFGenerator.generate([image1, image2], to: path3)
XCTAssertTrue(isExistPDF(path3))
-
+
XCTAssertNotNil(try? PDFGenerator.generated(by: image1))
XCTAssertNotNil(try? PDFGenerator.generated(by: [image1]))
XCTAssertNotNil(try? PDFGenerator.generated(by: [image1, image2]))
}
-
+
// MARK: ImagePath(String) -> PDF
func testImagePathToPDF() {
let image1 = Mock.imagePath("test_image1")
let image2 = Mock.imagePath("test_image1")
-
+
let path1 = PDFfilePath("test_sample1.pdf")
_ = try? PDFGenerator.generate(image1, to: path1)
XCTAssertTrue(isExistPDF(path1))
-
+
let path2 = PDFfilePath("hoge/test_sample2.pdf")
_ = try? PDFGenerator.generate(image1, to: path2)
XCTAssertFalse(isExistPDF(path2))
-
+
let path3 = PDFfilePath("test_sample3.pdf")
_ = try? PDFGenerator.generate([image1, image2], to: path3)
XCTAssertTrue(isExistPDF(path3))
-
+
XCTAssertNotNil(try? PDFGenerator.generated(by: image1))
XCTAssertNotNil(try? PDFGenerator.generated(by: [image1]))
XCTAssertNotNil(try? PDFGenerator.generated(by: [image1, image2]))
}
-
+
// MARK: PDFPage -> PDF
func testMixedPageToPDF() {
let p1 = PDFPage.view(Mock.view(CGSize(width: 100, height: 100)))
@@ -138,7 +138,7 @@ class PDFGeneratorTests: XCTestCase {
let p4 = PDFPage.whitePage(CGSize(width: 100, height: 100))
let p5 = PDFPage.imageRef(Mock.image(Mock.ImageName.testImage1).cgImage!)
let p6 = PDFPage.binary(Mock.image(Mock.ImageName.testImage1).pngData()!)
-
+
let path1 = PDFfilePath("test_sample1.pdf")
_ = try? PDFGenerator.generate(p1, to: path1)
XCTAssertTrue(isExistPDF(path1))
@@ -146,7 +146,7 @@ class PDFGeneratorTests: XCTestCase {
let path2 = PDFfilePath("hoge/test_sample2.pdf")
_ = try? PDFGenerator.generate(p2, to: path2)
XCTAssertFalse(isExistPDF(path2))
-
+
let path3 = PDFfilePath("test_sample3.pdf")
_ = try? PDFGenerator.generate([p1, p2, p3, p4], to: path3)
XCTAssertTrue(isExistPDF(path3))
@@ -157,7 +157,7 @@ class PDFGeneratorTests: XCTestCase {
XCTAssertNotNil(try? PDFGenerator.generated(by: [p5, p6]))
}
-
+
// swiftlint:disable function_body_length
func testErrors() {
let view = Mock.view(CGSize(width: 100, height: 100))
@@ -179,7 +179,7 @@ class PDFGeneratorTests: XCTestCase {
Mock.imagePath(Mock.ImageName.testImage1),
Mock.imagePath(Mock.ImageName.testImage1)
]
-
+
let pages = [
PDFPage.view(Mock.view(CGSize(width: 100, height: 100))),
PDFPage.image(Mock.image(Mock.ImageName.testImage1)),
@@ -200,14 +200,14 @@ class PDFGeneratorTests: XCTestCase {
imagePaths,
pages
]
-
+
let emptyMocks: [Any] = [
[UIView](),
[UIImage](),
[String](),
[PDFPage]()
]
-
+
// MARK: check EmptyOutputPath
mocks.forEach {
do {
@@ -237,7 +237,7 @@ class PDFGeneratorTests: XCTestCase {
XCTFail("[\($0)] Unknown or wrong error occurred.\(e)")
}
}
-
+
// MARK: check EmptyPage
emptyMocks.forEach {
do {
@@ -260,7 +260,7 @@ class PDFGeneratorTests: XCTestCase {
XCTFail("[\($0)] Unknown or wrong error occurred.\(e)")
}
}
-
+
// MARK: check EmptyPage
emptyMocks.forEach {
do {
@@ -282,7 +282,7 @@ class PDFGeneratorTests: XCTestCase {
XCTFail("[\($0)] Unknown or wrong error occurred.\(e)")
}
}
-
+
// MARK: check ZeroSizeView
let emptyView = Mock.view(CGSize.zero)
do {
@@ -307,7 +307,7 @@ class PDFGeneratorTests: XCTestCase {
} catch (let e) {
XCTFail("Unknown or wrong error occurred.\(e)")
}
-
+
let emptyViewPage = PDFPage.view(emptyView)
do {
let path = PDFfilePath("test_sample3.pdf")
@@ -380,9 +380,9 @@ class PDFGeneratorTests: XCTestCase {
} catch (let e) {
XCTFail("Unknown or wrong error occurred.\(e)")
}
-
+
let wrongData = Data()
-
+
do {
_ = try PDFGenerator.generated(by: PDFPage.binary(wrongData))
} catch PDFGenerateError.imageLoadFailed(let data) {
@@ -393,19 +393,19 @@ class PDFGeneratorTests: XCTestCase {
}
// swiftlint:enable function_body_length
-
+
func testPDFPassword() {
let view = Mock.view(CGSize(width: 100, height: 100))
let view2 = Mock.view(CGSize(width: 100, height: 100))
-
+
let path1 = PDFfilePath("test_sample1.pdf")
_ = try? PDFGenerator.generate(view, to: path1, password: "abcdef")
XCTAssertTrue(isExistPDF(path1))
-
+
let path2 = PDFfilePath("test_sample2.pdf")
_ = try? PDFGenerator.generate(view, to: path2, password: "⌘123456")
XCTAssertFalse(isExistPDF(path2))
-
+
let path3 = PDFfilePath("test_sample3.pdf")
do {
try PDFGenerator.generate([view, view2], to: path3, password: "123456")
@@ -435,7 +435,7 @@ class PDFGeneratorTests: XCTestCase {
XCTAssertNotNil(try? PDFGenerator.generated(by: view, password: "abcdef"))
XCTAssertNil(try? PDFGenerator.generated(by: [view], password: "⌘123456"))
-
+
do {
_ = try PDFGenerator.generated(by: [view], password: "123456")
} catch {
@@ -449,7 +449,7 @@ class PDFGeneratorTests: XCTestCase {
} catch {
XCTFail()
}
-
+
do {
_ = try PDFGenerator.generated(by: [view], password: "0123456789abcdef0123456789abcdefA")
XCTFail()
diff --git a/PDFGeneratorTests/PDFPasswordTests.swift b/PDFGeneratorTests/PDFPasswordTests.swift
index 2c6a9f1..e9bb7f2 100644
--- a/PDFGeneratorTests/PDFPasswordTests.swift
+++ b/PDFGeneratorTests/PDFPasswordTests.swift
@@ -18,7 +18,7 @@ class PDFPasswordTests: XCTestCase {
} catch _ {
XCTFail()
}
-
+
let p2: PDFPassword = PDFPassword(user: "123456", owner: "abcdef")
XCTAssertNotEqual(p2.userPassword, p2.ownerPassword)
do {
@@ -36,7 +36,7 @@ class PDFPasswordTests: XCTestCase {
} catch _ {
XCTFail()
}
-
+
let p4: PDFPassword = PDFPassword(user: "123456", owner: "ああああ")
do {
try p4.verify()
@@ -46,7 +46,7 @@ class PDFPasswordTests: XCTestCase {
} catch _ {
XCTFail()
}
-
+
let p5: PDFPassword = PDFPassword(user: "1234567890123456789012345678901234567890", owner: "abcdef")
do {
try p5.verify()
@@ -56,7 +56,7 @@ class PDFPasswordTests: XCTestCase {
} catch _ {
XCTFail()
}
-
+
let p6: PDFPassword = PDFPassword(user: "123456", owner: "abcdefghijabcdefghijabcdefghijabcdefghij")
do {
try p6.verify()