我正在嘗試按照此處找到的 pdfjs 檔案https://www.pdftron.com/documentation/core/guides/features/manipulation/remove/嘗試從我上傳到我的 html 頁面的 PDF 中洗掉頁面. 這是我的 html 代碼:
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.228/pdf.js"></script>
<input type="file" id="input"/>
<script>
document.getElementById('input').addEventListener('change', function(e){
var reader = new FileReader()
reader.onload = function(x){
window['pdfjs-dist/build/pdf'].getDocument({data:x.target.result}).promise.then(function(doc){
doc.pageRemove(doc.getPageIterator(5));
console.log(doc.numPages)
})}
reader.readAsBinaryString(e.target.files[0])
}, false)
</script>
當我將 PDF 檔案上傳到頁面時,會出現此控制臺錯誤:
removeDemo.html:10 Uncaught (in promise) TypeError: doc.getPageIterator is not a function
我上傳的 PDF 超過 5 頁,因此要求洗掉第 5 頁應該不是問題。然而,其他功能似乎確實有效,例如,我在上面的代碼中有一行列印檔案的頁數。當我注釋掉 'getPageIterator' 行時,這很好用。所以似乎是這個特定功能的問題,而不是更普遍的問題。我想知道是什么導致了這個問題。如果這是相關的,我將在 macbook pro 上用 Chrome 運行它。
請讓我知道上述問題中是否有我可以進一步澄清的內容。
uj5u.com熱心網友回復:
Mozilla 主導的 pdf.js 主要是瀏覽器插件 pdf 查看器,沒有編輯器功能。
您呼叫的函式doc.pageRemove(doc用于 PDFTron webview/edit SDK,因此特定于該商業 JavaScript 庫。
uj5u.com熱心網友回復:
您從 PDFTron 鏈接到的檔案與 PDF.js 無關,它是一個完全獨立的 SDK。這就是在不同的 SDK 上呼叫 SDK API 時出錯的原因。
由于 PDF.js 不支持從 PDF 中洗掉頁面(也不支持一般編輯),那么我假設您的意圖是使用 PDFTron SDK 在瀏覽器客戶端中洗掉(或以其他方式編輯)PDF 檔案。
在這種情況下,您要執行以下操作。
請參閱此示例:https : //www.pdftron.com/documentation/web/samples/pdf-manipulation/#page-operations
請參閱此處開始使用 SDK:https : //www.pdftron.com/documentation/web/get-started/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/384568.html
標籤:javascript html pdf pdfjs pdftron
