Skip to content

Instantly share code, notes, and snippets.

@Inviz
Created March 13, 2009 21:19
Show Gist options
  • Select an option

  • Save Inviz/78769 to your computer and use it in GitHub Desktop.

Select an option

Save Inviz/78769 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PDF Annotator</title>
<script src="mootools.js"></script>
<script src="pdfviewer.js"></script>
<script>
window.addEvent('domready', function() {
$viewer = new PDFViewer(document.body, {
path: 'pdfviewer.swf',
height: 1000,
width: 1000,
onLoad: function() {
console.log(123)
},
onReady: function() {
for(var i=0; i<5; i++){
this.annotate(i,100*(i+0.5),100*(i+1),"Automatic annotation...","Dmitry"+i);
}
this.filter("Dmitry0", "Dmitry2")
}
})
})
</script>
<!-- Date: 2009-03-14 -->
</head>
<body>
</body>
</html>
var PDFViewer = new Class({
Extends: Swiff,
Implements: [Events, Options],
options: {
path: "/flashes/pdfviewer.swf",
/*
Events:
onLoad: fires on swf load
onReady: viewer is ready and loaded first few pages (happens on startup)
onRequest: started loading something (e.g. starting a new page) (viewer is busy),
onComplete: finished all current requests (viewer is idle),
onZoom(new_zoom_value): user zoomed in or out something. Required for knob position update.
onShow(page_number): "page_number" page appeared in viewpoint
onChange(page_number): user jumped to "page_number".
onAnnotateStart(x, y): user clicked at x,y to add a new comment
onAnnotateFinish(x, y, text): user typed in comment (new annotation interface is in flash)
onAnnotate(x, y, text): annotation added at x, y, text
onDeannotate(x, y, text): annotation removed from x, y. text was text
onScroll(x, y): viewport got scrolled to x, y. To be fired rapidly when user scrolls using scrollbar
onFilter(person, another_author, third_author...): user chose to show annotations only by given authors
SWF Methods (external interface):
load(path, pages): load pages from path (e.g. path is: /articles/%.png, pages is: 20. It loads /articles/1.png to /articles/20.png)
goTo(page): go to page numbered "page". Fires onChange, onReady
annotate(x, y, text, author): render annotation with text at x, y. Author is a string. Fires onAnnotate
deannotate(x, y): remove annotation at x, y. Fires onDeannotate
scrollTo(x, y): scroll canvas to x, y, Fires onScroll
zoom(measure = 1): zooms document to the given measure (1 is 100% and is default value). Fires onZoom
refresh(n = false): refresh nth page (if n == false, refresh all). Fires onRequest for each page refreshing, onComplete on each, onReady when everything is done.
forward(n = 1): scroll forward by n screens
back(n = 1): scroll back by n screens
next(n = 1): navigate forward by n pages
previous(n = 1): navigate back by n pages
filter(author, another_author, third_author...): Show only annotations by given authors (match any of strings). Fires onFilter
Settings:
annotatable(default: true). allows user to add an annotation on click
scrollbars(default: true). shows scrollbars
interface(default: true). shows interface (in case if there will be any other buttons or controls)
multiuser(default: true). shows author filter bar
Sample flash implementation:
Firing events: ExternalInterface.call(root.loaderInfo.parameters.onLoad, param1, param2);
Registering external interface function:
ExternalInterface.addCallback('goTo', goTo);
ExternalInterface.addCallback('scrollTo', scrollTo);
Getting options:
*/
params: {
annotatable: true,
scrollbars: true,
'interface': true
},
callBacks: null
},
initialize: function(wrapper, options) {
this.setOptions(options);
var callBacks = this.options.callBacks || this;
var prepare = {}, self = this;
["onLoad", "onReady", "onRequest", "onComplete", "onZoom", "onShow", "onChange", "onAnnotateStart", "onAnnotateFinish", "onAnnotate", "onDeannotate"].each(function(index) {
var fn = callBacks[index] || self[index] || $empty;
prepare[index] = function() {
self.fireEvent(index, arguments);
return fn.apply(self, arguments);
};
});
this.options.callBacks = prepare
this.parent(this.options.path);
this.inject(wrapper)
},
load: function(path, pages, a) {
this.remote('load', path, pages, a)
},
goTo: function(page) {
this.remote('goTo', page)
},
annotate: function(x, y, text) {
this.remote('annotate', x, y, text)
},
deannotate: function(x, y) {
this.remote('deannotate', x, y)
},
forward: function(x) {
this.remote('forward', x || 1)
},
backward: function(x) {
this.remote('backward', x || 1)
},
next: function(x) {
this.remote('next', x || 1)
},
previous: function(x) {
this.remote('previous', x || 1)
},
scrollTo: function(x, y) {
this.remote('scrollTo', x, y)
},
zoom: function(measure) {
this.remote('zoom', measure || 1)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment