我使用pdf.js庫從客戶端上的PDF頁面製作圖像/畫布。但它只適用於FireFox,不適用於Chrome或IE10 +。我環顧四周,但找不到一個好的答案或解決方案。pdfjs到img/canvas,僅適用於FireFox
我在IE或Chrome上閱讀pdf.js需要一個web服務器,但是當我嘗試JSFiddle上的代碼時,它仍然不起作用。
這裏是一個例子:https://jsfiddle.net/aqxwsfjo/2/
var url = 'https://raw.githubusercontent.com/mozilla/pdf.js/master/examples/helloworld/helloworld.pdf';
PDFJS.disableWorker = true;
PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport})
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compatibility.js"></script>
<script src="https://raw.githubusercontent.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<canvas id="the-canvas" style="border:1px solid black"></canvas>