2014-02-26 48 views

回答

12

您應該能夠使用的FileReader得到一個文件對象的內容作爲一個類型數組打開它的方式,這PDFJS接受(http://mozilla.github.io/pdf.js/api/draft/PDFJS.html

//Step 1: Get the file from the input element     
inputElement.onchange = function(event) { 

    var file = event.target.files[0]; 

    //Step 2: Read the file using file reader 
    var fileReader = new FileReader(); 

    fileReader.onload = function() { 

     //Step 4:turn array buffer into typed array 
     var typedarray = new Uint8Array(this.result); 

     //Step 5:PDFJS should be able to read this 
     PDFJS.getDocument(typedarray).then(function(pdf) { 
      // do stuff 
     }); 


    }; 
    //Step 3:Read the file as ArrayBuffer 
    fileReader.readAsArrayBuffer(file); 

} 
+1

謝謝@sam。爲了補充這個答案:請參閱這裏瞭解如何使用pdf.js提取文本:http://stackoverflow.com/a/20522307/408286 – Motasim

+0

謝謝,這工作得很好。 –

相關問題