forked from marty5499/webbit-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.html
165 lines (149 loc) · 4.43 KB
/
pdf.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html>
<head>
<title>PDF Viewer</title>
<link rel="stylesheet" type="text/css" href="https://mozilla.github.io/pdf.js/web/viewer.css">
<style>
#ctx {
position: relative;
top: 100px;
left: 100px;
width: 500px;
height: 500px;
border: solid;
}
#pdfObj {
max-width: 100%;
max-height: 100%;
overflow: auto;
}
#pdfContainer {
#height: calc(100vh - 40px);
#margin: 50px 0 0 0;
}
.pdfContainer-highlight {
background-color: rgb(239, 248, 0);
}
.pdfContainer-mark {
background-color: rgb(255, 77, 77);
}
.pdfContainer-overlay {
z-index: 900;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
color: rgb(101, 98, 98);
top: 0;
left: 0;
}
.pdfContainer-loading {
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: center;
font-size: 1.6em;
width: 100%;
}
.page-tool {
bottom: 10px;
position: fixed;
padding-left: 12px;
padding-right: 12px;
display: flex;
align-items: center;
background: rgb(66, 66, 66);
color: white;
border-radius: 15px;
z-index: 100;
cursor: pointer;
left: 50%;
transform: translateX(-50%);
user-select: none;
}
.page-tool-item {
cursor: pointer;
padding: 8px 15px;
padding-left: 10px;
transition: background-color 0.3s;
}
.page-tool-item:active {
background-color: #ddd;
}
.page-tool-input {
border: none;
background: none;
outline: none;
color: white;
}
body {
background-color: bisque;
}
</style>
</head>
<body>
<div id="ctx">
<div id="pdfObj">
<div class="page-tool">
<div class="page-tool-item" onclick="pdf.zoom(0.7)">整頁</div>
<div class="page-tool-item" onclick="pdf.lastPage()">上一頁</div>
<div id='pageShow' class="page-tool-item"></div>
<div class="page-tool-item" onclick="pdf.nextPage()">下一頁</div>
<div class="page-tool-item" onclick="pdf.zoomIn(0.2)">放大</div>
<div class="page-tool-item" onclick="pdf.zoomOut(0.2)">缩小</div>
<div class="page-tool-item">
<input type="text" class="page-tool-input" placeholder="輸入內容" />
</div>
</div>
<div id="pdfContainer">
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<!--
<script src="/test/pdf/pdf.3.8.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.8.162/pdf.min.js"></script>
-->
<script src="./src/waPDF.js"></script>
<script>
var pdf = new PDF();
pdf.setViewElement(document.getElementById("pdfContainer"), document.getElementById("pageShow"));
var searchInput = document.querySelector(".page-tool-input");
var flag = false;
searchInput.addEventListener("compositionstart", function (ev) {
flag = true;
});
searchInput.addEventListener("compositionupdate", function (ev) {
flag = true;
});
searchInput.addEventListener("compositionend", function (ev) {
handleInput(ev.data);
flag = false;
});
searchInput.addEventListener("input", function (ev) {
if (!flag) handleInput(ev.data);
});
function handleInput(value) {
console.log("find:", searchInput.value);
pdf.mark(searchInput.value);
}
((async function () {
var url = 'https://kn-staging.nodered.vip/books/docs/eyJucyI6IjFXS0ZOal84MzhSNlJRVHRsa2lrXzBscjNQcG4tQjVKNSIsImZpbGUiOiJib29rLnBkZiJ9';
var url = './test/pdf/book3.pdf';
await pdf.load(url);
//pdf.page(await pdf.mark('民國38年'));
console.log("== test1 ==");
//pdf.page(await pdf.mark('什麼是機會'));
//pdf.page(await pdf.mark('生物可藉由'));
//pdf.page(await pdf.mark('認識各種顯微鏡'));
console.log("== test2 ==");
//pdf.page(await pdf.mark('1-1'));
//pdf.page(await pdf.mark('5 張開雙眼,以一眼從目鏡觀察,打開光源及調整光圈的大小,使視野中的亮度'));
//pdf.page(await pdf.mark('解探究提問'));
console.log("== test4 ==");
//pdf.page(await pdf.mark('瞬間一片寂靜'));
console.log("== test3 ==");
//pdf.page(await pdf.mark('設計與進行實驗'));
})())
</script>
</body>
</html>