forked from 0x68/TFPDFView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TFPDFView.j
119 lines (93 loc) · 2.67 KB
/
TFPDFView.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@import <Foundation/CPObject.j>
@implementation TFPDFView : CPWebView
{
CPURL theURL;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[self setBackgroundColor:[CPColor grayColor]];
[self setScrollMode:CPWebViewScrollAppKit];
//load the viewer.html file which contains a link to the viewer.js file
var myURL = [[CPBundle mainBundle] pathForResource:"pdfFrame/viewer.html"];
[self setMainFrameURL:[CPURL URLWithString:myURL]];
}
return self;
}
- (void)loadPDFFromURL:(CPURL)anURL startPage:(int)pageNumber
{
if(pageNumber && pageNumber > 0){
var theJS = "setStartPage(" + pageNumber + ");";
[self stringByEvaluatingJavaScriptFromString:theJS];
}else{
var theJS = "setStartPage(1)";
[self stringByEvaluatingJavaScriptFromString:theJS];
}
var myJS = "getMyPdfFromUrl(\"" + anURL + "\");";
[self stringByEvaluatingJavaScriptFromString:myJS];
theURL = anURL;
}
- (void)loadPDFFromData:(CPObject)data
{
var myJS = "getMyPdfFromData(\"" + data + "\")";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)clear
{
var myJS = "clear()";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)nextPage
{
var myJS = "PDFView.page++;";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)prevPage
{
var myJS = "PDFView.page--;";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)goToPage:(int)pageNum
{
var myJS = "PDFView.page = " + pageNum + ";";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (int)numberOfPages
{
var myJS = "getNumberOfPages()";
return [self stringByEvaluatingJavaScriptFromString:myJS];
}
- (int)currentPage
{
var myJS = "getCurrentPage()";
return [self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)zoomOut
{
var myJS = "PDFView.zoomOut();";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)zoomIn
{
var myJS = "PDFView.zoomIn();";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
- (void)selectZoom:(CPString)zoomName
{
/*
<option value="0.5">50%</option>
<option value="0.75">75%</option>
<option value="1">100%</option>
<option value="1.25">125%</option>
<option value="1.5" selected="selected">150%</option>
<option value="2">200%</option>
<option id="pageWidthOption" value="page-width">Page Width</option>
<option id="pageFitOption" value="page-fit">Page Fit</option>
*/
var myJS = "PDFView.parseScale(\"" + zoomName + "\");";
[self stringByEvaluatingJavaScriptFromString:myJS];
}
@end