How to extract body text part of a sfdt

Hi, I have an sfdt document with header and footer. 
I need to extract the body text.
How can I do that?

Thank You in advance

3 Replies

HC Harini Chellappa Syncfusion Team April 2, 2020 05:58 AM UTC

Hi Antonio, 

Syncfusion Greetings! 

Document editor provides support to extract text from selection. Please refer the below documentation on text property of selection. 


To achieve your requirement, you can select the entire document and call text property of selection to return the text. 


Please refer the below sample code snippet 

//select all the document content. 
 
documentEditorContainerInstance.documentEditor.selection.selectAll(); 
 
//returns text within the selection. 
 
documentEditorContainerInstance.documentEditor.selection.text; 
 

Please let us know whether this satisfies your requirement. 

Regards, 

Harini C 



AN Antonio May 20, 2020 02:34 PM UTC

Hi Harini, 
your solution for getting text works fine.
Now I have to copy formatted body (with styles, not only text), without header and footer, to save it in database and to paste it later on demand (and programmatically) in another document with different header and footer.
Please, can You help me?


HC Harini Chellappa Syncfusion Team May 21, 2020 08:47 AM UTC

Hi Antonio, 

Document editor provides paste API which extracts the document content and inserts paragraph and table with its properties in current selection. 


Sample code snippet 
Document Editor container 
 
//pass the sfdt string, which extracts the document and inserts paragraph and table with its properties   
containerInstance.documentEditor.editor.paste(sfdtstring)  
  
DocumentEditor  
documentEditorInstance.documentEditor.editor.paste(sfdtstring)  

 
Document editor doesn’t provide any API to extract the body content alone without headers and footers. You can extract the complete document as SFDT Json string using serialize API and pass it to paste API which will extract and inserts the body content alone in current selection. 


Sample code snippet 

Document Editor container 
  
containerInstance.documentEditor.serialize();  
  
DocumentEditor  
 
documentEditorInstance.serialize();  

 
For your reference, please check the sample below. 


please check it and let us know whether this helps. 

Regards, 

Harini C 


Loader.
Up arrow icon