编辑CSHTML查看页面保存为PDF [英] Editable cshtml View Page save as PDF

查看:256
本文介绍了编辑CSHTML查看页面保存为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个由Web应用程序的


  1. 编辑CSHTML视图页

然后

<醇开始=2>
  • 是编辑的内容的另存为PDF 当我按一下按钮

  • 所以这是整个CSHTML视图页面,

      @model IEnumerable的&LT; INT&GT;        @ {
                ViewBag.Title =创建模板;
            }
            &LT;!DOCTYPE HTML&GT;
            &LT; HTML和GT;
            &LT; HEAD&GT;
                &LT;标题&GT;创建一个模板&LT; /标题&GT;
            &LT; /头&GT;
            &LT;身体GT;
                        &LT; D​​IV ID ='模板'&GT;
                           &LT; H1 = CONTENTEDITABLE'真'&GT;产品名称&LT; / H1&GT;
                            &LT; D​​IV&GT;
                              &LT; H2 = CONTENTEDITABLE'真'&GT;产品说明&LT; / H&GT;
                              &LT; p = CONTENTEDITABLE'真'&GT;伦敦是英国的首都城市&LT; / P&GT;
                           &LT; / DIV&GT;
                       &LT; / DIV&GT;          &LT;按钮ID =btn_sumbit类型=按钮级=BTN BTN-危险提交&GT;保存为PDF&LT; /按钮&GT;        &LT; /身体GT;
            &LT; / HTML&GT;        @section脚本{            @ Scripts.Render(〜/包/ jqueryval)
                @ Scripts.Render(〜/包/ jQueryUI的)            &LT;脚本类型=文/ JavaScript的&GT;                $('#btn_sumbit')。在('点击',功能(){                    VAR div_value =的document.getElementById(模板)的innerHTML。                    RazorPDF.PdfResult(div_value,PDF);
                    });            &LT; / SCRIPT&GT;        }

    我使用 RazorPDF 做这个任务,但一旦我点击这个按钮,它不T保存到PDF

    我可以编辑该CSHTML视图页上,我想保存最后编辑的内容为PDF格式(这是动态视图)


    解决方案

    我觉得你这样做是错误的。行RazorPDF.PdfResult(......)中的控制器属于未在视图中。

    观看此视频: http://nyveldt.com/blog/post/Introducing-RazorPDF
    它应该给你的东西RazorPDF是如何工作的一个更清晰的认识。

    编辑:

    只要创建一个控制器方法,即基于参数生成的PDF查看。

     公众的ActionResult PDF(字符串名称,字符串描述){
        变种产品=新产品();
        product.Name =名称;
        product.Description =描述;    VAR pdfResult =新PdfResult(产品,PDF);    返回pdfResult;
    }

    当然,你需要创建一个产品级保存的信息。

    在你的Javascript一部分,你可以这样写:

      location.href = @ Url.Action(PDF,Controllername)+ +姓名+NAME =?,&放大器;描述=+说明;

    这将有望产生,你可以在Javascript中点击一个链接。名称和描述是认为是由用户输入的信息的JavaScript变量

    你明白吗?我的做法是基于您可编辑视图的信息生成(在视频等)在不同的视图中的PDF内容。

    告诉我,如果它的工作。 ; - )

    I'm trying to create web application that consisting an

    1. editable cshtml view page

    and then

    1. save that edited content as a PDF once I click the button

    So this is the whole cshtml view page ,

            @model IEnumerable<int>
    
            @{
                ViewBag.Title = "Create Template";
            }
            <!DOCTYPE html>
            <html>
            <head>
                <title>Create a Template</title>
            </head>
            <body>
                        <div id='template'>
                           <h1 contentEditable='True'>Product Name</h1>
                            <div >
                              <h2 contentEditable='True'>Product Description</h2>       
                              <p contentEditable='True'>London is the capital city of England.</p>
                           </div>
                       </div>
    
              <button id="btn_sumbit" type="button" class="btn btn-danger submit">Save as PDF</button>
    
            </body>
            </html>
    
            @section Scripts {
    
                @Scripts.Render("~/bundles/jqueryval")
                @Scripts.Render("~/bundles/jqueryui")
    
                <script type="text/javascript">
    
                    $('#btn_sumbit').on('click', function () {
    
                        var div_value = document.getElementById('template').innerHTML;
    
                        RazorPDF.PdfResult(div_value, "PDF");
                    });
    
                </script>
    
            }
    

    I'm using RazorPDF to do this task , but once I click this button it doesn't saving to PDF

    I can edit this cshtml view page , I want to save that finally edited content as pdf (which is dynamic view)

    解决方案

    I think you're doing it wrong. The line "RazorPDF.PdfResult(...)" belongs in the Controller not in the View.

    Watch this Video: http://nyveldt.com/blog/post/Introducing-RazorPDF It should give you a clearer understanding of how things work in RazorPDF.

    EDIT:

    Just create a Controller method, that generates a PDF-View based on Parameters.

    public ActionResult Pdf(string name, string description) {
        var product = new Product();
        product.Name = name;
        product.Description = description;
    
        var pdfResult = new PdfResult(product, "Pdf");
    
        return pdfResult;
    }
    

    Of course you need to create a Product-Class that holds the information.

    In your Javascript part you can write:

    location.href = @Url.Action("Pdf", "Controllername") + "?name=" + name + "&description=" + description;
    

    This will hopefully generate a link that you can follow in Javascript. name and description are Javascript variables that hold the information that was typed by the user.

    Do you understand? My approach would be to generate the PDF content in a different view (like in that video) based on the information of your editable view.

    Tell me if it worked. ;-)

    这篇关于编辑CSHTML查看页面保存为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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