Re: Edited content save as PDF when I click a Button

  •  10-13-2015, 11:44 PM

    Re: Edited content save as PDF when I click a Button

     Hi thank you very much for your help up to now , because of your help I able to save to PDF once I click a button.

     

     but there is an issue, once I click the button its saving ""Type here" text only ,

     

    this is the view of it.

     

     

     

    it doesn't extracting currntly edited content from the RTE ,  I think its saving "Type here"  text because of this code line 

    1. editor.Text = "Type here";  
      inside the PrepairEditor() method . How to extract currently edited content ?

     

    Here my relavant , BrochureController.cs file methods 

     

     

    1. [ValidateInput(false)]  
    2. public ActionResult output_xhtml()  
    3. {  
    4.     PrepairEditor(delegate (Editor editor)  
    5.     {  
    6.         editor.LoadHtml("~/brochuretemplates/myhtml.html");  
    7.     });  
    8.     return View();  
    9. }  
    10.   
    11. [HttpPost]  
    12. [ValidateInput(false)]  
    13. public ActionResult output_xhtml(string m)  
    14. {  
    15.     Editor theeditor = PrepairEditor(delegate (Editor editor)  
    16.     {  
    17.   
    18.     });  
    19.   
    20.     theeditor.SavePDF(m);  
    21.   
    22.     return View();  
    23. }  
    24.   
    25.   protected Editor PrepairEditor(Action<Editor> oninit)  
    26.    {  
    27.     Editor editor = new Editor(System.Web.HttpContext.Current, "editor");  
    28.   
    29.     editor.ClientFolder = "/richtexteditor/";  
    30.     editor.ContentCss = "/Content/example.css";  
    31.     //editor.ClientFolder = "/Content/richtexteditor/";    
    32.     //editor.ClientFolder = "/Scripts/richtexteditor/";    
    33.   
    34.     editor.Text = "Type here";  
    35.   
    36.     editor.AjaxPostbackUrl = Url.Action("EditorAjaxHandler");  
    37.   
    38.     if (oninit != null) oninit(editor);  
    39.   
    40.     //try to handle the upload/ajax requests    
    41.     bool isajax = editor.MvcInit();  
    42.   
    43.     if (isajax)  
    44.         return editor;  
    45.   
    46.     //load the form data if any    
    47.     if (this.Request.HttpMethod == "POST")  
    48.     {  
    49.         string formdata = this.Request.Form[editor.Name];  
    50.         if (formdata != null)  
    51.             editor.LoadFormData(formdata);  
    52.     }  
    53.   
    54.     //render the editor to ViewBag.Editor    
    55.     ViewBag.Editor = editor.MvcGetString();  
    56.   
    57.     return editor;  
    58. }  
    59.   
    60. //this action is specified by editor.AjaxPostbackUrl = Url.Action("EditorAjaxHandler");    
    61. //it will handle the editor dialogs Upload/Ajax requests    
    62. [ValidateInput(false)]  
    63. public ActionResult EditorAjaxHandler()  
    64. {  
    65.     PrepairEditor(delegate (Editor editor)  
    66.     {  
    67.   
    68.     });  
    69.     return new EmptyResult();  
    70. }  

     

     Here the output_xhtml.cshtml file

     

    1. @{  
    2.     ViewBag.Title = "Index";  
    3.     Layout = "~/Views/Shared/_Layout.cshtml";  
    4. }  
    5.   
    6. <h4> Edit the Brochure </h4>  
    7.   
    8.   
    9. <form>  
    10.     <div> @Html.Raw(ViewBag.Editor) </div>  
    11. </form>  
    12.   
    13. <div style="margin-top:10px">  
    14.     <button id="MyButton" type="button" class="btn btn-danger submit">Save as PDF</button>  
    15. </div>  
    16.   
    17. @section Scripts {  
    18.     @Scripts.Render("~/bundles/jqueryval")  
    19.     @Scripts.Render("~/bundles/jqueryui")  
    20.   
    21. <script>  
    22.   
    23.     $('#MyButton').click(function () {  
    24.   
    25.         var model = { m: "~/brochuretemplates/anemeh.pdf" };  
    26.   
    27.            $.ajax({  
    28.                 url: '@Url.Action("output_xhtml", "Brochure")',  
    29.                 contentType: 'application/json; charset=utf-8',  
    30.                 type: 'POST',  
    31.                 dataType: 'html',  
    32.                 data: JSON.stringify(model)  
    33.             })  
    34.             .success(function(result) {  
    35.             });  
    36.     });  
    37.   
    38. </script>  
    39.   
    40.   
    41.   
    42. <script type='text/javascript'>  
    43. function RichTextEditor_OnLoad(editor)  
    44. {  
    45.     editor.SetWidth(1150); //Sets the width.  
    46.     editor.SetHeight(612); //Sets the height.  
    47. }  
    48. </script>  
    49. }  
     

     

    Filed under: ,
View Complete Thread