86 lines
2.1 KiB
HTML
86 lines
2.1 KiB
HTML
<html>
|
|
<head>
|
|
<title>Simple pdf.js page viewer</title>
|
|
<script type="text/javascript"
|
|
src="pdf.js"></script>
|
|
<style type"text/css">
|
|
body {
|
|
margin: 6px;
|
|
padding: 0px;
|
|
background-color: #c0bdb7;
|
|
}
|
|
#viewer {
|
|
margin: auto;
|
|
border: 1px solid black;
|
|
width: 8.5in;
|
|
height: 11in;
|
|
}
|
|
#pageNumber {
|
|
text-align: right;
|
|
}
|
|
</style>
|
|
|
|
<script type="text/javascript">
|
|
var canvas, numPages, pageDisplay, pageNum;
|
|
function load() {
|
|
canvas = document.getElementById("canvas");
|
|
pageDisplay = document.getElementById("pageNumber");
|
|
numPages = tests.length;
|
|
displayPage(pageNum = 0);
|
|
}
|
|
|
|
function displayPage(number) {
|
|
var page = tests[number];
|
|
pageDisplay.value = number;
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
ctx.save();
|
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
ctx.restore();
|
|
|
|
var gfx = new CanvasGraphics(ctx);
|
|
var interp = new Interpreter(null, page.res, null, gfx);
|
|
interp.interpretHelper(page.mediaBox, new MockParser(page.objs));
|
|
}
|
|
|
|
function nextPage() {
|
|
pageNum = (pageNum + 1) % numPages;
|
|
displayPage(pageNum);
|
|
}
|
|
|
|
function prevPage() {
|
|
pageNum = (pageNum - 1 + numPages) % numPages;
|
|
displayPage(pageNum);
|
|
}
|
|
|
|
function profile() {
|
|
const NUM_TRIALS = 10000;
|
|
var start = Date.now();
|
|
for (var i = 0; i < NUM_TRIALS; ++i)
|
|
displayPage(pageNum);
|
|
var end = Date.now();
|
|
var elapsed = (end - start);
|
|
|
|
alert("Drawing current page "+ NUM_TRIALS +" times took "+
|
|
(elapsed / 1000.0) +" seconds, "+
|
|
"~"+ (elapsed / NUM_TRIALS) +" ms/draw (totally unscientific)");
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body onload="load();">
|
|
<div>
|
|
<button onclick="prevPage();">Previous</button>
|
|
<button onclick="nextPage();">Next</button>
|
|
<input type="text" id="pageNumber" value="0" size="5"></input>
|
|
<button onclick="profile();">Profile</button>
|
|
<div id="viewer">
|
|
<!-- Canvas dimensions must be specified in CSS pixels. CSS pixels
|
|
-- are always 96 dpi. These dimensions are 8.5x11in at 96dpi. -->
|
|
<canvas id="canvas" width="816" height="1056"></canvas>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|