4

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.

5
  • 3
    You want to duplicate the Adobe browser add-in? Dec 28, 2012 at 17:10
  • Sounds like you are looking for a rewrite of Adobe's browser add-in. Not sure you will find that and if you do, it will cost.
    – andleer
    Dec 28, 2012 at 18:49
  • try pdfobject.com/markup/index.php
    – VahidN
    Dec 29, 2012 at 6:23
  • Thank you for your response. I want to display pdf in browser through my asp.net code. and i will have a button on page when user click it. i will get the page number he is visiting of pdf. and i will save the page number. next time he come over the pdf i will open pdf at that page number. Dec 29, 2012 at 8:01
  • Did you get the solution
    – Neha
    Jul 5, 2017 at 22:21

3 Answers 3

5

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
        });
    });
});
3

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

<iframe src="mypdf.pdf"></iframe>
2
  • +1 i dont like iframes one bit, but this seems to be the least complicated and most reasonable solution to the OP's question
    – Thousand
    Dec 28, 2012 at 17:58
  • Sorry this is not what i am looking for. I want to control number of pages to show from server end. and also need to load pdf from server end. and should have option to get the current page of pdf. – Dec 29, 2012 at 7:28
0

You can try to embed the PDF file using the "object"-Tag in ASP.NET.

here's a little example:

//Markup
<asp:LinkButton ID="view" runat="server" Text="Click me!" onClick="ViewPDF"></asp:LinkButton>
<asp:Literal ID="embedPdf" runat="server"/>

//C#
private void ViewPDF(object sender, EventArgs e)
{
   string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"1200px\" height=\"1000px\"></object>";
   embedPdf.Text = string.Format(embed, ResolveUrl("/your/pdf/file/path.pdf"));
}

after clicking on the ASP-LinkButton the PDF-reader should appear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.