Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET PDF Viewer

I am looking for a ASP.NET control to load PDFs in browser. It should allow to control the number of pages to show to user, and also it should able to do some bookmark stuff like when user click on a button, then I could get the page number of viewer and save it, and then next time reload the PDF from that page number.

like image 358
Muhammad Hammad Avatar asked Feb 27 '26 02:02

Muhammad Hammad


2 Answers

As an alternative to IFRAME use PDFJS library (https://mozilla.github.io/pdf.js/)

It allows you to display the PDF document with Javascript/HTML5 Canvas only.

HTML5 Canvas browser compatibility: http://caniuse.com/#feat=canvas

Example to display a specific page - NOT TESTED

// pdf document file
var pdfDocument = 'yourfile.pdf';
// page Number you want to display
var pageNo = 1;
// name of the HTML5 Canvas
var canvasName = 'pdfCanvas';

PDFJS.getDocument( pdfDocument ).then(function (pdf) {
    pdf.getPage( pageNo ).then(function (page) {
        var scale = 1.5;
        var viewport = page.getViewport(scale);

        var canvas = document.getElementById(canvasName);
        var context = canvas.getContext('2d');
        canvas.height = viewport.height;
        canvas.width = viewport.width;

        var renderContext = {
            canvasContext: context,
            viewport: viewport
        };

        page.render(renderContext).promise.then(function () {
            // do something when rendering is completed
        });
    });
});
like image 99
Ole K Avatar answered Feb 28 '26 21:02

Ole K


You can use iframe to view your pdf in browser as follows

<iframe src="mypdf.pdf"></iframe>
like image 23
sreejithsdev Avatar answered Feb 28 '26 20:02

sreejithsdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!