How to show PDF using server Viewer.js?

Asked

Viewed 537 times

0

On the View page, I have the following code:

<iframe style="width:800px; height:550px;" id="FileReload" src="@Url.Action("GetPDF", "Account", new { id = Model.Id })" onerror="function_documenthide();"></iframe>

Each browser has its own PDF.

The problem is the safari browser and IE. Safari does not show PDF and IE is too heavy.

I’m trying to show standard PDF of all browsers using Viewerjs.

It works where your PDF is. (Appdata/Document/test.pdf).

So I put this code to work with Viewerjs:(With server)

<iframe style="width:815px; height:550px;" id="FileReload" src="/ViewerJS/#../@Url.Action("GetPDF", "Account", new { id= Model.ID})"></iframe>

More does not work, gives this problem below:

inserir a descrição da imagem aqui

UPDATE

With local PDF works:

<iframe style="float:right;" src="/ViewerJS/pdf-test.pdf" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe>

In Controller it returns with application/pdf type:

PDF = ((byte[])reader["File"]);
return new FileContentResult(PDF, "application/pdf");

Any idea ?

  • Which browser? Which error occurs?

  • In fact all browsers do not show PDF using Viewerjs, plus google Chrome shows error.

  • Error : The provided value 'Moz-chunked-arraybuffer' is not a Valid Enum value of type Xmlhttprequestresponsetype.

  • 1

    @Laerte the problem has been solved, see the answer.

1 answer

1


Problem solved, follow code:

Html:

<iframe src="/Scripts/ViewerJS/#/home/getpdf" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe>

Controller:

public ActionResult GetPDF()
{
    using (WebClient client = new WebClient())
    {
        var t = client.DownloadData("http://www.irs.gov/pub/irs-pdf/fw4.pdf");

        return new FileContentResult(t, "application/pdf");
    }
}

See the result:

inserir a descrição da imagem aqui

  • Very good! : ) +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.