forked from Submitty/pdf-annotate.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47c10c6
commit 1798c91
Showing
16 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>PDFJSAnnotate</title> | ||
</head> | ||
<body> | ||
<canvas id="canvas" style="border: 1px solid black;"></canvas> | ||
<script src="bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import __pdfjs from 'pdfjs-dist/build/pdf.js'; | ||
import PDFJSAnnotate from '../'; | ||
import annotations from './annotations'; | ||
|
||
PDFJS.workerSrc = '../node_modules/pdfjs-dist/build/pdf.worker.js'; | ||
|
||
PDFJSAnnotate.StoreAdapter.getAnnotations = (documentId, pageNumber) => { | ||
return new Promise((resolve, reject) => { | ||
resolve(annotations); | ||
}); | ||
}; | ||
|
||
PDFJS.getDocument('helloworld.pdf').then((pdf) => { | ||
Promise.all([ | ||
pdf.getPage(1), | ||
PDFJSAnnotate.getAnnotations(1) | ||
]) | ||
.then(([page, annotations]) => { | ||
let scale = 3.5; | ||
let viewport = page.getViewport(scale); | ||
let canvas = document.getElementById('canvas'); | ||
let canvasContext = canvas.getContext('2d'); | ||
|
||
canvas.height = viewport.height; | ||
canvas.width = viewport.width; | ||
|
||
page.render({canvasContext, viewport}); | ||
PDFJSAnnotate.render(viewport, annotations); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import PDFJSAnnotate from './src/PDFJSAnnotate'; | ||
|
||
export default PDFJSAnnotate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "pdf-annotate.js", | ||
"version": "0.0.0", | ||
"description": "Annotation layer for pdf.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "./node_modules/.bin/webpack-dev-server --inline --config ./webpack.example.js --content-base ./" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mzabriskie/pdf-annotate.js.git" | ||
}, | ||
"keywords": [ | ||
"pdf", | ||
"annotation" | ||
], | ||
"author": "Matt Zabriskie", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/mzabriskie/pdf-annotate.js/issues" | ||
}, | ||
"homepage": "https://github.com/mzabriskie/pdf-annotate.js#readme", | ||
"devDependencies": { | ||
"babel-core": "5.8.22", | ||
"babel-loader": "5.3.2", | ||
"pdfjs-dist": "1.1.399", | ||
"webpack": "1.11.0", | ||
"webpack-dev-server": "1.10.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import renderSVG from './render/renderSVG'; | ||
import renderDrawing from './render/renderDrawing'; | ||
|
||
export default class AnnotateView { | ||
constructor(viewport, annotations) { | ||
this.viewport = viewport; | ||
this.annotations = annotations; | ||
} | ||
|
||
render() { | ||
let svg = renderSVG(this.viewport); | ||
|
||
this.annotations.forEach((a) => { | ||
let el; | ||
switch (a.type) { | ||
case 'drawing': | ||
el = renderDrawing(a); | ||
break; | ||
} | ||
|
||
svg.appendChild(el); | ||
}); | ||
|
||
document.body.appendChild(svg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import StoreAdapter from './StoreAdapter'; | ||
import AnnotateView from './AnnotateView'; | ||
|
||
// Public API | ||
let PDFJSAnnotate = { | ||
StoreAdapter, | ||
|
||
getAnnotations(documentId, pageNumber) { | ||
return this.StoreAdapter.getAnnotations(documentId, pageNumber); | ||
}, | ||
|
||
render(viewport, annotations) { | ||
let view = new AnnotateView(viewport, annotations); | ||
view.render(); | ||
} | ||
}; | ||
|
||
export default PDFJSAnnotate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import abstractFunction from './utils/abstractFunction'; | ||
|
||
// Adapter should never be invoked publicly | ||
let StoreAdapter = { | ||
getAnnotations: abstractFunction('getAnnotations'), | ||
addAnnotation: abstractFunction('addAnnotation'), | ||
editAnnotation: abstractFunction('editAnnotation'), | ||
deleteAnnotation: abstractFunction('deleteAnnotation') | ||
}; | ||
|
||
export default StoreAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function renderDrawing(a) { | ||
let d = []; | ||
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); | ||
|
||
for (let i=0, l=a.lines.length; i<l; i++) { | ||
var p1 = a.lines[i]; | ||
var p2 = a.lines[i+1]; | ||
if (p2) { | ||
d.push('M' + p1[0] + ' ' + p1[1] + ' ' + p2[0] + ' ' + p2[1]); | ||
} | ||
} | ||
|
||
path.setAttribute('d', d.join(',') + 'Z'); | ||
path.setAttribute('stroke', '#' + a.color); | ||
path.setAttribute('fill', 'none'); | ||
|
||
return path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default function renderSVG(viewport) { | ||
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); | ||
|
||
svg.style.display = 'block'; | ||
svg.style.position = 'absolute'; | ||
svg.style.top = viewport.offsetY + 'px'; | ||
svg.style.left = viewport.offsetX + 'px'; | ||
svg.style.width = viewport.width + 'px'; | ||
svg.style.height = viewport.height + 'px'; | ||
// svg.style.background = 'rgba(0, 0, 0, .2)'; | ||
|
||
return svg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default function abstractFunction(name) { | ||
return function () { | ||
throw new Error(name + ' is not implemented'); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default function uuid() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | ||
return v.toString(16); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
entry: './index.js', | ||
output: { | ||
filename: 'dist/pdf-annotate.js', | ||
library: 'PDFAnnotate', | ||
libraryTarget: 'umd' | ||
}, | ||
module: { | ||
loaders: [ | ||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' } | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
entry: './example/index.js', | ||
output: { | ||
filename: './example/bundle.js', | ||
}, | ||
module: { | ||
loaders: [ | ||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' } | ||
] | ||
} | ||
}; | ||
|