Back to Blog

    Developer Blog

    How to Show the First Third of a PDF with Foxit PDF SDK for Web

    Foxit PDF SDK for Web

    Often times you need to show just certain parts of a PDF. This is often due to a particular PDF template that a company follows with the same kinds of information in the same location. For example, a 6 page invoice where you just want to show the first 2 pages that contains the key information you’re after.

    The following example will show you how to produce a PDF that shows only the first third of pages of a document in our Web-based JavaScript PDF viewer.

    Code Snippet:

    customs: {
     closeDocBefore: function () {
     returnconfirm('Close the current document?');
     },
     PageCustomRender: (function () {
     function CustomPageCustomRender (eCustom, pdfPageRender) {
     this.eCustom = eCustom;
     this.pdfPageRender = pdfPageRender;
     }
     CustomPageCustomRender.prototype.render = function () {
     var self = this;
     returnself.pdfPageRender.getPDFPage().then(function (page) {
     if(page.getIndex() > 3) {
     self.eCustom.innerHTML = 'You are not authorized to view this page.';
     returnfalse;
     }
     })
     }
     CustomPageCustomRender.prototype.destroy = function () {
     this.eCustom.innerHTML = '';
     };
     returnCustomPageCustomRender;
     })(),
    }