Vikram
Vikram

Reputation: 4106

Display contents from a PDF on Web browser on a machine where PDF Reader/Viewer is not installed

I want to design an application using ASP.Net MVC which will allow me to display the contents from PDF on a Web browser. This should happen without any problem even on the machines where the PDF Reader/Viewer is not installed.

I was thinking of converting PDF to image and then displaying, but I believe there will be more efficient ways/plugins with which this can be achieved.

Please let me know the ways to do it.

Upvotes: 1

Views: 658

Answers (2)

Umair Ahmad
Umair Ahmad

Reputation: 11

In View:

<object data="@Url.Action("Showpdf", "ControllerName")"></object>

In Controller:

public ActionResult Showpdf()
    {
        return File("FilePath", "application/pdf");
    }

In Order to display pdf from a DB or something, you can use

public ActionResult Showpdf()
    {
        byte[] pdf = getPdfFromDbOrSomewhereElse();
        return File(pdf, "application/pdf");
    }

Upvotes: 0

Chris Pratt
Chris Pratt

Reputation: 239290

Short of making all your users use Chrome, which has built-in PDF display, there's nothing that can be done. PDF is a proprietary file format, and as such needs some sort of viewer installed on the machine in order to see it. What you're talking about is like asking how you can open an Excel file without having to have Excel or some other program capable of reading it like LibreOffice installed. It's simply not possible.

Upvotes: 2

Related Questions