2013-03-20 108 views
7

我正在嘗試pdf.js庫,只是想在我的服務器上顯示本地pdf文件,而不是示例中提供的pdf文件。pdf.js與本地pdf文件

<html> 
<body> 
    <canvas id="the-canvas" style="border:1px solid black"></canvas> 

    <!-- Use latest PDF.js build from Github --> 
    <script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script> 

    <script type="text/javascript"> 
    // 
    // NOTE: 
    // Modifying the URL below to another server will likely *NOT* work. Because of browser 
    // security restrictions, we have to use a file server with special headers 
    // (CORS) - most servers don't support cross-origin browser requests. 
    // 
    var url = '/test.pdf'; 

    // 
    // Disable workers to avoid yet another cross-origin issue (workers need the URL of 
    // the script to be loaded, and dynamically loading a cross-origin script does 
    // not work) 
    // 
    PDFJS.disableWorker = true; 

    // 
    // Asynchronous download PDF as an ArrayBuffer 
    // 
    PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) { 
     // 
     // Fetch the first page 
     // 
     pdf.getPage(1).then(function getPageHelloWorld(page) { 
     var scale = 1.5; 
     var viewport = page.getViewport(scale); 

     // 
     // 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 
     // 
     page.render({canvasContext: context, viewport: viewport}); 
     }); 
    }); 
    </script> 

</body> 
</html> 

因此,我將pdf url更改爲我的本地'/test.pdf'網址。但是,這給我的消息,當它明確存在於我的根文件夾中時找不到該文件。任何想法可能會導致此錯誤?

+0

在你找到答案這個工作? – Technacron 2016-12-26 11:18:19

回答