Skip to content

Commit d32b749

Browse files
committed
Add more tests and examples structure
1 parent 7f1942b commit d32b749

23 files changed

Lines changed: 466 additions & 162 deletions

File tree

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ A lightweight, standalone JavaScript PDF viewer library that wraps Mozilla's pdf
2626
### 1. Add to Your HTML
2727

2828
```html
29-
<div id="viewer" style="height: 100vh; width: 100%;"></div>
29+
<div id="viewer" style="height: 100dvh; width: 100%;"></div>
3030

3131
<script src="https://cdn.jsdelivr.net/gh/BrunoRNS/SimplePDFviewer@latest/min/core.min.js"></script>
3232
<script type="text/javascript">
3333
const course = {
34+
id: "mycourseid",
3435
title: "My Course",
3536
modules: [{
37+
id: "module1id",
3638
title: "Module 1",
3739
chapters: [{
40+
id: "chapter1id",
3841
title: "Chapter 1",
3942
pdf: "https://example.com/chapter1.pdf"
4043
}]
@@ -103,17 +106,22 @@ SimplePDFviewer organizes PDFs hierarchically:
103106

104107
```javascript
105108
{
109+
id: "course-001",
106110
title: "Course Title",
107111
modules: [{
112+
id: "mod-001",
108113
title: "Module 1",
109114
chapters: [{
115+
id: "chap-001",
110116
title: "Chapter 1",
111117
pdf: "url/to/pdf.pdf"
112118
}, {
119+
id: "chap-002",
113120
title: "Chapter 2",
114121
pdf: "url/to/pdf2.pdf"
115122
}]
116123
}, {
124+
id: "mod-002",
117125
title: "Module 2",
118126
chapters: [/* ... */]
119127
}]
@@ -261,17 +269,6 @@ docker-compose up
261269

262270
See [BUILD.md](./docs/BUILD.md) for complete build instructions and Docker setup.
263271

264-
## Browser Support
265-
266-
| Browser | Version | Status |
267-
|---------|---------|------------|
268-
| Chrome | 45+ | Full |
269-
| Firefox | 40+ | Full |
270-
| Safari | 10+ | Full |
271-
| Edge | 12+ | Full |
272-
| IE | 11 | Limited |
273-
| Mobile | Latest | Full |
274-
275272
## Performance
276273

277274
- **File Size**: ~15KB minified (gzips to ~4KB)
@@ -337,13 +334,6 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for detailed instructions.
337334
- **Usage Questions**: Check [FAQ.md](./docs/FAQ.md) or [USAGE.md](./docs/USAGE.md)
338335
- **Contributing**: See [CONTRIBUTING.md](./docs/CONTRIBUTING.md)
339336

340-
## Project Status
341-
342-
- **Status**: Active development
343-
- **Latest Version**: Rolling release
344-
- **Last Updated**: February 2026
345-
- **Maintenance**: Community maintained
346-
347337
## Example Use Cases
348338

349339
### Educational Platforms
335 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Basic Usage Example</title>
5+
<link rel="icon" type="image/png" href="./favicon.png">
6+
</head>
7+
<body>
8+
<div id="viewer" style="height: 100dvh; width: 100%;"></div>
9+
<!-- Change the path to your core.min.js file or to the online CDN(see README) -->
10+
<script src="http://localhost:8001/core.min.js"></script>
11+
<script type="text/javascript">
12+
const course = {
13+
id: "courseID",
14+
title: "My Course",
15+
modules: [{
16+
id: "module1ID",
17+
title: "Module 1",
18+
chapters: [{
19+
id: "chapter1ID",
20+
title: "Chapter 1",
21+
// Hello World PDF from pdf.js
22+
pdf: "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"
23+
}]
24+
}]
25+
};
26+
PDFViewer.init(document.getElementById('viewer'), course);
27+
</script>
28+
</body>
29+
</html>

test-example/course.json renamed to test-example/002_external_json_usage/course.json

File renamed without changes.
522 KB
Loading
File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"id": "test#666",
3+
"title": "Simple PDF Viewer Test Example",
4+
"modules": [
5+
{
6+
"id": "mod#1",
7+
"title": "Test Module",
8+
"chapters": [
9+
{
10+
"id": "chap#1",
11+
"title": "Chapter 1 Example",
12+
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"
13+
},
14+
{
15+
"id": "chap#2",
16+
"title": "Chapter 2 Example",
17+
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"
18+
}
19+
]
20+
}
21+
]
22+
}
824 KB
Loading
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>SimplePDFviewer Test - CDN Loading</title>
7+
<style type="text/css">
8+
body { font-family: Arial, sans-serif; margin: 20px; }
9+
#viewer { height: 80dvh; border: 1px solid #ccc; }
10+
.info { background: #f0f0f0; padding: 10px; margin-bottom: 20px; border-radius: 4px; }
11+
.error { color: #d32f2f; }
12+
.success { color: #388e3c; }
13+
code { background: #f5f5f5; padding: 2px 4px; border-radius: 3px; }
14+
.controls { margin-bottom: 20px; }
15+
.controls button {
16+
padding: 8px 15px;
17+
margin-right: 10px;
18+
cursor: pointer;
19+
border: 1px solid #ccc;
20+
border-radius: 4px;
21+
background: #f0f0f0;
22+
}
23+
.controls button:hover { background: #e0e0e0; }
24+
.controls input {
25+
padding: 8px;
26+
margin-right: 10px;
27+
border: 1px solid #ccc;
28+
border-radius: 4px;
29+
width: 120px;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<h1>SimplePDFviewer Test</h1>
35+
<div class="info">
36+
<p>
37+
Loading SimplePDFviewer from CDN: <code>http://localhost:8001/core.min.js</code>
38+
</p>
39+
<p id="status">Loading...</p>
40+
</div>
41+
42+
<div class="controls">
43+
<h3>Theme Customization (Optional)</h3>
44+
<input type="text" id="colorInput" placeholder="e.g. #3498DB" value="#3498DB">
45+
<button onclick="changeTheme()">Change Theme</button>
46+
<button onclick="changeTheme('#3498DB')">Blue (Default)</button>
47+
<button onclick="changeTheme('#E91E63')">Pink</button>
48+
<button onclick="changeTheme('#4CAF50')">Green</button>
49+
<button onclick="changeTheme('#FF9800')">Orange</button>
50+
<button onclick="changeTheme('#9C27B0')">Purple</button>
51+
</div>
52+
53+
<div id="viewer"></div>
54+
55+
<!-- Change the path to your core.min.js file or to the online CDN(see README) -->
56+
<script type="text/javascript" src="http://localhost:8001/core.min.js"></script>
57+
58+
<script type="text/javascript">
59+
let viewer = null;
60+
const COLOR_STORAGE_KEY = 'pdfViewer_theme';
61+
const DEFAULT_COLOR = '#3498DB';
62+
63+
function changeTheme(color) {
64+
if (!viewer) {
65+
alert('Viewer not initialized yet');
66+
return;
67+
}
68+
const colorInput = document.getElementById('colorInput');
69+
if (color) {
70+
colorInput.value = color;
71+
}
72+
const colorValue = colorInput.value || DEFAULT_COLOR;
73+
const success = viewer.setTheme(colorValue);
74+
if (success) {
75+
localStorage.setItem(COLOR_STORAGE_KEY, colorValue);
76+
alert(`Theme changed to ${colorValue}`);
77+
} else {
78+
alert(`Invalid color: ${colorValue}`);
79+
}
80+
}
81+
82+
function getSavedTheme() {
83+
const saved = localStorage.getItem(COLOR_STORAGE_KEY);
84+
return saved && /^#[0-9A-Fa-f]{6}$/.test(saved) ? saved : DEFAULT_COLOR;
85+
}
86+
87+
function initializeViewer() {
88+
if (typeof PDFViewer === 'undefined') {
89+
document.getElementById('status').innerHTML = `
90+
<span class="error">PDFViewer library not loaded</span>
91+
`;
92+
return;
93+
}
94+
95+
document.getElementById('status').innerHTML = `
96+
<span class="success">SimplePDFviewer loaded from CDN successfully</span>
97+
`;
98+
99+
const savedTheme = getSavedTheme();
100+
const colorInput = document.getElementById('colorInput');
101+
colorInput.value = savedTheme;
102+
103+
fetch('course.json')
104+
.then(response => response.json())
105+
.then(course => {
106+
viewer = PDFViewer.init(
107+
document.getElementById('viewer'),
108+
course,
109+
{
110+
colorTheme: savedTheme,
111+
onError: (error) => {
112+
console.error('Viewer error:', error);
113+
document.getElementById('status').innerHTML += `
114+
<br><span class="error">
115+
Viewer Error: ${error.message}
116+
</span>`;
117+
}
118+
}
119+
);
120+
if (viewer) {
121+
colorInput.value = savedTheme;
122+
document.getElementById('status').innerHTML += `
123+
<br><span class="success">
124+
Viewer initialized successfully (Theme: ${savedTheme})
125+
</span>`;
126+
} else {
127+
document.getElementById('status').innerHTML += `
128+
<br><span class="error">
129+
Failed to initialize viewer
130+
</span>`;
131+
}
132+
})
133+
.catch(err => {
134+
console.error('Error loading course:', err);
135+
document.getElementById('status').innerHTML += `
136+
<br><span class="error">
137+
Error loading course: ${err.message}
138+
</span>`;
139+
document.getElementById('viewer').innerHTML = `
140+
<p style="color:red">
141+
Error loading course. Check browser console for details.
142+
</p>`;
143+
});
144+
}
145+
146+
if (document.readyState === 'loading') {
147+
document.addEventListener('DOMContentLoaded', initializeViewer);
148+
} else {
149+
initializeViewer();
150+
}
151+
</script>
152+
</body>
153+
</html>
File renamed without changes.

0 commit comments

Comments
 (0)