Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 71c129b

Browse files
author
Nicolas Schäfli
committed
Merge branch 'release/0.2.0' into 'master'
Release 0.2.0 See merge request Apps/bin-eLehrmittel/pdf-wrap!5
2 parents 1444e02 + 7c4e3ac commit 71c129b

27 files changed

+3281
-2209
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.2.0 - 2019-01-18
8+
9+
### Added
10+
* Close method to pdf document which resolves after the cleanup finished.
11+
* Use pdf link service for internal document links.
12+
* Add scaleTo method which allows scaling to predefined values.
13+
* Add isEnabled getter to highlight interface.
14+
* Experimental touch support for drawing tools.
15+
* Engines version constraint (node 10.9 - 10.x, yarn 1.12 - 1.14)
16+
* Max picture size constraint to 4096^2.
17+
18+
### Fixed
19+
* Filter highlights which are to small to be visible.
20+
* Recalculate height of highlights to really fit the element instead of the selection (webkit & blink).
21+
* Page number detection while drawing with freehand tool.
22+
* Eraser tool now stops removing lines after mouse up.
23+
* Freehand tool now scales lines according to document scale.
24+
25+
### Changed
26+
* Disable background highlight layer because its not visible with colored
27+
document backgrounds.
28+
* pdf document service loadWith now resolves after the viewer is ready instead of instantly after
29+
creation.
30+
* Upgrade to typescript version ^3.1.0
31+
* Enable text selection enhancement.
32+
* Enable WebGL.
33+
* Upgrade pdfjs to 2.0.943.
34+
* Update example (dev-viewer).
35+
* The freehand touchscreen support is now mentioned in the documentation.
36+
37+
### Removed
38+
* Documentation about first highlight layer which is no longer implemented.
39+
740
## 0.1.3 - 2018-08-23
841

942
### Fixed

docs/development-guide.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
**Authors**
44

55
Nicolas Märchy
6+
Nicolas Schäfli
67

78
**Version 1.0.0**
89

@@ -42,11 +43,7 @@ rendered PDF page, so it won't cover the text.
4243
Is the actual PDF page rendered as svg by PDF.js.
4344

4445
**HIGHLIGHT LAYER TRANSPARENCY**<br>
45-
Is the same as the *HIGHLIGHT Layer* but with less opacity (about 40%). This layer
46-
is required to highlight text which is not on a white background. With only
47-
the *HIGHLIGHT LAYER*, the highlight would not be visible at all, because of the
48-
non-transparent background of the *PDF LAYER*. The transparency is required
49-
to not cover the *PDF LAYER* completely.
46+
This layer contains any highlighting with an opacity of (about 40%).
5047

