Reputation: 1430
I am trying to follow the documentation for pdfjs found here https://www.pdftron.com/documentation/core/guides/features/manipulation/remove/ in an attempt to remove a page from a PDF I have uploaded to my html page. Here is my html code:
<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>
which gives this console error when I upload a PDF file to the page:
removeDemo.html:10 Uncaught (in promise) TypeError: doc.getPageIterator is not a function
The PDF I am uploading has more than 5 pages, so asking to remove the 5th page in particular shouldn't be the problem. Other functionality does seem to work however, for example, I have a line in the above code that prints the number of pages of the document. This works fine when I comment out the 'getPageIterator' line. So it seems to be a problem with this specific function, rather than a more general problem. I would like to know what is causing this problem. In case this is relevant, I am running this in chromium on a macbook pro.
Please let me know if there is something in the above question that I can further clarify.
Upvotes: 1
Views: 281
Reputation: 2570
The documentation you linked to, from PDFTron, has nothing to do with PDF.js, it is a completely separate SDK. This is why you get an error making a SDK API call on a different SDK.
Since PDF.js does not support removing pages from a PDF (nor editing in general), then I assume your intention is to use PDFTron SDK to remove (or edit in other ways) a PDF file in the browser client side.
In which case you want to do the following.
See this sample: https://www.pdftron.com/documentation/web/samples/pdf-manipulation/#page-operations
See here to get started with the SDK: https://www.pdftron.com/documentation/web/get-started/
Upvotes: 1
Reputation: 11731
Mozilla led pdf.js is primarily a browser plugin pdf viewer, without editor functions.
The function your calling doc.pageRemove(doc
is for use with PDFTron webview / edit SDK and thus specific to that commercial JavaScript library.
Upvotes: 1