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

  •  10-14-2015, 11:12 AM

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

    Hi,

     

    Can you try my code? Does it has the same issue too?

     

    1. protected Editor PrepairEditor(Action<Editor> oninit)  
    2.       {  
    3.           Editor editor = new Editor(System.Web.HttpContext.Current, "editor");  
    4.   
    5.           editor.ClientFolder = "/richtexteditor/";  
    6.           editor.ContentCss = "/Content/example.css";  
    7.           //editor.ClientFolder = "/Content/richtexteditor/";      
    8.           //editor.ClientFolder = "/Scripts/richtexteditor/";      
    9.   
    10.           editor.Text = "Type here";  
    11.   
    12.           editor.AjaxPostbackUrl = Url.Action("EditorAjaxHandler");  
    13.   
    14.           if (oninit != null) oninit(editor);  
    15.   
    16.           //try to handle the upload/ajax requests      
    17.           bool isajax = editor.MvcInit();  
    18.   
    19.           if (isajax)  
    20.               return editor;  
    21.   
    22.           //load the form data if any      
    23.           if (this.Request.HttpMethod == "POST")  
    24.           {  
    25.               string formdata = this.Request.Form[editor.Name];  
    26.               if (formdata != null)  
    27.                   editor.LoadFormData(formdata);  
    28.           }  
    29.   
    30.           //render the editor to ViewBag.Editor      
    31.           ViewBag.Editor = editor.MvcGetString();  
    32.   
    33.           return editor;  
    34.       }  
    35.   
    36.       //this action is specified by editor.AjaxPostbackUrl = Url.Action("EditorAjaxHandler");      
    37.       //it will handle the editor dialogs Upload/Ajax requests      
    38.       [ValidateInput(false)]  
    39.       public ActionResult EditorAjaxHandler()  
    40.       {  
    41.           PrepairEditor(delegate(Editor editor)  
    42.           {  
    43.   
    44.           });  
    45.           return new EmptyResult();  
    46.       }    
     

    1. [ValidateInput(false)]  
    2.       public ActionResult output_xhtml()  
    3.       {  
    4.           PrepairEditor(delegate(Editor editor)  
    5.           {  
    6.               editor.LoadHtml("~/example.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("~/aaa.pdf");  
    21.   
    22.           return View();  
    23.       }   
     

    View page

     

    1. <!DOCTYPE html>  
    2. <html>  
    3. <head>  
    4.     <title>RichTextEditor - Output XHTML</title>  
    5.     <link rel="stylesheet" href="/Content/example.css" type="text/css" />  
    6. </head>  
    7. <body>  
    8.     <script type="text/javascript">  
    9.         var editor;  
    10.         function RichTextEditor_OnLoad(rteeditor) {  
    11.             editor = rteeditor;  
    12.             var content = true;  
    13.             if (!content) {  
    14.                 setTimeout(function () {  
    15.                     editor.SetText("<table cellspacing=\"4\" cellpadding=\"4\" border=\"0\"><tr><td><p><img src=\"http://www.richtexteditor.com/uploads/j0262681.jpg\" alt=\"\" /></p></td> <td> <p>When your algorithmic and programming skills have reached a level which you cannot improve any further, refining your team strategy will give you that extra edge you need to reach the top. We practiced programming contests with different team members and strategies for many years, and saw a lot of other teams do so too.</p></td></tr> <tr> <td> <p> <img src=\"http://www.richtexteditor.com/uploads/PH02366J.jpg\" alt=\"\" /></p></td> <td> <p>From this we developed a theory about how an optimal team should behave during a contest. However, a refined strategy is not a must: The World Champions of 1995, Freiburg University, were a rookie team, and the winners of the 1994 Northwestern European Contest, Warsaw University, met only two weeks before that contest.</p></td></tr></table>");  
    16.                 }, 1000);  
    17.                 return;  
    18.             }  
    19.         }  
    20.     </script>  
    21.     @using (Html.BeginForm())  
    22.     {   
    23.         <h1>  
    24.             Support output well-formed HTML and XHTML</h1>  
    25.         <p>  
    26.             This example shows RichTextEditor supports output well-formed XHTML. Your choice  
    27.             of XHTML 1.0 or HTML 4.01 output.  
    28.         </p>  
    29.         <div>  
    30.             @Html.Raw(ViewBag.Editor)  
    31.             <br />  
    32.             <button id="btn_sumbit" type="submit">  
    33.                 Submit</button>  
    34.         </div>  
    35.         <br />  
    36.         <div>  
    37.             <h3>  
    38.                 Result html:</h3>  
    39.             <div>  
    40.                 @ViewBag._content  
    41.             </div>  
    42.         </div>  
    43.     }  
    44. </body>  
    45. </html>  
     

    Regards,

     

    Ken 

View Complete Thread