Foxit Mobile PDF SDK 入门级(1)-显示一个PDF-Swift工程中的使用(Xcode 7.x, swift 2.x)
Swift 渐渐流行,Foxit的SDK是不是可以在Swift中很好的使用呢?答案当然是可以的啦。
SDK的下载申请:
英文网站:
http://www.foxitsdk.com/products/mobile-pdf-sdk/request-trial/
中文网站:
http://www.foxitsoftware.cn/products/sdk/mobile-pdf-sdk/
对iOS的开发我是小白,Swift的了解也是少之又少,不过有万能的Google/百度,现学现卖还是很快的。
因为我的机器系统比较旧,Xcode是7.x版本,所有就暂时试试Swift2.x了,打算这个尝试做完就升级系统, 升级Xocde了。
废话少说,直接写步骤吧!(其实只要几分钟的事情,截图是给小白看的 ,高手可能不用看这文章就知道咋做了,为什么截图呢,比较容易一步一步照着做,也因为我自己也是小白)
一样,准备好SDK包,然后创建Swift工程,
第一步:新建工程
打开XCode File->NewProject->Single View Application.创建一个新的Universal Swift app
选择Single View Application
填写Project名称,注意:语言选择Swift, Devices选择Universal,如下图
接着选择一个存放目录,点击Create就生成好工程了。
如下图:
第二步:导入库存及工程设置
导入库
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
加入测试文件:
![](/assets/blank.gif)
![](/assets/blank.gif)
创建和配置Bridging-Header.h
创建Bridging-Header.h
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
Build Setting
![](/assets/blank.gif)
//
// Bridging-Header.h
// SwiftDemo
//
// Created by Amy Lin on 16/11/2.
// Copyright © 2016年 Amy Lin. All rights reserved.
//#ifndef Bridging_Header_h
#define Bridging_Header_h#import <FoxitRDK/FSPDFObjC.h>
#import <FoxitRDK/FSPDFViewControl.h>#endif /* Bridging_Header_h */
设置Other Linker Flags -lstdc++
![](/assets/blank.gif)
第三步,开始写代码
库的初始化
<pre name="code" class="plain"> //init librarylet sn: String = ""let key: String = ""let eRet = FSLibrary.init(sn,key:key)if e_errSuccess != eRet {return false}
整个文件的代码
<pre name="code" class="plain">//
// AppDelegate.swift
// SwiftDemo
//
// Created by Amy Lin on 16/11/2.
// Copyright © 2016年 Amy Lin. All rights reserved.
//import UIKit@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {// Override point for customization after application launch.//init librarylet sn: String = "TtGWd61AP09nKyEIkWRip9/sdHEfet/NbaCW6bGFnaQdGdppuzvWHg=="let key: String = "ezJvj93HtBp39Js1IV0+hIBmZehlKDiKb8RKO8M5RZ7SkoE5DnYhZ2kCHF8rv3HJbfvMjg9nnncPclJpsPsT3myZuPtAromUOHhJSHx9Yar/ANfHXTuFa8+AC+00R0GfFZs8LHgxu2kK+uaE8KiJiURZuDYxGzqKZkAgv52o1qs7FSeP0P+1jzVy5q/2xlz1xKovfnAISs1l/ezggBocDP8DLmFtWU3LQ/LFTVKTWtu2XUgJ5TulzhayQfzI58679RBMK2gfzq1611T+wtP3ZX57S8d5PHKMpAXaiN/qN14aCN0YvQsBCc3XhSAdP+IGkS/vpqVTXLCW5NXpwFMCQxhNt6ggR0w+51HNZ//lyBHCnhfs+L1G5ENqn0hPwpalMrY6Z8L1csnoVPhV7hUCO4csnyDbIWi3ynoh2hvfwlmBqsmyLiaSYK2AcH4RgNjlG8gF4RhD7Qg0PG8nSR+RpFaHuNiYvhF7cdcID5mXqgnKbh6EHHjoXSd3VM7hLDOIPGcD+3eCJLPQBSFny5I0VPHLV8C20T4I915rbKfh0lHwW1eXntygMBcS1mpr7mrZqXqoGdZTFLGBIp3gWS2KXbqRJAu+8bFMJLE07K6KS+crxW37gJA84uuNT7vhVc5hIk9zcOR7R+eC4o0Vp1IDSN0SZXttRezUddPQWG+6+CbygXTYzlqotyunjSklgwVk1mJD1VrgzkMC8lQyGyBoBKIIcSsmwWB3zdKD9GkGVkwbAM0HQbRh6X7pKx+KBCHqXokzpblz9tmtM4XpYFrZv6lJWo8DikZzLA4UDav0HPZB5TGDWlgghpq2pVspcCxXYn+lgXcJ05AgM9TQwYebJ5T9FKvUJXPl3oIfNYSndDoOeAfdtAD+uxfktPOxWAOaSTJhkv1AMjAjI31rGSmTKEWqHh+rKLOA1DAvimpKH6FCSlquwNojPtL4+czCVjEk04CZHDbDA29zy5mAeVlh2tJXB4PpObh35b/vWENTboO+G+HaOmqW0X2Zl0lcTuTXrJzNKfh6i59FnoRxYDqMY9n8GuGV13mAPan+WrCKIFdLnz4m3DrVmbqyu5AIHIcTDBajE5yQ0DIrP0u9ZuTQvPocydKzxUvDmho8D0oMCBXeO8HzCYzL/ISE9nKPjgYnpSU6DM84WQruswXLgYJxhWwLINEgo9PLnPS3gP4UfqM4FVvQZ1s7dBjUoBjJIg=="let eRet = FSLibrary.init(sn,key:key)if e_errSuccess != eRet {return false}return true}func applicationWillResignActive(application: UIApplication) {// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}func applicationDidEnterBackground(application: UIApplication) {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}func applicationWillEnterForeground(application: UIApplication) {// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}func applicationDidBecomeActive(application: UIApplication) {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}func applicationWillTerminate(application: UIApplication) {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}}
文档加载和显示
1. 在UIViewController中定义 pdfViewCtrl
var pdfViewCtrl: FSPDFViewCtrl!
2.LoadDoc And Show
viewDidLoad函数中加入以下代码
super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.self.pdfViewCtrl = FSPDFViewCtrl(frame:self.view.bounds)//Load Doclet pdfPath = NSBundle.mainBundle().pathForResource("getting_started_ios", ofType: "pdf")let doc = FSPDFDoc.createFromFilePath(pdfPath)if e_errSuccess == doc!.load(nil) {self.pdfViewCtrl.setDoc(doc)self.view.insertSubview(self.pdfViewCtrl, atIndex: 0)}
ViewController.swift整个文件的代码如下
//
// ViewController.swift
// SwiftDemo
//
// Created by Amy Lin on 16/11/2.
// Copyright © 2016年 Amy Lin. All rights reserved.
//import UIKitclass ViewController: UIViewController {var pdfViewCtrl: FSPDFViewCtrl!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.self.pdfViewCtrl = FSPDFViewCtrl(frame:self.view.bounds)//Load Doclet pdfPath = NSBundle.mainBundle().pathForResource("getting_started_ios", ofType: "pdf")let doc = FSPDFDoc.createFromFilePath(pdfPath)if e_errSuccess == doc!.load(nil) {self.pdfViewCtrl.setDoc(doc)self.view.insertSubview(self.pdfViewCtrl, atIndex: 0)}}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}}
build 运行后效果
其他说明
本文中的代码,是满足显示的最小代码,如果实际开发,需要加入出错判断等。
Foxit Mobile PDF SDK 入门级(1)-显示一个PDF-Swift工程中的使用(Xcode 7.x, swift 2.x)相关推荐
- 如何把一张pdf分成多个?一个pdf怎么分成若干个pdf?
我们经常会遇到PDF文档里面页面比较多,但是有时候我们只需要其中的一部分内容,改怎么办呢,这个时候就需要把这个PDF文件拆分成多个pdf文件了,或者按页面,或者只需要其中一两页,今天我就给大家分享一个 ...
- android pdf编辑,Foxit PDF SDK
PDF显示 Foxit PDF SDK提供了高性能的PDF库,使PDF页面.页面对象.注释和表单的显示更加清晰.明快.精准且易于阅读.支持应用程序对PDF文档和表单进行浏览.缩小.放大和打印,同时也支 ...
- Foxit PDF SDK ActiveX 5.9.7 Crack
Foxit PDF SDK ActiveX对于刚接触PDF或不愿投入过多精力学习PDF技术的产品管理者及开发者来说,Foxit PDF SDK ActiveX无疑是理想的选择.破解版它拥有操作简单的特 ...
- 使用ComPDFKit PDF SDK 构建iOS PDF阅读器
在当今以移动为先的世界中,为企业和开发人员创建一个iOS应用程序是必不可少的.随着对PDF文档处理需求的增加,使用ComPDFKit这个强大的PDF软件开发工具包(SDK)来构建iOS PDF阅读器和 ...
- Win10用Windows照片查看程序打开图片+更改注册表后导致Win10任务栏Adobe PDF阅读器图标显示异常
Win10用Windows照片查看程序打开图片 解决办法: 参考:https://jingyan.baidu.com/article/455a9950bb20bda166277824.html 上述操 ...
- Windows Mobile 6 SDK 中的 GPS 工具
Windows Mobile 6 SDK 中的 GPS 工具 GPS Intermediate Driver 自从 Windows Mobile 5.0 引进了 GPS Intermediate Dr ...
- 在ubuntu上如何将多张图片或PDF合到一个PDF上
在日常工作中我们可能需要将不同的PDF或图像合并为一个PDF上,这种情况并不少见. 这时候我们需要学习使用一个非常强大的命令行工具ImageMagick. 通过apt命令下载安装ImageMagick ...
- 如何将多个pdf合成一个pdf?
如何将多个pdf合成一个pdf?我们经常会在电脑上下载很多的学习资料,下载到的学习资料大多是pdf格式的文件,有时候可能会下载到数量比较多的pdf学习文件,这样每次使用的时候都要一个一个文件的寻找然后 ...
- 【Python】将多个jpg合并成一个pdf
import img2pdf import time # 导入时间库生成时间戳 import os ` local_time = time.localtime() # 获取本地时间 time_sign ...
最新文章
- linux完美卸载mysql,Linux下彻底卸载mysql详解
- AI、区块链和机器人:技术会让未来的工作发生什变化?
- [转]Photoshop Lab模式下保细节修复偏暗人物照片
- TextView 的ScrollView滚动效果
- openwrt 安装尔雅云_[网络]openwrt的阿里云编译
- 这些假脸实在太逼真了!英伟达造出新一代GAN,生成壁纸级高清大图毫无破绽...
- BZOJ2160 拉拉队排练【Manacher】
- ubuntu设置虚拟显示器且远程连接
- BlueCoat SG设备对非标准HTTPS应用访问提示不可信任发行者证书问题解决
- springboot2集成shiro认证鉴权(上篇)
- php ansiix99mac,华擎推出X99E-ITX/ac主板,终于可以把Haswell-E装进小钢炮
- C语言文件重定向---“系统找不到指定的文件”
- Uncle Sam 山姆大叔
- 微信开通公众号 每日发一篇编程精文 自己搞着玩,不盈利
- 辽宁省省直个人住房公积金贷款指南
- 【Linux】内核驱动篇九--设备模型
- 人工智能入门算法逻辑回归学习笔记
- 博图注册表删除方法_三菱、西门子软件安装常见出错解决方法!(干货)
- 论文翻译1-PARSEC-Streaming 360-Degree Videos Using Super-Resolution
- 金蝶标准单据扩展类开发