This is a migrated thread and some comments may be shown as answers.

[Solved] RadEditor:Save pdf from serverside

1 Answer 396 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Hrushikesh Mokashi
Top achievements
Rank 1
Hrushikesh Mokashi asked on 12 Aug 2009, 11:22 AM
Hi,

I am using RadControl Q1 2009.
I am using RadEditor.

'RadEditor.ExportToPdf()' is used to open pdf in browser.



How can I save the radeditor content as pdf from serverside.?

Thanks


1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 13 Aug 2009, 09:54 AM
Hi Hrushikesh,

To save the generated PDF content from RadEditor in Database, you should use the OnExportContent event. This event was implemented in version 2009.1.527 of Telerik.Web.UI.dll and is not supported in the previous versions.

For your convenience I prepared and attached here an example demonstrating how to export the editor's content as PDF on the server using the new OnExportContent event property of RadEditor. The demo is based on the following blog post:
How To: Export grid to PDF file and show the result using the window.

Please, note that there some limitations in the export to pdf functionality: for example to export a TABLE element, you should add COLGROUP and COL tags for each table row and set table width. You can do that programmatically using the following custom content filter:

<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad" > 
 <ImageManager ViewPaths="~/Images" UploadPaths="~/Images" /> 
 <ExportSettings OpenInNewWindow="true" /> 
    <Content> 
    </Content> 
</telerik:RadEditor>   
<script type="text/javascript"
    var editorObject; 
    function OnClientLoad(editor, args) 
    { 
       editor.get_filtersManager().add(new MyFilter()); 
       editorObject = editor; 
    } 
     
    MyFilter = function() 
    { 
       MyFilter.initializeBase(this); 
       this.set_isDom(true); 
       this.set_enabled(true); 
       this.set_name("RadEditor filter"); 
       this.set_description("RadEditor filter description"); 
    } 
    MyFilter.prototype = 
    { 
    //Table neeed 1) COLGOUPS!, 2) width! 
     
       getHtmlContent : function(content) 
       { 
         var newContent = content; 
         var tables = newContent.getElementsByTagName("TABLE"); 
         var colCount = null
         var editorDocument = editorObject.get_document(); 
          
         for (var i=0; i < tables.length; i++) 
         { 
                var table = tables[i]; 
                 
                table.style.width = "0px"
                 
                //If there are colgroups - skip table 
                var groups = table.getElementsByTagName("colgroup"); 
                if (groups.length > 0) continue;//! 
                 
                 
                colCount  = table.rows[0].cells.length;                                                    
               // create colgroup 
               var newColGroup = editorDocument.createElement("colgroup"); 
                
               // create cols 
               var newCol; 
               for(var j=0; j<colCount; j++) 
               { 
                  // create cols 
                  newCol = editorDocument.createElement("col"); 
                  newColGroup.appendChild(newCol); 
                   
               } 
                
               //table.appendChild(newColGroup) 
               table.insertBefore(newColGroup, table.firstChild); 
         } 
         //newContent = newContent.toUpperCase(); 
         return newContent; 
       } 
    } 
     
    MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter); 
    </script> 





Best wishes,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Hrushikesh Mokashi
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or