forked from sgr-ksmt/PDFGenerator
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare Demo for webView sgr-ksmt#18
- Loading branch information
Showing
7 changed files
with
146 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="agr-Bd-01h"> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Web View Controller--> | ||
<scene sceneID="xDk-0N-TTV"> | ||
<objects> | ||
<viewController id="agr-Bd-01h" customClass="WebViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="tFx-VQ-KEU"/> | ||
<viewControllerLayoutGuide type="bottom" id="yiC-n7-0o7"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="IRc-XT-O1w"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VC0-fG-sSg"> | ||
<rect key="frame" x="0.0" y="20" width="600" height="200"/> | ||
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="deviceRGB"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="200" id="BaV-Vk-89A"/> | ||
</constraints> | ||
</webView> | ||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GnF-lf-UMf"> | ||
<rect key="frame" x="285" y="250" width="30" height="30"/> | ||
<constraints> | ||
<constraint firstAttribute="width" constant="30" id="fco-gS-WH1"/> | ||
<constraint firstAttribute="height" constant="30" id="tDp-3p-Egp"/> | ||
</constraints> | ||
<state key="normal" title="PDF"/> | ||
<connections> | ||
<action selector="generatePDF" destination="agr-Bd-01h" eventType="touchUpInside" id="1Dr-rA-1tr"/> | ||
</connections> | ||
</button> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="GnF-lf-UMf" firstAttribute="centerX" secondItem="IRc-XT-O1w" secondAttribute="centerX" id="EEL-dG-gHB"/> | ||
<constraint firstItem="VC0-fG-sSg" firstAttribute="leading" secondItem="IRc-XT-O1w" secondAttribute="leading" id="JFA-ge-bAo"/> | ||
<constraint firstItem="GnF-lf-UMf" firstAttribute="top" secondItem="VC0-fG-sSg" secondAttribute="bottom" constant="30" id="Jxb-tE-jJ6"/> | ||
<constraint firstAttribute="trailing" secondItem="VC0-fG-sSg" secondAttribute="trailing" id="TPP-ws-uqx"/> | ||
<constraint firstItem="VC0-fG-sSg" firstAttribute="top" secondItem="tFx-VQ-KEU" secondAttribute="bottom" id="gls-O5-HeG"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="webView" destination="VC0-fG-sSg" id="FN0-YH-6N8"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="tD9-QV-HgR" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="762" y="285"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// WebViewController.swift | ||
// PDFGenerator | ||
// | ||
// Created by Suguru Kishimoto on 2016/03/23. | ||
// | ||
// | ||
|
||
import UIKit | ||
import WebKit | ||
import PDFGenerator | ||
|
||
class WebViewController: UIViewController { | ||
|
||
@IBOutlet private weak var webView: UIWebView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
let req = NSMutableURLRequest(URL: NSURL(string: "http://www.yahoo.co.jp")!, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 60) | ||
webView.loadRequest(req) | ||
} | ||
|
||
override func didReceiveMemoryWarning() { | ||
super.didReceiveMemoryWarning() | ||
} | ||
|
||
@IBAction func generatePDF() { | ||
do { | ||
let dst = NSHomeDirectory().stringByAppendingString("/sample_tblview.pdf") | ||
try PDFGenerator.generate(webView, outputPath: dst) | ||
openPDFViewer(dst) | ||
} catch let error { | ||
print(error) | ||
} | ||
|
||
} | ||
|
||
private func openPDFViewer(pdfPath: String) { | ||
let url = NSURL(fileURLWithPath: pdfPath) | ||
let storyboard = UIStoryboard(name: "PDFPreviewVC", bundle: nil) | ||
let vc = storyboard.instantiateInitialViewController() as! PDFPreviewVC | ||
vc.setupWithURL(url) | ||
presentViewController(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. | ||
} | ||
*/ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters