2014-09-16 23:24:48 +09:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<title>'Hello, world!' example</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1>'Hello, world!' example</h1>
|
|
|
|
|
2020-01-12 20:25:23 +09:00
|
|
|
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
|
2014-09-16 23:24:48 +09:00
|
|
|
|
2017-05-11 08:28:18 +09:00
|
|
|
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
|
2014-09-16 23:24:48 +09:00
|
|
|
|
|
|
|
<script id="script">
|
|
|
|
//
|
|
|
|
// If absolute URL from the remote server is provided, configure the CORS
|
|
|
|
// header on that server.
|
|
|
|
//
|
|
|
|
var url = './helloworld.pdf';
|
|
|
|
|
|
|
|
//
|
2015-11-06 22:39:13 +09:00
|
|
|
// The workerSrc property shall be specified.
|
2014-09-16 23:24:48 +09:00
|
|
|
//
|
2018-03-16 05:49:28 +09:00
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
2018-02-14 22:49:24 +09:00
|
|
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
2014-09-16 23:24:48 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// Asynchronous download PDF
|
|
|
|
//
|
2018-11-08 21:40:06 +09:00
|
|
|
var loadingTask = pdfjsLib.getDocument(url);
|
|
|
|
loadingTask.promise.then(function(pdf) {
|
2014-09-16 23:24:48 +09:00
|
|
|
//
|
|
|
|
// Fetch the first page
|
|
|
|
//
|
2018-11-08 21:40:06 +09:00
|
|
|
pdf.getPage(1).then(function(page) {
|
2014-09-16 23:24:48 +09:00
|
|
|
var scale = 1.5;
|
2018-12-24 20:28:20 +09:00
|
|
|
var viewport = page.getViewport({ scale: scale, });
|
2014-09-16 23:24:48 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// Prepare canvas using PDF page dimensions
|
|
|
|
//
|
|
|
|
var canvas = document.getElementById('the-canvas');
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
canvas.height = viewport.height;
|
|
|
|
canvas.width = viewport.width;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render PDF page into canvas context
|
|
|
|
//
|
|
|
|
var renderContext = {
|
|
|
|
canvasContext: context,
|
2018-12-24 20:28:20 +09:00
|
|
|
viewport: viewport,
|
2014-09-16 23:24:48 +09:00
|
|
|
};
|
|
|
|
page.render(renderContext);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
<h2>JavaScript code:</h2>
|
|
|
|
<pre id="code"></pre>
|
|
|
|
<script>
|
|
|
|
document.getElementById('code').textContent =
|
|
|
|
document.getElementById('script').text;
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|