5148
**DRAW LAYER**<br>
5249
The layer contains all drawings made by a user.
@@ -314,6 +311,27 @@ yarn gulp publishDoc
314311
This will generate the documentation, updates the `gh-pages` branch
315312
and pushes it to Github.
316313
314+
# NPM
315+
316+
PDF Wrap is published to [npm.js](https://www.npmjs.com/package/@srag/pdf-wrap).
317+
318+
## How to publish PDF Wrap
319+
320+
In order to publish this project to npm you have to log in with your npm account
321+
322+
```
323+
yarn login
324+
```
325+
326+
Then simply run
327+
328+
```
329+
yarn gulp publish
330+
```
331+
332+
> It is important to use this command and **NOT `yarn publish`** directly, because the gulp command will
333+
prepare PDF Wrap before publishing it.
334+
317335
# Unit Testing
318336
319337
PDF Wrap uses [Mocha](https://mochajs.org/) to run its tests. In addition, [chaijs](http://www.chaijs.com/) is used

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ the reference documentation.
2626
## Examples
2727
Looking for finished examples? Here you'll find access to examples made with PDF Wrap.
2828

29-
[Check out examples >](link-to-github)
29+
[Check out examples >](https://github.com/studer-raimann/pdf-wrap/tree/master/examples)

docs/reference-documentation.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
**Authors**
44

55
Nicolas Märchy
6+
Nicolas Schäfli
67

7-
**Version 0.0.1**
8+
**Version 1.0.0**
89

910
Copyright &copy; 2018 studer + raimann ag, <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
1011

@@ -49,12 +50,6 @@ yarn add pdf-wrap
4950
npm i pdf-wrap
5051
```
5152

52-
### Manual Installation
53-
54-
You can download the PDF Wrap distribution from the npm repository.
55-
56-
* [pdf-wrap.tar.zip](https://www.npmjs.com/)
57-
5853
# Using PDF Wrap
5954

6055
This section goes into more detail about how you should use PDF Wrap.
@@ -287,7 +282,7 @@ pdf.toolbox.freehand.stateChange
287282
**Limitations:**
288283

289284
* The Freehand tool can **not** draw over multiple PDF pages at once
290-
* The Freehand tool does **not** work with touchscreen
285+
* The Freehand tool touchscreen support is **experimental**.
291286

292287
The Freehand tool as additional setters:
293288

-8.66 KB
Loading

examples/dev-viewer/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "GPL-3.0",
88
"scripts": {
99
"copyCSS": "cp -r src/css build/www",
10-
"copyPDFjs": "mkdir -p build/www/assets/libs/pdf-wrap && cp -r node_modules/pdf-wrap/assets/* build/www/assets/libs/pdf-wrap",
10+
"copyPDFjs": "mkdir -p build/www/assets/libs/pdf-wrap && cp -r node_modules/@srag/pdf-wrap/assets/* build/www/assets/libs/pdf-wrap",
1111
"copyResources": "cp src/index.html build/www && cp -r src/assets/* build/www/assets",
1212
"build": "yarn webpack && yarn run copyResources && yarn run copyPDFjs && yarn run copyCSS",
1313
"clean": "rm -r build",
@@ -18,7 +18,5 @@
1818
"webpack": "^4.12.0",
1919
"webpack-cli": "^3.0.3"
2020
},
21-
"dependencies": {
22-
"log4js": "^2.9.0"
23-
}
21+
"dependencies": {}
2422
}

examples/dev-viewer/src/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ <h1 class="middle aligned">Dev PDF viewer</h1>
102102
<button id="previous-page"><-</button>
103103
<button id="next-page">-></button>
104104

105+
<button id="load-page">Load</button>
106+
<button id="close-page">Close</button>
107+
105108
</div>
106109

107110
</div>
@@ -133,4 +136,4 @@ <h4>Thumbnails</h4>
133136
<script src="main.js"></script>
134137

135138
</body>
136-
</html>
139+
</html>

examples/dev-viewer/src/js/index.js

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import {setAssetsSrc} from "../../../../src/pdfjs/pdfjs.document.service";
1+
import {LoggerFactory} from "@srag/pdf-wrap/log-config";
2+
import {PageOverlay} from "@srag/pdf-wrap/api/storage/adapter";
3+
4+
import {setAssetsSrc} from "@srag/pdf-wrap/pdfjs/pdfjs.document.service";
5+
import {colorFromHex} from "@srag/pdf-wrap/api/draw/color";
6+
import {PDFjsDocumentService} from "@srag/pdf-wrap/pdfjs/pdfjs.document.service";
7+
import {URI} from "@srag/pdf-wrap/api/document.service";
8+
import {StorageRegistry} from "@srag/pdf-wrap/api/storage/adapter.registry";
9+
import {LogLevel} from "@srag/pdf-wrap/log-config";
10+
211

3-
const {colorFromHex} = require("pdf-wrap/api/draw/color");
4-
const {PDFjsDocumentService, setWorkerSrc, setCMapUrl} = require("pdf-wrap/pdfjs/pdfjs.document.service");
5-
const {URI} = require("pdf-wrap/api/document.service");
6-
const {StorageRegistry} = require("pdf-wrap/api/storage/adapter.registry");
7-
const {PageOverlay} = require("pdf-wrap/api/storage/adapter");
8-
const {LoggerFactory} = require("pdf-wrap/log-config");
912

1013
LoggerFactory.configure({
1114
logGroups: [
1215
{
1316
logger: "ch/studerraimann/pdfwrap",
14-
logLevel: 0
17+
logLevel: LogLevel.TRACE
1518
}
1619
]
1720
});
@@ -33,15 +36,15 @@ export class InMemStorageAdapter {
3336

3437
events.afterPolyLineRendered().subscribe(it => {
3538
store.set(it.element.id, it);
36-
});
39+
}, (it) => console.error(it), () => console.log("afterPolyLineRendered complete"));
3740

3841
events.afterRectangleRendered().subscribe(it => {
3942
store.set(it.element.id, it);
40-
});
43+
}, (it) => console.error(it), () => console.log("afterRectangleRendered complete"));
4144

4245
events.afterElementRemoved().subscribe(it => {
4346
store.delete(it.element.id);
44-
})
47+
}, (it) => console.error(it), () => console.log("afterElementRemoved complete"))
4548
}
4649

4750
loadPage(uri, pageNumber) {
@@ -219,6 +222,7 @@ export class SidebarManager {
219222

220223
this._outline.then(outline => {
221224

225+
this.clearOutline();
222226
outline.flatList.forEach(it => {
223227

224228
const li = document.createElement("li");
@@ -235,6 +239,7 @@ export class SidebarManager {
235239

236240
renderThumbnails() {
237241

242+
this.clearThumbnails();
238243
this._thumbails.subscribe(it => {
239244

240245
const li = document.createElement("li");
@@ -249,34 +254,38 @@ export class SidebarManager {
249254
this._thumbnailsUlElement.appendChild(li);
250255
});
251256
}
252-
}
253257

254-
const documentService = new PDFjsDocumentService();
258+
clearThumbnails() {
259+
while (this._thumbnailsUlElement.lastChild) {
260+
this._thumbnailsUlElement.removeChild(this._thumbnailsUlElement.lastChild);
261+
}
262+
}
255263

264+
clearOutline() {
265+
while (this._tableOfContents.lastChild) {
266+
this._tableOfContents.removeChild(this._tableOfContents.lastChild);
267+
}
268+
}
269+
}
256270

257-
new Promise(resolve => {
271+
let documentService = null;
272+
let pdfDoc = null;
258273

259-
const request = new XMLHttpRequest();
260-
request.open('GET', "assets/resources/chicken.pdf", true);
261-
request.responseType = 'blob';
262-
request.onload = function() {
263-
resolve(request.response);
264-
};
265-
request.send();
266-
}).then(pdf => {
267-
return documentService.loadWith({
274+
export async function loadPDF() {
275+
documentService = new PDFjsDocumentService();
276+
const pdf = await (await fetch("assets/resources/chicken.pdf")).blob();
277+
const pdfDocument = await documentService.loadWith({
268278
container: document.getElementById("viewerContainer"),
269279
pdf: pdf,
270280
layerStorage: URI.from("mem://chicken.pdf")
271-
})
272-
}).then(it => {
281+
});
273282

274283
const highlightService = new HighlightService();
275284

276285
const highlightButton = new HighlightButton(highlightService);
277286
const clearButton = new ClearButton(highlightService);
278-
const penButton = new PenButton(it.toolbox.freehand);
279-
const eraserButton = new EraserButton(it.toolbox.eraser);
287+
const penButton = new PenButton(pdfDocument.toolbox.freehand);
288+
const eraserButton = new EraserButton(pdfDocument.toolbox.eraser);
280289

281290
// search
282291
const searchButton = document.getElementById("search-button");
@@ -286,72 +295,89 @@ new Promise(resolve => {
286295
const searchField = document.getElementById("search-term");
287296

288297
searchButton.addEventListener("click", () => {
289-
it.searchController.search(searchField.value, {fuzzy: true, searchPhrase: true, highlightAll: true});
298+
pdfDocument.searchController.search(searchField.value, {fuzzy: true, searchPhrase: true, highlightAll: true});
290299
});
291300

292301
previousSearch.addEventListener("click", () => {
293-
it.searchController.previous();
302+
pdfDocument.searchController.previous();
294303
});
295304

296305
nextSearch.addEventListener("click", () => {
297-
it.searchController.next();
306+
pdfDocument.searchController.next();
298307
});
299308

300309
// zoom
301310
const zoomIn = document.getElementById("zoom-in-button");
302311
const zoomOut = document.getElementById("zoom-out-button");
303312

304313
zoomIn.addEventListener("click", () => {
305-
it.scale = it.scale * 1.5;
314+
pdfDocument.scale = pdfDocument.scale * 1.5;
306315
});
307316

308317
zoomOut.addEventListener("click", () => {
309-
it.scale = it.scale / 1.5;
318+
pdfDocument.scale = pdfDocument.scale / 1.5;
310319
});
311320

312321
// page navigation
313322
const pageNumberInput = document.getElementById("page-number");
314-
pageNumberInput.innerHTML = it.currentPageNumber;
323+
pageNumberInput.innerHTML = pdfDocument.currentPageNumber.toString();
315324

316-
it.pageChange.subscribe(it => {
317-
pageNumberInput.innerHTML = it.pageNumber;
325+
pdfDocument.pageChange.subscribe(it => {
326+
pageNumberInput.innerHTML = it.pageNumber.toString();
318327
});
319328

320329
const pageCountLabel = document.getElementById("page-count-label");
321-
pageCountLabel.innerHTML = "/ " + it.pageCount;
330+
pageCountLabel.innerHTML = "/ " + pdfDocument.pageCount;
322331

323332
const previousPage = document.getElementById("previous-page");
324333
const nextPage = document.getElementById("next-page");
325334

326335
previousPage.addEventListener("click", () => {
327-
it.currentPageNumber = it.currentPageNumber - 1;
336+
pdfDocument.currentPageNumber = pdfDocument.currentPageNumber - 1;
328337
});
329338

330339
nextPage.addEventListener("click", () => {
331-
it.currentPageNumber = it.currentPageNumber + 1;
340+
pdfDocument.currentPageNumber = pdfDocument.currentPageNumber + 1;
332341
});
333342

334343
// sidebar left
335-
const sidebarManager = new SidebarManager(it);
344+
const sidebarManager = new SidebarManager(pdfDocument);
336345
sidebarManager.renderOutline();
337346
sidebarManager.renderThumbnails();
338347

339-
it.highlighting.enable();
348+
pdfDocument.highlighting.enable();
340349

341350
// highlighting
342-
it.highlighting.onTextSelection
351+
pdfDocument.highlighting.onTextSelection
343352
.subscribe(it => {
344353
highlightService.textSelection = it;
345354
highlightButton.enable();
346355
clearButton.enable();
347356
});
348357

349-
it.highlighting.onTextUnselection
358+
pdfDocument.highlighting.onTextUnselection
350359
.subscribe(() => {
351360
highlightButton.disable();
352361
clearButton.disable();
353362
});
354-
});
363+
pdfDoc = pdfDocument;
364+
365+
}
366+
367+
export function close() {
368+
console.log("close");
369+
const thumbnails = document.getElementById("thumbnails");
370+
while (thumbnails.lastChild) {
371+
thumbnails.removeChild(thumbnails.lastChild);
372+
}
373+
pdfDoc.close();
374+
pdfDoc = null;
375+
documentService = null;
376+
}
377+
378+
loadPDF();
355379

380+
document.getElementById("close-page").addEventListener("click", close);
381+
document.getElementById("load-page").addEventListener("click", loadPDF);
356382

357383

0 commit comments

Comments
 (0)