PDF阅读器在MVC中,显示在浏览PDF内容 [英] Pdf Viewer in MVC to show the pdf contents in View

查看:677
本文介绍了PDF阅读器在MVC中,显示在浏览PDF内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ShowDocument.cshtml查看。

I have a View called ShowDocument.cshtml.

我要显示在浏览PDF文档。
首先我转换HTML页面的.pdf其中包含的信息为:

I want to show the pdf document in a view. First I am converting the html page to .pdf which contains the information as :

在控制器中的code是:

The code in the controller is:

Stream stream = HtmlToPdfBuilder.GetHtmlForm(model.Type, 16);

如果我给符文件(流应用程序/ PDF,Authorization.pdf),我会越来越为保存,另存为对话框。

If I give return File(stream, "application/pdf", "Authorization.pdf"), I will be getting as save, save as dialog box.

我不想要这个对话框中,我要显示在页面内的PDF内容而已。

I do not want this dialog box ,I want to show the pdf content inside the page only .

那么,有没有在任何MVC PDF阅读器,这样我只能用一些控制显示在视图中含量

So Is there any pdf viewer in MVC so that I can show the content in a View only using some control

推荐答案

这可能不是正是你想要的,但可能满足您的需要。您可以嵌入PDF的局部视图然后用窗体上的PDF更新通过AJAX的局部视图提交按钮。

This may not be exactly what you want but might meet your need. You can embed the PDF in a partial view then update the partial view via ajax with the PDF on the form submit button.

举例code:
局部视图

Example code: Partial view

    @model Test.Models.ViewModel

<style type="text/css">

#pdfbox
{
    width:600px;
    height:400px;
    border: 5px solid #ccc;
}

</style>

<object id='pdfbox' type="application/pdf" data="@Url.Action("GeneratePDF", "Home", Model)">
    Click @Html.ActionLink("here", "GeneratePDF", "Home") to view the file.
</object>    

控制器电话:

    public ActionResult GeneratePDF(ViewModel model)
    {

        byte[] bytes = OpenPDFAndGetBytes("Thepdfname");
        return File(bytes, "application/pdf");
    }

    public ActionResult RenderPDF(LabelViewModel model)
    {
        return PartialView(model);
    }

main view

@using (Ajax.BeginForm("RenderPDF", "Home", new AjaxOptions { UpdateTargetId = "pdf" }))
{
    <table>
        <tr>
            <td>
                <fieldset>
                    <legend>Fill the form:</legend>
                        Some form junk can go here
                    <br />
                    <input type="submit" value="Display PDF" />
                </fieldset>
            </td>
            <td>
                <div id='pdf'>
                    @{
                        Html.RenderPartial("RenderPDF", Model);
                    }
                </div>
            </td>
        </tr>
    </table>
}

这篇关于PDF阅读器在MVC中,显示在浏览PDF内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