View PDF as part of the page

后端 未结 1 2022
迷失自我
迷失自我 2020-12-01 08:19

I am trying to view a PDF document in my MVC web page, but I cant make it to work.

I would like the PDF to be displayed as a part of the other stuff on the page (hea

1条回答
  •  再見小時候
    2020-12-01 08:44

    Why don't you try using iframe like this :

    
    

    I suggest to use object tag if it's possible, use iframe just for testing.

    If you want to render PDF as part of the page as you just did

    src='<% Html.RenderAction("GetPDF"); %>'

    Then this is your option

    If you need complete control over PDF content using CSS or whatsoever, like Google books and so on, then you need tools that help you to convert each requested page of PDF to Plain Text, HTML or even image. tools like PDFsharp. Search Google For Tools

    If you want display PDF as part of the page then this is what you have to do

    ASPX: src="<%= Url.Action("GetPDF") %>"
    Razor: src="@Url.Action("GetPDF")"
    

    And final answer could be

    " type="application/pdf" width="300" height="200">
        alt : test.pdf
    
    

    And in the case that you want to return PDF as Stream then you need

    public FileStreamResult GetPDF()
    {
        FileStream fs = new FileStream("c:\\PeterPDF2.pdf", FileMode.Open, FileAccess.Read);
        return File(fs, "application/pdf");
    }
    

    0 讨论(0)
提交回复
热议问题