pdfjs cannot use function ‘getPageIterator’

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.