diff --git a/files_reader/CHANGELOG.md b/files_reader/CHANGELOG.md
index 3a2d9fe..347a3c6 100644
--- a/files_reader/CHANGELOG.md
+++ b/files_reader/CHANGELOG.md
@@ -1,4 +1,4 @@
-## UNRELEASED
+## 1.1 - 2018-01-18
### Added
- Reader now supports PDF
- PDF double page spreads are supported
@@ -8,6 +8,7 @@
### Changed
- #38: moved declarations in js/ready.js one level lower to work around a bug in the Palemoon browser
- new version bitjs archive tools, fixes compatibility problems with some CBR files
+ - increased maximum supported version for OC and NC
## 1.0.1 - 2017-03-19
### Fixed
diff --git a/files_reader/README.md b/files_reader/README.md
index af26845..ca15d34 100644
--- a/files_reader/README.md
+++ b/files_reader/README.md
@@ -1,26 +1,30 @@
files_reader
------------
-Reader is an ebook reader based on pure javascript renderers. It works for books formatted according to the following standards:
+Reader is an ebook reader based on pure javascript renderers. It works for publications formatted according to the following standards:
- [Epub]
+ - [PDF]
- [CBR and CBZ] ('comics')
For Epub Reader uses the futurepress [epub.js] renderer to provide near-native looks, especially when used full-screen. Turn pages by pressing the left/right hand side of the screen/window or using the cursor keys (if you have those), use the sidebar to browse through chapters or bookmarks and add annotations.
+PDF is handled by Mozilla's [pdf.js] renderer in combination with a custom reader app to enable side-by-side display, batch search and more. Controls are like those used in the Epub renderer with a few exceptions, e.g. night mode has not been implemented yet.
+
CBR and CBZ are supported using a custom renderer inspired by [balaclark]'s work. As with Epub, books can be navigated using the keyboard as well as mouse or touch navigation. Reader generates a visual index of all pages, show in the sidebar (thumbnail generation can be disabled for low-memory and/or -speed devices). As CBx files are often of varying quality, a set of image enhancement filters are provided.
# Features
Reader remembers the last-visited page in a book and returns to that page when the book is re-opened. As all settings are stored on the server these features are device-independent, ie. you can start reading on a mobile device, continue on a PC to finish the book on a tablet.
-### Text-based formats
+
+### Text-based formats incl. PDF
- seamless full-screen mode supported on browsers which allow full user-control, ie. not on Apple)
- single- and double-page viewing mode
- user-configurable font and colour settings
- - night mode, toggled by clicking the book title/author on top of the viewer
+ - night mode, toggled by clicking the book title/author on top of the viewer (not yet implemented for PDF)
- full-text search with keyword highlighting
- bookmarks (with automatic snippet generation)
- - annotations
+ - annotations (not yet implemented for PDF)
- keyboard and pointer/touch-based navigation
### CBR/CBZ ('Comics')
@@ -32,6 +36,8 @@ Reader remembers the last-visited page in a book and returns to that page when t
- visual index (thumbnail size user-configurable, can be disabled for low-memory or -cpu devices)
- keyboard and pointer/touch-based navigation
+PDF support is still somewhat rough around the edges, not all features have been implemented yet. There is a known cosmetical issue in that in spread mode the (invisible but selectable) text layer for the left page is offset from the left when opening a document. As soon as a page is turned this problem disappears.
+
### Keyboard navigation
Reader supports both pointer/touch-based as well as keyboard-based navigation. Pointer/touch based is mostly self-explanatory,
@@ -54,7 +60,7 @@ Reader supports both pointer/touch-based as well as keyboard-based navigation. P
### Defaults and Preferences
-Reader stores __defaults__ - settings which are independent of _fileId_ (ie. independent of the book currently open) - and __preferences__ - _fileId_-dependent (ie. different for every book) - on the server. Defaults are not shared between renderers, ie. the CBR renderer does not share defaults with the EPUB renderer. Defaults and preferences are removed from the server when the associated book or user is deleted.
+Reader stores __defaults__ - settings which are independent of _fileId_ (ie. independent of the book currently open) - and __preferences__ - _fileId_-dependent (ie. different for every book) - on the server. Defaults are not shared between renderers, ie. the CBR renderer does not share defaults with the EPUB or PDF renderer. Defaults and preferences are removed from the server when the associated book or user is deleted.
### Annotations and Bookmarks
@@ -75,6 +81,14 @@ Search on small-screen device|![Search on small-screen device][SS07]
As close to full-screen as you can get on iOS|![As close to full-screen as you can get on iOS][SS08]
Android supports true fullscreen (as do most other systems)|![Android supports true fullscreen (as do most other systems)][SS09]
+### PDF
+| | |
+---|---
+Reader showing PDF Reference document in spread mode (pages side by side)|![Reader showing PDF Reference document in spread mode (pages side by side)][SS20]
+Search through a document, showing all results in the sidebar|![Search through a document, showing all results in the sidebar][SS19]
+Dropdown showing page format options - spread, single page, page width and zoom options|![Dropdown showing page format options - spread, single page, page width and zoom options][SS21]
+Reader showing PDF in spread mode, thumbnails in the sidebar|![Reader showing PDF in spread mode, thumbnails in the sidebar][SS22]
+
### CBR/CBZ
| | |
@@ -95,6 +109,7 @@ The same Android device showing a zoomed-in part of a page|![The same Android de
[Epub]: http://idpf.org/epub
[CBR and CBZ]: https://wiki.mobileread.com/wiki/CBR_and_CBZ
[balaclark]: https://github.com/balaclark/HTML5-Comic-Book-Reader
+ [pdf.js]: https://github.com/mozilla/pdf.js
[SS01]: https://raw.githubusercontent.com/Yetangitu/owncloud-apps/master/screenshots/files_reader-1.png "Reader showing day/nighyt mode"
[SS02]: https://raw.githubusercontent.com/Yetangitu/owncloud-apps/master/screenshots/files_reader-3.png "Single page full screen on a small-screen device"
[SS03]: https://raw.githubusercontent.com/Yetangitu/owncloud-apps/master/screenshots/photo_2017-03-15_17-21-39.jpg "Day mode color selector"
@@ -113,3 +128,9 @@ The same Android device showing a zoomed-in part of a page|![The same Android de
[SS16]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/photo_2017-03-15_17-22-10.jpg?raw=true "Same page, zoomed in"
[SS17]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/photo_2017-03-15_18-28-54.jpg?raw=true "Small-screen, low memory (Android) device showing full-page book cover"
[SS18]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/photo_2017-03-15_18-28-56.jpg?raw=true "The same Android device showing a zoomed-in part of a page"
+ [SS19]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/files_reader_PDF_001.png?raw=true "Search through a document, showing all results in the sidebar"
+ [SS20]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/files_reader_PDF_002.png?raw=true "Reader showing PDF Reference document in spread mode (pages side by side)"
+ [SS21]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/files_reader_PDF_005.png?raw=true "Dropdown showing page format options - spread, single page, page width and zoom options"
+ [SS22]: https://github.com/Yetangitu/owncloud-apps/blob/master/screenshots/files_reader_PDF_006.png?raw=true "Reader showing PDF in spread mode, thumbnails in the sidebar"
+
+
diff --git a/files_reader/appinfo/info.xml b/files_reader/appinfo/info.xml
index c2006e4..77a3556 100644
--- a/files_reader/appinfo/info.xml
+++ b/files_reader/appinfo/info.xml
@@ -5,28 +5,32 @@
Files_ReaderA multi-format browser-based ebook reader, supports EPUB and CBR/CBZ
-
- 1.0.1
+ 1.1AGPLFrank de Lange
@@ -140,8 +159,8 @@ The same Android device showing a zoomed-in part of a page|![The same Android de
-
-
+
+ pgsqlsqlitemysql
diff --git a/files_reader/js/ready.js b/files_reader/js/ready.js
index 7237189..1efb08e 100644
--- a/files_reader/js/ready.js
+++ b/files_reader/js/ready.js
@@ -25,6 +25,8 @@ document.onreadystatechange = function () {
options.session.basePath = $session.data('basepath');
options.session.downloadLink = $session.data('downloadlink');
+ console.log(options.session.basePath);
+
/* functions return jquery promises */
options.session.getPreference = function(name) {
@@ -142,6 +144,7 @@ document.onreadystatechange = function () {
// start pdf.js renderer
function renderPdf(file, options) {
PDFJS.filePath = "vendor/pdfjs/";
+ PDFJS.imageResourcesPath = "vendor/pdfjs/css/images/";
PDFJS.workerSrc = options.session.basePath + 'vendor/pdfjs/lib/pdf.worker.js';
var reader = pdfReader(file, options);
diff --git a/files_reader/templates/cbreader.php b/files_reader/templates/cbreader.php
index 7d8b69d..c3c27ff 100644
--- a/files_reader/templates/cbreader.php
+++ b/files_reader/templates/cbreader.php
@@ -28,7 +28,7 @@
?>
-' data-scope='' data-cursor='' data-defaults='' data-preferences='' data-metadata='' data-annotations=''>
+
diff --git a/files_reader/templates/epubreader.php b/files_reader/templates/epubreader.php
index f2ff51f..16032e7 100644
--- a/files_reader/templates/epubreader.php
+++ b/files_reader/templates/epubreader.php
@@ -28,7 +28,7 @@
?>
-' data-scope='' data-cursor='' data-defaults='' data-preferences='' data-metadata='' data-annotations=''>
+
diff --git a/files_reader/templates/pdfreader.php b/files_reader/templates/pdfreader.php
index 49d5748..39791d9 100644
--- a/files_reader/templates/pdfreader.php
+++ b/files_reader/templates/pdfreader.php
@@ -28,7 +28,7 @@
?>
-' data-scope='' data-cursor='' data-defaults='' data-preferences='' data-metadata='' data-annotations=''>
+
@@ -40,14 +40,17 @@
-
+
+
+
+
@@ -57,6 +60,9 @@
+
+
+
@@ -87,7 +93,9 @@
+
@@ -119,6 +127,7 @@
+
-
+
-
-
+
+
+
+
+
+
diff --git a/files_reader/vendor/pdfjs/controllers/.bookmarks_controller.js.swp b/files_reader/vendor/pdfjs/controllers/.bookmarks_controller.js.swp
new file mode 100644
index 0000000..216f4bb
Binary files /dev/null and b/files_reader/vendor/pdfjs/controllers/.bookmarks_controller.js.swp differ
diff --git a/files_reader/vendor/pdfjs/controllers/annotationlayer_controller.js b/files_reader/vendor/pdfjs/controllers/annotationlayer_controller.js
new file mode 100644
index 0000000..94efc87
--- /dev/null
+++ b/files_reader/vendor/pdfjs/controllers/annotationlayer_controller.js
@@ -0,0 +1,59 @@
+PDFJS.Reader.AnnotationLayerController = function (options, reader) {
+
+ this.reader = reader;
+ this.annotationDiv = options.annotationDiv;
+ this.pdfPage = options.pdfPage;
+ this.renderInteractiveForms = options.renderInteractiveForms;
+ this.linkService = options.linkService;
+ this.downloadManager = options.downloadManager;
+
+ this.div = null;
+
+ return this;
+};
+
+PDFJS.Reader.AnnotationLayerController.prototype.render = function (viewport, intent) {
+ var self = this;
+ var parameters = {
+ intent: (intent === undefined ? 'display' : intent),
+ };
+
+ this.pdfPage.getAnnotations(parameters).then(function (annotations) {
+ viewport = viewport.clone({ dontFlip: true });
+ parameters = {
+ viewport: viewport,
+ div: self.div,
+ annotations: annotations,
+ page: self.pdfPage,
+ renderInteractiveForms: self.renderInteractiveForms,
+ linkService: self.linkService,
+ downloadManager: self.downloadManager,
+ };
+
+ if (self.div) {
+ // If an annotationLayer already exists, refresh its children's
+ // transformation matrices.
+ PDFJS.AnnotationLayer.update(parameters);
+ } else {
+ // Create an annotation layer div and render the annotations
+ // if there is at least one annotation.
+ if (annotations.length === 0) {
+ return;
+ }
+
+ self.div = self.annotationDiv;
+ parameters.div = self.div;
+
+ PDFJS.AnnotationLayer.render(parameters);
+ }
+ });
+};
+
+PDFJS.Reader.AnnotationLayerController.prototype.hide = function () {
+
+ if (!this.div) {
+ return;
+ }
+
+ this.div.setAttribute('hidden', 'true');
+};
diff --git a/files_reader/vendor/pdfjs/controllers/bookmarks_controller.js b/files_reader/vendor/pdfjs/controllers/bookmarks_controller.js
index ff92a08..6eda789 100644
--- a/files_reader/vendor/pdfjs/controllers/bookmarks_controller.js
+++ b/files_reader/vendor/pdfjs/controllers/bookmarks_controller.js
@@ -1,6 +1,7 @@
PDFJS.reader.BookmarksController = function() {
var reader = this,
+ eventBus = this.eventBus,
book = this.book,
annotations = reader.settings.annotations;
@@ -18,38 +19,68 @@ PDFJS.reader.BookmarksController = function() {
var addBookmarkItem = function (bookmark) {
$list.append(reader.NotesController.createItem(bookmark));
+ reader.settings.session.setBookmark(bookmark.id, bookmark.anchor, bookmark.type, bookmark);
+ };
+
+ var addBookmark = function (pageNum) {
+ var bookmark = new reader.Annotation(
+ "bookmark",
+ pageNum,
+ null,
+ pageToId(pageNum)
+ );
+
+ addBookmarkItem(bookmark);
+ };
+
+ var removeBookmark = function (pageNum) {
+ var id = pageToId(pageNum);
+ console.log("ID", id);
+
+ if (isBookmarked(id)) {
+ delete reader.settings.annotations[id];
+ reader.settings.session.deleteBookmark(id);
+ if (id === pageToId(reader.settings.currentPage)) {
+ $bookmark
+ .removeClass("icon-turned_in")
+ .addClass("icon-turned_in_not");
+ }
+ }
+ };
+
+ eventBus.on('bookmarkremoved', function removeBookmark1(e) {
+ var id = e.id,
+ $item = $("#"+id);
+
+ $item.remove();
+
+ if (id === pageToId(reader.settings.currentPage)) {
+ $bookmark
+ .removeClass("icon-turned_in")
+ .addClass("icon-turned_in_not");
+ }
+ });
+
+ var pageToId = function (pageNum) {
+ return "page_" + pageNum;
+ };
+
+ var isBookmarked = function (pageNum) {
+ return (reader.settings.annotations[pageToId(pageNum)] !== undefined);
};
for (var bookmark in annotations) {
if (annotations.hasOwnProperty(bookmark) && (annotations[bookmark].type === "bookmark"))
addBookmarkItem(annotations[bookmark]);
};
-
- this.on("reader:bookmarkcreated", function (bookmark) {
- addBookmarkItem(bookmark);
- });
-
- this.on("reader:bookmarkremoved", function (id) {
- var $item = $("#"+id),
- cfi = reader.book.getCurrentLocationCfi(),
- cfi_id = reader.cfiToId(cfi);
-
- $item.remove();
-
- if(cfi_id === id) {
- $bookmark
- .removeClass("icon-turned_in")
- .addClass("icon-turned_in_not");
- }
- });
-
- this.on("reader:gotobookmark", function (bookmark) {
- if (bookmark && bookmark.value)
- book.gotoCfi(bookmark.value);
- });
return {
"show" : show,
- "hide" : hide
+ "hide" : hide,
+ "addItem" : addBookmarkItem,
+ "addBookmark" : addBookmark,
+ "removeBookmark" : removeBookmark,
+ "pageToId" : pageToId,
+ "isBookmarked" : isBookmarked
};
};
diff --git a/files_reader/vendor/pdfjs/controllers/controls_controller.js b/files_reader/vendor/pdfjs/controllers/controls_controller.js
index b23c2c6..9afdeed 100644
--- a/files_reader/vendor/pdfjs/controllers/controls_controller.js
+++ b/files_reader/vendor/pdfjs/controllers/controls_controller.js
@@ -121,15 +121,16 @@ PDFJS.reader.ControlsController = function(book) {
});
$bookmark.on("click", function() {
- var cfi = reader.book.getCurrentLocationCfi();
+ var currentPage = reader.settings.currentPage,
+ bmc = reader.BookmarksController;
- if(!(reader.isBookmarked(cfi))) { //-- Add bookmark
- reader.addBookmark(cfi);
+ if(!bmc.isBookmarked(currentPage)) { //-- Add bookmark
+ bmc.addBookmark(currentPage);
$bookmark
.addClass("icon-turned_in")
.removeClass("icon-turned_in_not");
} else { //-- Remove Bookmark
- reader.removeBookmark(cfi);
+ bmc.removeBookmark(currentPage);
$bookmark
.removeClass("icon-turned_in")
.addClass("icon-turned_in_not");
diff --git a/files_reader/vendor/pdfjs/controllers/notes_controller.js b/files_reader/vendor/pdfjs/controllers/notes_controller.js
index 6a5a612..3db8e9a 100644
--- a/files_reader/vendor/pdfjs/controllers/notes_controller.js
+++ b/files_reader/vendor/pdfjs/controllers/notes_controller.js
@@ -1,4 +1,4 @@
-PDFJS.reader.NotesController = function() {
+PDFJS.reader.NotesController = function(book) {
var book = this.book,
reader = this,
@@ -9,10 +9,10 @@ PDFJS.reader.NotesController = function() {
$next = $("#next"),
$prev = $("#prev"),
$touch_nav = $("#touch_nav"),
+ $viewer = $("#viewer"),
annotations = reader.settings.annotations,
renderer = book.renderer,
- popups = [],
- epubcfi = new PDFJS.EpubCFI();
+ popups = [];
var show = function() {
$notesView.addClass('open');
@@ -31,8 +31,8 @@ PDFJS.reader.NotesController = function() {
var range,
textNode,
offset,
- doc = book.renderer.doc,
- cfi,
+ doc = document,
+ loc,
annotation;
// standard
@@ -47,6 +47,9 @@ PDFJS.reader.NotesController = function() {
offset = range.startOffset;
}
+ console.log("textNode", textNode, "offset", offset);
+ console.log(e);
+
if (textNode.nodeType !== 3) {
for (var i=0; i < textNode.childNodes.length; i++) {
if (textNode.childNodes[i].nodeType == 3) {
@@ -64,9 +67,9 @@ PDFJS.reader.NotesController = function() {
offset += 1; // After the period
}
- cfi = epubcfi.generateCfiFromTextNode(textNode, offset, book.renderer.currentChapter.cfiBase);
+ loc = "";
- annotation = new reader.Annotation('annotation', cfi, $text.val());
+ annotation = new reader.Annotation('annotation', loc, $text.val());
// save...
reader.addAnnotation(annotation);
@@ -87,6 +90,16 @@ PDFJS.reader.NotesController = function() {
var addAnnotationItem = function(annotation) {
$notes.append(createItem(annotation));
+ reader.settings.session.setBookmark(annotation.id, annotation.anchor, annotation.type, annotation);
+ };
+
+ var removeAnnotation = function (id) {
+
+ if (annotations[id] !== undefined) {
+ deleteAnnotationItem(id);
+ delete annotations[id];
+ reader.settings.session.deleteBookmark(id);
+ }
};
var deleteAnnotationItem = function (id) {
@@ -133,24 +146,14 @@ PDFJS.reader.NotesController = function() {
link.href = "#"+annotation.anchor;
link.onclick = function(){
- book.gotoCfi(annotation.anchor);
+ reader.queuePage(annotation.anchor);
return false;
};
del.onclick = function() {
var id = this.parentNode.parentNode.getAttribute("id");
- //var marker = book.renderer.doc.getElementById("note-" + id);
- // remove note from collection...
- //reader.removeAnnotation(id);
- // ... and remove the marker...
- //if (marker) {
- // marker.remove();
- // renumberMarkers();
- //}
- // ...and finally remove the HTML representation
- //this.parentNode.parentNode.remove();
- //renumberMarkers();
- reader.removeAnnotation(id);
+ console.log("ID", id);
+ removeAnnotation(id);
};
save.onclick = function() {
@@ -241,7 +244,7 @@ PDFJS.reader.NotesController = function() {
mark.innerHTML = findIndex(annotation.id) + "[Reader]";
marker.appendChild(mark);
- epubcfi.addMarker(annotation.anchor, doc, marker);
+ // epubcfi.addMarker(annotation.anchor, doc, marker);
markerEvents(marker, annotation.body);
renumberMarkers();
@@ -251,17 +254,17 @@ PDFJS.reader.NotesController = function() {
for (var note in annotations) {
if (annotations.hasOwnProperty(note)) {
var chapter = renderer.currentChapter;
- var cfi = epubcfi.parse(annotations[note].anchor);
- if(cfi.spinePos === chapter.spinePos) {
- try {
- var marker = book.renderer.doc.getElementById("note-" + annotations[note].id);
- if (marker !== undefined) {
- marker.innerHTML = findIndex(annotations[note].id) + "[Reader]";
- }
- } catch(e) {
- console.log("renumbering of markers failed", annotations[note].anchor);
- }
- }
+// var cfi = epubcfi.parse(annotations[note].anchor);
+// if(cfi.spinePos === chapter.spinePos) {
+// try {
+// var marker = book.renderer.doc.getElementById("note-" + annotations[note].id);
+// if (marker !== undefined) {
+// marker.innerHTML = findIndex(annotations[note].id) + "[Reader]";
+// }
+// } catch(e) {
+// console.log("renumbering of markers failed", annotations[note].anchor);
+// }
+// }
}
};
};
@@ -406,7 +409,7 @@ PDFJS.reader.NotesController = function() {
$prev.addClass("restore_touch_nav");
}
// listen for selection
- book.on("renderer:click", insertAtPoint);
+ $viewer.on("click", insertAtPoint);
} else {
$text.prop("disabled", false);
$anchor.removeClass("icon-location_off");
@@ -416,7 +419,8 @@ PDFJS.reader.NotesController = function() {
$prev.addClass("touch_nav");
$next.addClass("touch_nav");
}
- book.off("renderer:click", insertAtPoint);
+
+ $viewer.off("click", insertAtPoint);
}
});
@@ -425,36 +429,11 @@ PDFJS.reader.NotesController = function() {
addAnnotationItem(annotations[note]);
};
- this.on("reader:annotationcreated", function (note) {
- addAnnotationItem(note);
- });
-
- this.on("reader:annotationremoved", function (id) {
- deleteAnnotationItem(id);
- });
-
- // replace markers for annotations
- renderer.registerHook("beforeChapterDisplay", function(callback, renderer){
- var chapter = renderer.currentChapter;
- for (var note in annotations) {
- if (annotations.hasOwnProperty(note) && (annotations[note].type === "annotation")) {
- var cfi = epubcfi.parse(annotations[note].anchor);
- if(cfi.spinePos === chapter.spinePos) {
- try {
- placeMarker(annotations[note]);
- } catch(e) {
- console.log("anchoring failed", annotations[note].anchor);
- }
- }
- }
- };
- callback();
- }, true);
-
-
return {
"show" : show,
"hide" : hide,
- "createItem": createItem
+ "createItem": createItem,
+ "addItem" : addAnnotationItem,
+ "removeAnnotation" : removeAnnotation
};
};
diff --git a/files_reader/vendor/pdfjs/controllers/search_controller.js b/files_reader/vendor/pdfjs/controllers/search_controller.js
index e9fa9fa..d1f73d3 100644
--- a/files_reader/vendor/pdfjs/controllers/search_controller.js
+++ b/files_reader/vendor/pdfjs/controllers/search_controller.js
@@ -464,6 +464,7 @@ PDFJS.reader.SearchController = function () {
var root = document.getElementById("searchResults"),
item,
match,
+ matchlist,
i;
item = root.getElementsByClassName("selected");
@@ -472,12 +473,13 @@ PDFJS.reader.SearchController = function () {
match = document.getElementById("match:" + selected.pageIdx + ":" + selected.matchIdx);
match.classList.add("selected");
- match = document.getElementsByClassName("match:" + selected.pageIdx + ":" + selected.matchIdx);
- for (i = 0; i < match.length; i++)
- match[i].classList.add("selected_again");
-
updateMatchCounter(match.dataset.index);
+
+ //matchlist = document.getElementsByClassName("match:" + selected.pageIdx + ":" + selected.matchIdx);
+ //for (i = 0; i < matchlist.length; i++)
+ // matchlist[i].classList.add("selected_again");
+
if (!reader.isVisible(match))
match.scrollIntoView();
diff --git a/files_reader/vendor/pdfjs/css/annotation_layer_builder.css b/files_reader/vendor/pdfjs/css/annotation_layer_builder.css
new file mode 100644
index 0000000..493f555
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/annotation_layer_builder.css
@@ -0,0 +1,153 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+.annotationLayer {
+ position: absolute;
+ opacity: 0.7;
+}
+
+.annotationLayer section {
+ position: absolute;
+}
+
+.annotationLayer .linkAnnotation > a {
+ position: absolute;
+ font-size: 1em;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+}
+
+.annotationLayer .linkAnnotation > a /* -ms-a */ {
+ background: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7") 0 0 repeat;
+}
+
+.annotationLayer .linkAnnotation > a:hover {
+ opacity: 0.2;
+ background: #ff0;
+ box-shadow: 0px 2px 10px #ff0;
+}
+
+.annotationLayer .textAnnotation img {
+ position: absolute;
+ cursor: pointer;
+}
+
+.annotationLayer .textWidgetAnnotation input,
+.annotationLayer .textWidgetAnnotation textarea,
+.annotationLayer .choiceWidgetAnnotation select,
+.annotationLayer .buttonWidgetAnnotation.checkBox input,
+.annotationLayer .buttonWidgetAnnotation.radioButton input {
+ background-color: rgba(0, 54, 255, 0.13);
+ border: 1px solid transparent;
+ box-sizing: border-box;
+ font-size: 9px;
+ height: 100%;
+ padding: 0 3px;
+ vertical-align: top;
+ width: 100%;
+}
+
+.annotationLayer .textWidgetAnnotation textarea {
+ font: message-box;
+ font-size: 9px;
+ resize: none;
+}
+
+.annotationLayer .textWidgetAnnotation input[disabled],
+.annotationLayer .textWidgetAnnotation textarea[disabled],
+.annotationLayer .choiceWidgetAnnotation select[disabled],
+.annotationLayer .buttonWidgetAnnotation.checkBox input[disabled],
+.annotationLayer .buttonWidgetAnnotation.radioButton input[disabled] {
+ background: none;
+ border: 1px solid transparent;
+ cursor: not-allowed;
+}
+
+.annotationLayer .textWidgetAnnotation input:hover,
+.annotationLayer .textWidgetAnnotation textarea:hover,
+.annotationLayer .choiceWidgetAnnotation select:hover,
+.annotationLayer .buttonWidgetAnnotation.checkBox input:hover,
+.annotationLayer .buttonWidgetAnnotation.radioButton input:hover {
+ border: 1px solid #000;
+}
+
+.annotationLayer .textWidgetAnnotation input:focus,
+.annotationLayer .textWidgetAnnotation textarea:focus,
+.annotationLayer .choiceWidgetAnnotation select:focus {
+ background: none;
+ border: 1px solid transparent;
+}
+
+.annotationLayer .textWidgetAnnotation input.comb {
+ font-family: monospace;
+ padding-left: 2px;
+ padding-right: 0;
+}
+
+.annotationLayer .textWidgetAnnotation input.comb:focus {
+ /*
+ * Letter spacing is placed on the right side of each character. Hence, the
+ * letter spacing of the last character may be placed outside the visible
+ * area, causing horizontal scrolling. We avoid this by extending the width
+ * when the element has focus and revert this when it loses focus.
+ */
+ width: 115%;
+}
+
+.annotationLayer .buttonWidgetAnnotation.checkBox input,
+.annotationLayer .buttonWidgetAnnotation.radioButton input {
+ -webkit-appearance: none;
+ -moz-appearance: none;
+ -ms-appearance: none;
+ appearance: none;
+}
+
+.annotationLayer .popupWrapper {
+ position: absolute;
+ width: 20em;
+}
+
+.annotationLayer .popup {
+ position: absolute;
+ z-index: 200;
+ max-width: 20em;
+ background-color: #FFFF99;
+ box-shadow: 0px 2px 5px #333;
+ border-radius: 2px;
+ padding: 0.6em;
+ margin-left: 5px;
+ cursor: pointer;
+ word-wrap: break-word;
+}
+
+.annotationLayer .popup h1 {
+ font-size: 1em;
+ border-bottom: 1px solid #000000;
+ padding-bottom: 0.2em;
+}
+
+.annotationLayer .popup p {
+ padding-top: 0.2em;
+}
+
+.annotationLayer .highlightAnnotation,
+.annotationLayer .underlineAnnotation,
+.annotationLayer .squigglyAnnotation,
+.annotationLayer .strikeoutAnnotation,
+.annotationLayer .fileAttachmentAnnotation {
+ cursor: pointer;
+}
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-check.svg b/files_reader/vendor/pdfjs/css/images/annotation-check.svg
new file mode 100644
index 0000000..71cd16d
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-check.svg
@@ -0,0 +1,11 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-comment.svg b/files_reader/vendor/pdfjs/css/images/annotation-comment.svg
new file mode 100644
index 0000000..86f1f17
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-comment.svg
@@ -0,0 +1,16 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-help.svg b/files_reader/vendor/pdfjs/css/images/annotation-help.svg
new file mode 100644
index 0000000..00938fe
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-help.svg
@@ -0,0 +1,26 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-insert.svg b/files_reader/vendor/pdfjs/css/images/annotation-insert.svg
new file mode 100644
index 0000000..519ef68
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-insert.svg
@@ -0,0 +1,10 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-key.svg b/files_reader/vendor/pdfjs/css/images/annotation-key.svg
new file mode 100644
index 0000000..8d09d53
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-key.svg
@@ -0,0 +1,11 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-newparagraph.svg b/files_reader/vendor/pdfjs/css/images/annotation-newparagraph.svg
new file mode 100644
index 0000000..38d2497
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-newparagraph.svg
@@ -0,0 +1,11 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-noicon.svg b/files_reader/vendor/pdfjs/css/images/annotation-noicon.svg
new file mode 100644
index 0000000..c07d108
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-noicon.svg
@@ -0,0 +1,7 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-note.svg b/files_reader/vendor/pdfjs/css/images/annotation-note.svg
new file mode 100644
index 0000000..7017365
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-note.svg
@@ -0,0 +1,42 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/images/annotation-paragraph.svg b/files_reader/vendor/pdfjs/css/images/annotation-paragraph.svg
new file mode 100644
index 0000000..6ae5212
--- /dev/null
+++ b/files_reader/vendor/pdfjs/css/images/annotation-paragraph.svg
@@ -0,0 +1,16 @@
+
+
diff --git a/files_reader/vendor/pdfjs/css/sidebar.css b/files_reader/vendor/pdfjs/css/sidebar.css
index 0628315..c7ef2e1 100644
--- a/files_reader/vendor/pdfjs/css/sidebar.css
+++ b/files_reader/vendor/pdfjs/css/sidebar.css
@@ -62,7 +62,7 @@
/* font-size: 1em; */
padding: 0.4em 0.2em;
margin: 0;
- height: 100%;
+ /* height: 100%; */
}
.mobile .sidebar div > button {
diff --git a/files_reader/vendor/pdfjs/css/text_layer_builder.css b/files_reader/vendor/pdfjs/css/text_layer_builder.css
index ff5e7c8..b964737 100644
--- a/files_reader/vendor/pdfjs/css/text_layer_builder.css
+++ b/files_reader/vendor/pdfjs/css/text_layer_builder.css
@@ -19,7 +19,7 @@
top: 0;
right: 0;
bottom: 0;
- overflow: hidden;
+ /* overflow: hidden; */
opacity: 0.2;
line-height: 1.0;
}
diff --git a/files_reader/vendor/pdfjs/pdf.reader.js b/files_reader/vendor/pdfjs/pdf.reader.js
index 1ebcf75..510d3d7 100644
--- a/files_reader/vendor/pdfjs/pdf.reader.js
+++ b/files_reader/vendor/pdfjs/pdf.reader.js
@@ -41,6 +41,8 @@ PDFJS.Reader = function(bookPath, _options) {
canvasLimit: 0,
cssZoomOnly: false, // true || false, only zoom using CSS, render document at 100% size
textSelect: true, // true || false, add selectable text layer
+ annotationLayer: true, // true || false. show PDF annotations
+ mergeAnnotations: true,// true || false, merge PDF annotations into bookmarks/annotations
doubleBuffer: true, // true || false, draw to off-screen canvas
cacheNext: true, // true || false, pre-render next page (by creathing thumbnail))
numPages: 0,
@@ -86,9 +88,26 @@ PDFJS.Reader = function(bookPath, _options) {
annotations: {},
customStyles: {},
activeStyles: {},
- session: {}
+ session: {
+ getCursor: function() {},
+ setCursor: function(value) {},
+ getBookmark: function(name, type) {},
+ setBookmark: function(name, value, type, content) {},
+ getDefault: function(name) {},
+ setDefault: function(name, value) {},
+ getPreference: function(name) {},
+ setPreference: function(name, value) {}
+ }
});
+ // event bus service
+ var eventBus = new PDFJS.Reader.EventBus();
+ this.eventBus = eventBus;
+
+ // link service
+ var linkService = new PDFJS.Reader.LinkService( { eventBus: this.eventBus }, reader);
+ this.linkService = linkService;
+
// used for annotations and bookmarks
this.Annotation = function (type, anchor, body, id) {
this.id = id || PDFJS.core.uuid();
@@ -112,7 +131,9 @@ PDFJS.Reader = function(bookPath, _options) {
canvas: document.getElementById("left"),
ctx: document.getElementById("left").getContext('2d'),
textdiv: document.getElementById("text_left"),
+ annotationdiv: document.getElementById("annotations_left"),
textLayer: null,
+ annotationLayer: null,
renderTask: null,
oscanvas: null,
osctx: null,
@@ -122,7 +143,9 @@ PDFJS.Reader = function(bookPath, _options) {
canvas: document.getElementById("right"),
ctx: document.getElementById("right").getContext('2d'),
textdiv: document.getElementById("text_right"),
+ annotationdiv: document.getElementById("annotations_right"),
textLayer: null,
+ annotationLayer: null,
renderTask: null,
oscanvas: null,
osctx: null,
@@ -194,74 +217,127 @@ PDFJS.Reader = function(bookPath, _options) {
reader.ProgressController.setProgress(progress);
};
- loadingTask.then(
+ loadingTask.then(
- function(_book) {
- reader.book = book = _book;
- //console.log(book);
- reader.settings.numPages = reader.book.numPages;
- document.getElementById('total_pages').textContent = reader.settings.numPages;
- if(!$.isEmptyObject(reader.settings.session.cursor)) {
- console.log("setting cursor:", reader.settings.session.cursor);
- reader.settings.currentPage = parseInt(reader.settings.session.cursor.anchor);
+ function(_book) {
+ reader.book = book = _book;
+ //console.log(book);
+ reader.settings.numPages = reader.book.numPages;
+ document.getElementById('total_pages').textContent = reader.settings.numPages;
+ console.log(reader.settings);
+ console.log("numPages",reader.settings.numPages);
+ console.log("cursor",reader.settings.session.cursor);
+ if(!$.isEmptyObject(reader.settings.session.cursor)
+ && (reader.settings.session.cursor.value !== null)
+ && (reader.settings.session.cursor.value < reader.settings.numPages)) {
+ console.log("setting cursor:", reader.settings.session.cursor);
+ reader.settings.currentPage = parseInt(reader.settings.session.cursor.value);
+ }
+
+ var firstPagePromise = book.getPage(1);
+ reader.firstPagePromise = firstPagePromise;
+
+ reader.linkService.setDocument(book, location.href.split('#')[0]);
+
+ // set labels
+ reader.book.getPageLabels().then(function (labels) {
+ if (labels) {
+ for (var i = 0; i < labels.length; i++) {
+ if (labels[i] !== (i + 1).toString()) {
+ reader.pageLabels[i + 1] = labels[i];
+ }
+ }
+ }
+ });
+
+ reader.ReaderController = PDFJS.reader.ReaderController.call(reader, book);
+ reader.SettingsController = PDFJS.reader.SettingsController.call(reader, book);
+ reader.ControlsController = PDFJS.reader.ControlsController.call(reader, book);
+ reader.SidebarController = PDFJS.reader.SidebarController.call(reader, book);
+
+ reader.queuePage(reader.settings.currentPage);
+ reader.ReaderController.hideLoader();
+ reader.ProgressController.hide();
+
+ reader.book.getOutline().then(function (outline) {
+ reader.OutlineController = PDFJS.reader.OutlineController.call(reader, outline);
+ });
+ reader.book.getMetadata().then(function (metadata) {
+ console.log("metadata", metadata);
+ reader.settings.pdfMetadata = metadata;
+ });
+ reader.book.getAttachments().then(function (attachments) {
+ console.log("attachments", attachments);
+ });
+
+ reader.book.getStats().then(function (stats) {
+ console.log("stats", stats);
+ });
+
+ // BookmarksController depends on NotesController so load NotesController first
+ reader.NotesController = PDFJS.reader.NotesController.call(reader, book);
+ reader.BookmarksController = PDFJS.reader.BookmarksController.call(reader, book);
+
+ if (reader.settings.mergeAnnotations) {
+ reader.firstPagePromise.then(function() {
+ var numPages = reader.settings.numPages;
+
+ function extractAnnotations(pageIndex) {
+ reader.book.getPage(pageIndex).then(function(page) {
+ page.getAnnotations().then(function(annotations) {
+ if (annotations.length > 0) {
+ for (var annotation in annotations) {
+ if (annotations.hasOwnProperty(annotation) && !annotations[annotation].parentId) {
+ var ann = annotations[annotation],
+ type = (ann.contents && ann.contents !== "") ? "annotation" : "bookmark",
+ item;
+
+ item = new reader.Annotation(
+ type,
+ pageIndex,
+ ann.contents,
+ ann.id || PDFJS.core.uuid()
+ );
+ console.log(ann);
+
+ if (type === "annotation") {
+ reader.NotesController.addItem(item);
+ } else {
+ reader.BookmarksController.addItem(item);
+ }
+ }
+ }
+ }
+ });
+
+ if ((pageIndex + 1) <= reader.settings.numPages) {
+ extractAnnotations(pageIndex + 1);
+ }
+ });
+ }
+ extractAnnotations(1);
+ });
}
- var firstPagePromise = book.getPage(1);
- reader.firstPagePromise = firstPagePromise;
+ reader.SearchController = PDFJS.reader.SearchController.call(reader, book);
+ //reader.MetaController = PDFJS.reader.MetaController.call(reader, meta);
+ reader.TocController = PDFJS.reader.TocController.call(reader, book);
+ },
+ function getDocumentError(exception) {
+ var message = exception && exception.message;
+ var errormsg = "An error occurred while loading the PDF";
+ if (exception instanceof PDFJS.InvalidPDFException) {
+ errormsg = "Invalid or corrupted PDF file";
+ } else if (exception instanceof PDFJS.MissingPDFException) {
+ errormsg = "Missing PDF file";
+ } else if (exception instanceof PDFJS.UnexpectedResponseException) {
+ errormsg = "Unexpected server response";
+ }
- // set labels
- reader.book.getPageLabels().then(function (labels) {
- if (labels) {
- for (var i = 0; i < labels.length; i++) {
- if (labels[i] !== (i + 1).toString()) {
- reader.pageLabels[i + 1] = labels[i];
- }
- }
- }
- });
-
- reader.ReaderController = PDFJS.reader.ReaderController.call(reader, book);
- reader.SettingsController = PDFJS.reader.SettingsController.call(reader, book);
- reader.ControlsController = PDFJS.reader.ControlsController.call(reader, book);
- reader.SidebarController = PDFJS.reader.SidebarController.call(reader, book);
-
- reader.queuePage(reader.settings.currentPage);
- reader.ReaderController.hideLoader();
- reader.ProgressController.hide();
-
- reader.book.getOutline().then(function (outline) {
- reader.OutlineController = PDFJS.reader.OutlineController.call(reader, outline);
- });
- reader.book.getMetadata().then(function (metadata) {
- console.log("metadata", metadata);
- reader.settings.pdfMetadata = metadata;
- });
- reader.book.getAttachments().then(function (attachments) {
- console.log("attachments", attachments);
- });
-
- // BookmarksController depends on NotesController so load NotesController first
- //reader.NotesController = PDFJS.reader.NotesController.call(reader, book);
- //reader.BookmarksController = PDFJS.reader.BookmarksController.call(reader, book);
- reader.SearchController = PDFJS.reader.SearchController.call(reader, book);
- //reader.MetaController = PDFJS.reader.MetaController.call(reader, meta);
- reader.TocController = PDFJS.reader.TocController.call(reader, book);
- },
- function getDocumentError(exception) {
- var message = exception && exception.message;
- var errormsg = "An error occurred while loading the PDF";
- if (exception instanceof PDFJS.InvalidPDFException) {
- errormsg = "Invalid or corrupted PDF file";
- } else if (exception instanceof PDFJS.MissingPDFException) {
- errormsg = "Missing PDF file";
- } else if (exception instanceof PDFJS.UnexpectedResponseException) {
- errormsg = "Unexpected server response";
- }
-
- console.log("Reader: ", errormsg);
- reader.ProgressController.setMessage(errormsg, "download", "error");
- }
- );
+ console.log("Reader: ", errormsg);
+ reader.ProgressController.setMessage(errormsg, "download", "error");
+ }
+);
return this;
};
@@ -395,6 +471,10 @@ PDFJS.Reader.prototype.cancelRender = function (index) {
resourcelst.textLayer.cancel();
resourcelst.textLayer = null;
}
+
+ if (resourcelst.annotationLayer) {
+ resourcelst.annotationLayer = null;
+ }
};
PDFJS.Reader.prototype.renderPage = function(pageNum) {
@@ -408,6 +488,7 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
oscanvas, // off-screen canvas
osctx, // off-screen context
textdiv,
+ annotationdiv,
textLayer,
outputscale,
max_view_width,
@@ -431,15 +512,17 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
resourcelst,
swap_orientation,
double_buffer,
- cache_next;
+ cache_next,
+ pageShift;
max_view_width = window.innerWidth;
max_view_height = window.innerHeight;
if (this.settings.zoomLevel === "spread") {
- // show second canvas
+ // show second canvas and textlayer
reader.resourcelst[1].canvas.style.display = "block";
+ reader.resourcelst[1].textdiv.style.display = "block";
max_view_width /= 2;
// select canvas and ctx based on pageNum, pageShift and oddPageRight
pageShift = 2;
@@ -449,10 +532,15 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
} else {
index = 0;
+ pageShift = 1;
// hide second canvas
reader.resourcelst[1].canvas.style.display = "none";
+ // hide second text layer
+ reader.resourcelst[1].textdiv.style.display = "none";
// clear text layer
reader.resourcelst[1].textdiv.innerHTML = "";
+ // clear annotation layer
+ reader.resourcelst[1].annotationdiv.innerHTML = "";
// clear page number
reader.resourcelst[1].pageNum = null;
@@ -468,12 +556,14 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
canvas = resourcelst.canvas;
ctx = resourcelst.ctx;
textdiv = resourcelst.textdiv;
+ annotationdiv = resourcelst.annotationdiv;
outputscale = reader.getOutputScale(resourcelst.ctx);
fraction = reader.approximateFraction(outputscale);
double_buffer = reader.settings.doubleBuffer;
cache_next = reader.settings.cacheNext;
textdiv.innerHTML = "";
+ annotationdiv.innerHTML = "";
if (pageNum <= this.settings.numPages && pageNum >= 1) {
@@ -487,12 +577,20 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
resourcelst.textLayer = null;
}
+ if (resourcelst.annotationLayer) {
+ //resourcelst.annotationLayer.hide();
+ resourcelst.annotationLayer = null;
+ }
+
resourcelst.pageNum = pageNum;
if (reader.cancelPage[pageNum])
delete reader.cancelPage[pageNum];
this.book.getPage(pageNum).then(function(page) {
+ page.getAnnotations().then(function (annotations) {
+ console.log("annotations", annotations);
+ });
//console.log(page);
page_rotation = page.rotate;
rotation = (page_rotation + reader.settings.rotation) % 360;
@@ -576,9 +674,6 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
}
}
- //console.log("outputscale: " + outputscale);
- //console.log("canvas w x h: " + canvas.width + " x " + canvas.height);
-
transform = (outputscale === 1)
? null
: [outputscale, 0, 0, outputscale, 0, 0];
@@ -595,7 +690,7 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
/* textlayer */
if (reader.settings.textSelect) {
textdiv.style.width = reader.roundToDivide(viewport.width, fraction[1]) + 'px';
- textdiv.style.height = reader.roundToDivide(viewport.height, fraction[1]) + 'px';
+ textdiv.style.height = 0;
offset = $(canvas).offset();
$(textdiv).offset({
top: offset.top,
@@ -613,9 +708,29 @@ PDFJS.Reader.prototype.renderPage = function(pageNum) {
} else {
resourcelst.textLayer = textLayer = null;
}
-
/* /textLayer */
+ /* annotationLayer */
+ if (reader.settings.annotationLayer) {
+ annotationdiv.style.width = reader.roundToDivide(viewport.width, fraction[1]) + 'px';
+ //annotationdiv.style.height = reader.roundToDivide(viewport.height, fraction[1]) + 'px';
+ annotationdiv.style.height = 0;
+ offset = $(canvas).offset();
+ $(annotationdiv).offset({
+ top: offset.top,
+ left: offset.left
+ });
+ resourcelst.annotationLayer = new PDFJS.Reader.AnnotationLayerController({
+ annotationDiv: annotationdiv,
+ pdfPage: page,
+ renderInteractiveForms: false,
+ linkService: reader.linkService,
+ downloadManager: null
+ }, reader);
+ resourcelst.annotationLayer.render(viewport, 'display');
+ }
+ /* /annotationLayer */
+
if (double_buffer) {
resourcelst.oscanvas = oscanvas = document.createElement("canvas");
resourcelst.osctx = context = osctx = oscanvas.getContext('2d');
@@ -688,6 +803,7 @@ PDFJS.Reader.prototype.queuePage = function(page) {
reader.settings.currentPage = page;
reader.ControlsController.setCurrentPage(page);
+ reader.settings.session.setCursor(page);
if (typeof reader.renderQueue === 'number') {
window.clearTimeout(reader.renderQueue);
@@ -843,104 +959,6 @@ PDFJS.Reader.prototype.getPageLabel = function (page) {
}
};
-PDFJS.Reader.prototype.navigateTo = function (destination) {
-
- var reader = this,
- destString = "",
- destinationPromise,
- goToDestination;
-
- goToDestination = function (destRef) {
-
- var pageNumber;
-
- if (destRef instanceof Object) {
-
- pageNumber = reader.cachedPageNum(destRef);
- } else if ((destRef | 0) === destRef) { // Integer
- pageNumber = destRef + 1;
- } else {
- console.error('PDFJS.Reader.navigateTo: "' + destRef
- + '" is not a valid destination reference.');
-
- return;
- }
-
- if (pageNumber) {
-
- if (pageNumber < 1 || pageNumber > reader.settings.numPages) {
- console.error('PDFJS.Reader.navigateTo: "' + pageNumber
- + '" is a non-existent page number.');
-
- return;
- }
-
- reader.queuePage(pageNumber);
-
- } else {
-
- reader.book.getPageIndex(destRef).then(function (pageIndex) {
-
- reader.cachePageRef(pageIndex + 1, destRef);
- goToDestination(destRef);
- }).catch(function () {
- console.error('PDFJS.Reader.navigateTo: "' + destRef
- + '" is not a valid page reference.');
-
- return;
- });
- }
- };
-
- if (typeof destination === 'string') {
-
- destString = destination;
- destinationPromise = reader.book.getDestination(destination);
-
- } else {
-
- destinationPromise = Promise.resolve(destination);
-
- }
-
- destinationPromise.then(function (_destination) {
-
- destination = _destination;
-
- if (!(destination instanceof Array)) {
-
- console.error('PDFJS.Reader.navigateTo: "' + destination
- + '" is not a valid destination array.');
-
- return;
- }
-
- goToDestination(destination[0]);
-
- });
-};
-
-PDFJS.Reader.prototype.pageRefStr = function (pageRef) {
-
- return pageRef.num + ' ' + pageRef.gen + ' R';
-};
-
-PDFJS.Reader.prototype.cachePageRef = function (pageNum, pageRef) {
-
- var reader = this,
- refStr;
-
- reader.pageRefs[reader.pageRefStr(pageRef)] = pageNum;
-};
-
-PDFJS.Reader.prototype.cachedPageNum = function (pageRef) {
-
- var reader = this;
-
- return (reader.pageRefs[reader.pageRefStr(pageRef)])
- || null;
-};
-
PDFJS.Reader.prototype.getPageTextContent = function (pageIndex) {
var reader = this,
@@ -953,28 +971,6 @@ PDFJS.Reader.prototype.getPageTextContent = function (pageIndex) {
});
};
-PDFJS.Reader.prototype.getDestinationHash = function (destination) {
-
- var url = location.href.split('#')[0],
- str;
-
- if (typeof destination === 'string') {
-
- url += "#"
- + (parseInt(destination) === destination)
- ? "nameddest="
- : ""
- + escape(destination);
-
- } else if (destination instanceof Array) {
-
- url += "#"
- + escape(JSON.stringify(destination));
- }
-
- return url;
-};
-
PDFJS.Reader.prototype.setStyles = function (element, item) {
var styleStr = "";
@@ -996,6 +992,7 @@ PDFJS.Reader.prototype.setStyles = function (element, item) {
PDFJS.Reader.prototype.bindLink = function (element, item) {
var reader = this,
+ linkService = this.linkService,
destination = item.dest;
if (item.url) {
@@ -1010,10 +1007,12 @@ PDFJS.Reader.prototype.bindLink = function (element, item) {
return;
} else {
- element.href = reader.getDestinationHash(destination);
+ //element.href = reader.getDestinationHash(destination);
+ element.href = linkService.getDestinationHash(destination);
element.onclick = function () {
if (destination) {
- reader.navigateTo(destination);
+ //reader._navigateTo(destination);
+ linkService.navigateTo(destination);
}
return false;
diff --git a/files_reader/vendor/pdfjs/services/eventbus_service.js b/files_reader/vendor/pdfjs/services/eventbus_service.js
new file mode 100644
index 0000000..efcffc6
--- /dev/null
+++ b/files_reader/vendor/pdfjs/services/eventbus_service.js
@@ -0,0 +1,39 @@
+PDFJS.Reader.EventBus = function () {
+
+ this._listeners = Object.create(null);
+
+ return this;
+};
+
+PDFJS.Reader.EventBus.prototype.on = function (eventName, listener) {
+ var eventListeners = this._listeners[eventName];
+ if (!eventListeners) {
+ eventListeners = [];
+ this._listeners[eventName] = eventListeners;
+ }
+ eventListeners.push(listener);
+};
+
+PDFJS.Reader.EventBus.prototype.off = function (eventName, listener) {
+ var eventListeners = this._listeners[eventName];
+ var i;
+ if (!eventListeners || ((i = eventListeners.indexOf(listener)) < 0)) {
+ return;
+ }
+ eventListeners.splice(i, 1);
+};
+
+PDFJS.Reader.EventBus.prototype.dispatch = function (eventName) {
+ var eventListeners = this._listeners[eventName];
+ if (!eventListeners || eventListeners.length === 0) {
+ return;
+ }
+ // Passing all arguments after the eventName to the listeners.
+ var args = Array.prototype.slice.call(arguments, 1);
+ // Making copy of the listeners array in case if it will be modified
+ // during dispatch.
+ eventListeners.slice(0).forEach(function (listener) {
+ listener.apply(null, args);
+ });
+};
+
diff --git a/files_reader/vendor/pdfjs/services/link_service.js b/files_reader/vendor/pdfjs/services/link_service.js
new file mode 100644
index 0000000..17fc545
--- /dev/null
+++ b/files_reader/vendor/pdfjs/services/link_service.js
@@ -0,0 +1,360 @@
+PDFJS.Reader.LinkService = function (options, reader) {
+
+ options = options || {};
+
+ this.eventBus = options.eventBus || reader.eventBus;
+ this.reader = reader;
+ this.baseUrl = null;
+ this.pdfDocument = null;
+ this.pdfHistory = null;
+ this.pageRefs = null;
+
+ return this;
+};
+
+Object.defineProperties(PDFJS.Reader.LinkService, {
+ 'pagesCount': {
+ get: function () { return this.pdfDocument ? this.pdfDocument.numPages : 0; }
+ },
+ 'page': {
+ get: function () { return reader.settings.currentPage; },
+ set: function(value) { reader.settings.currentPage = value; }
+ }
+});
+
+PDFJS.Reader.LinkService.prototype.setDocument = function (pdfDocument, baseUrl) {
+
+ this.baseUrl = baseUrl;
+ this.pdfDocument = pdfDocument;
+ this.pageRefs = Object.create(null);
+};
+
+PDFJS.Reader.LinkService.prototype.setHistory = function (pdfHistory) {
+
+ this.pdfHistory = pdfHistory;
+};
+
+PDFJS.Reader.LinkService.prototype.navigateTo = function (destination) {
+
+ var self = this,
+ destString = "",
+ destinationPromise,
+ goToDestination;
+
+ goToDestination = function (destRef) {
+
+ var pageNumber;
+
+ if (destRef instanceof Object) {
+ pageNumber = self._cachedPageNum(destRef);
+ } else if ((destRef | 0) === destRef) { // Integer
+ pageNumber = destRef + 1;
+ } else {
+ console.error('PDFJS.Reader.LinkService.navigateTo: "' + destRef
+ + '" is not a valid destination reference.');
+
+ return;
+ }
+
+ if (pageNumber) {
+
+ if (pageNumber < 1 || pageNumber > self.pagesCount) {
+ console.error('PDFJS.Reader.LinkService.navigateTo: "' + pageNumber
+ + '" is a non-existent page number.');
+
+ return;
+ }
+
+ self.reader.queuePage(pageNumber);
+
+ } else {
+
+ self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
+ self.cachePageRef(pageIndex + 1, destRef);
+ goToDestination(destRef);
+ }).catch(function () {
+ console.error('PDFJS.Reader.LinkService.navigateTo: "', destRef,
+ '" is not a valid page reference.');
+
+ return;
+ });
+ }
+ };
+
+ if (typeof destination === 'string') {
+
+ destString = destination;
+ destinationPromise = self.pdfDocument.getDestination(destination);
+
+ } else {
+
+ destinationPromise = Promise.resolve(destination);
+
+ }
+
+ destinationPromise.then(function (_destination) {
+
+ destination = _destination;
+
+ if (!(destination instanceof Array)) {
+
+ console.error('PDFJS.Reader.LinkService.navigateTo: "' + destination
+ + '" is not a valid destination array.');
+
+ return;
+ }
+ goToDestination(destination[0]);
+
+ });
+};
+
+PDFJS.Reader.LinkService.prototype.getDestinationHash = function (destination) {
+
+ var url = this.baseUrl,
+ str;
+
+ if (typeof destination === 'string') {
+
+ url += "#"
+ + (parseInt(destination) === destination)
+ ? "nameddest="
+ : ""
+ + escape(destination);
+
+ } else if (destination instanceof Array) {
+
+ url += "#"
+ + escape(JSON.stringify(destination));
+ }
+
+ return url;
+};
+
+PDFJS.Reader.LinkService.prototype.setHash = function (hash) {
+ var reader = this,
+ pageNumber,
+ dest;
+
+ if (hash.indexOf('=') >= 0) {
+ var params = parseQueryString(hash);
+ if ('search' in params) {
+ this.eventBus.dispatch('findfromurlhash', {
+ source: this,
+ query: params['search'].replace(/"/g, ''),
+ phraseSearch: (params['phrase'] === 'true')
+ });
+ }
+ // borrowing syntax from "Parameters for Opening PDF Files"
+ if ('nameddest' in params) {
+ if (this.pdfHistory) {
+ this.pdfHistory.updateNextHashParam(params.nameddest);
+ }
+ this.navigateTo(params.nameddest);
+ return;
+ }
+ if ('page' in params) {
+ pageNumber = (params.page | 0) || 1;
+ }
+ if ('zoom' in params) {
+ // Build the destination array.
+ var zoomArgs = params.zoom.split(','); // scale,left,top
+ var zoomArg = zoomArgs[0];
+ var zoomArgNumber = parseFloat(zoomArg);
+
+ if (zoomArg.indexOf('Fit') === -1) {
+ // If the zoomArg is a number, it has to get divided by 100. If it's
+ // a string, it should stay as it is.
+ dest = [null, { name: 'XYZ' },
+ zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null,
+ zoomArgs.length > 2 ? (zoomArgs[2] | 0) : null,
+ (zoomArgNumber ? zoomArgNumber / 100 : zoomArg)];
+ } else {
+ if (zoomArg === 'Fit' || zoomArg === 'FitB') {
+ dest = [null, { name: zoomArg }];
+ } else if ((zoomArg === 'FitH' || zoomArg === 'FitBH') ||
+ (zoomArg === 'FitV' || zoomArg === 'FitBV')) {
+ dest = [null, { name: zoomArg },
+ zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null];
+ } else if (zoomArg === 'FitR') {
+ if (zoomArgs.length !== 5) {
+ console.error('PDFLinkService_setHash: ' +
+ 'Not enough parameters for \'FitR\'.');
+ } else {
+ dest = [null, { name: zoomArg },
+ (zoomArgs[1] | 0), (zoomArgs[2] | 0),
+ (zoomArgs[3] | 0), (zoomArgs[4] | 0)];
+ }
+ } else {
+ console.error('PDFLinkService_setHash: \'' + zoomArg +
+ '\' is not a valid zoom value.');
+ }
+ }
+ }
+ if (dest) {
+
+ reader.queuePage(pageNumber || this.page);
+
+ } else if (pageNumber) {
+ this.page = pageNumber; // simple page
+ }
+ if ('pagemode' in params) {
+ this.eventBus.dispatch('pagemode', {
+ source: this,
+ mode: params.pagemode
+ });
+ }
+ } else { // Named (or explicit) destination.
+ if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
+ isPageNumber(hash) && hash <= this.pagesCount) {
+ console.warn('PDFLinkService_setHash: specifying a page number ' +
+ 'directly after the hash symbol (#) is deprecated, ' +
+ 'please use the "#page=' + hash + '" form instead.');
+ this.page = hash | 0;
+ }
+
+ dest = unescape(hash);
+ try {
+ dest = JSON.parse(dest);
+
+ if (!(dest instanceof Array)) {
+ // Avoid incorrectly rejecting a valid named destination, such as
+ // e.g. "4.3" or "true", because `JSON.parse` converted its type.
+ dest = dest.toString();
+ }
+ } catch (ex) {}
+
+ if (typeof dest === 'string' || this.isValidExplicitDestination(dest)) {
+ if (this.pdfHistory) {
+ this.pdfHistory.updateNextHashParam(dest);
+ }
+ this.navigateTo(dest);
+ return;
+ }
+ console.error('PDFLinkService_setHash: \'' + unescape(hash) +
+ '\' is not a valid destination.');
+ }
+};
+
+PDFJS.Reader.LinkService.prototype.executeNamedAction = function (action) {
+ // See PDF reference, table 8.45 - Named action
+ switch (action) {
+ case 'GoBack':
+ if (this.pdfHistory) {
+ this.pdfHistory.back();
+ }
+ break;
+
+ case 'GoForward':
+ if (this.pdfHistory) {
+ this.pdfHistory.forward();
+ }
+ break;
+
+ case 'NextPage':
+ if (this.page < this.pagesCount) {
+ this.page++;
+ }
+ break;
+
+ case 'PrevPage':
+ if (this.page > 1) {
+ this.page--;
+ }
+ break;
+
+ case 'LastPage':
+ this.page = this.pagesCount;
+ break;
+
+ case 'FirstPage':
+ this.page = 1;
+ break;
+
+ default:
+ break; // No action according to spec
+ }
+
+ this.eventBus.dispatch('namedaction', {
+ source: this,
+ action: action
+ });
+};
+
+PDFJS.Reader.LinkService.prototype.onFileAttachmentAnnotation = function (params) {
+ this.eventBus.dispatch('fileattachmentannotation', {
+ source: this,
+ id: params.id,
+ filename: params.filename,
+ content: params.content,
+ });
+};
+
+PDFJS.Reader.LinkService.prototype.pageRefStr = function (pageRef) {
+
+ return pageRef.num + ' ' + pageRef.gen + ' R';
+};
+
+PDFJS.Reader.LinkService.prototype.cachePageRef = function (pageNum, pageRef) {
+
+ this.pageRefs[this.pageRefStr(pageRef)] = pageNum;
+};
+
+PDFJS.Reader.LinkService.prototype._cachedPageNum = function (pageRef) {
+
+ return (this.pageRefs[this.pageRefStr(pageRef)])
+ || null;
+};
+
+PDFJS.Reader.LinkService.prototype.isValidExplicitDestination = function (dest) {
+ if (!(dest instanceof Array)) {
+ return false;
+ }
+ var destLength = dest.length, allowNull = true;
+ if (destLength < 2) {
+ return false;
+ }
+ var page = dest[0];
+ if (!(typeof page === 'object' &&
+ typeof page.num === 'number' && (page.num | 0) === page.num &&
+ typeof page.gen === 'number' && (page.gen | 0) === page.gen) &&
+ !(typeof page === 'number' && (page | 0) === page && page >= 0)) {
+ return false;
+ }
+ var zoom = dest[1];
+ if (!(typeof zoom === 'object' && typeof zoom.name === 'string')) {
+ return false;
+ }
+ switch (zoom.name) {
+ case 'XYZ':
+ if (destLength !== 5) {
+ return false;
+ }
+ break;
+ case 'Fit':
+ case 'FitB':
+ return destLength === 2;
+ case 'FitH':
+ case 'FitBH':
+ case 'FitV':
+ case 'FitBV':
+ if (destLength !== 3) {
+ return false;
+ }
+ break;
+ case 'FitR':
+ if (destLength !== 6) {
+ return false;
+ }
+ allowNull = false;
+ break;
+ default:
+ return false;
+ }
+ for (var i = 2; i < destLength; i++) {
+ var param = dest[i];
+ if (!(typeof param === 'number' || (allowNull && param === null))) {
+ return false;
+ }
+ }
+ return true;
+};
diff --git a/files_reader/vendor/pdfjs/services/simple_link_service.js b/files_reader/vendor/pdfjs/services/simple_link_service.js
new file mode 100644
index 0000000..7fec0ed
--- /dev/null
+++ b/files_reader/vendor/pdfjs/services/simple_link_service.js
@@ -0,0 +1,34 @@
+PDFJS.Reader.SimpleLinkService = function () {
+
+ return this;
+};
+
+Object.defineProperties(PDFJS.Reader.SimpleLinkService, {
+ 'page': {
+ get: function () { return 0; },
+ set: function(value) {}
+ }
+});
+
+PDFJS.Reader.SimpleLinkService.prototype.navigateTo = function (destUrl) {
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.getDestinationHash = function (destination) {
+ return "#";
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.getAnchorUrl = function (anchor) {
+ return "#";
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.setHash = function (hash) {
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.executeNamedAction = function (action) {
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.onFileAttachmentAnnotation = function (params) {
+};
+
+PDFJS.Reader.SimpleLinkService.prototype.cachePageRef = function (pageNum, pageRef) {
+};