function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VenkatVenkat 

How can I display word document content on visualforce page

I am uploading word document in Document folder and trying to get that document information and displaying on visualforce page. Not able to do.
Please share ideas

Thanks in advance.

Venkat.
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can try something like - 

VF Page  - 
<apex:page controller="displayDocumentController">
  {!docBody}
</apex:page>
Apex Controller - 
public class displayDocumentController {
    public String docBody{get;set;}   
    
    public displayDocumentController() {
        doc = [SELECT body from Document where name='test'];  
        docBody = (doc.body).toString();  
    }
}
Pls, let me know if you need further help.
 
VenkatVenkat
Hi Sumit Kumar,

Thank You! for your help. It is really appriciable. Here I am getting error when page loaded. Can you please look into this erro.

=====================================
BLOB is not a valid UTF-8 string 
An unexpected error has occurred. Your development organization has been notified.
=====================================

Thanks
Venkat
Sumit Kumar Singh 9Sumit Kumar Singh 9
Okay... 
Insted of using toSting() method , you can use this - 

docBody = EncodingUtil.base64Encode(doc.body);

It should help you.
Thnaks- 
VenkatVenkat
Thank You, Error resolved. But Information displaying in encrypted format.Also displaying in single line all the informatio. Word document formating is also not coming.

UEsDBBQABgAIAAAAIQAykW9XZgEAAKUFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0lMtqwzAQRfeF/oPRtthKuiilxMmij2UbaPoBijRORPVCo7z+vuM4MaUkMTTJxiDP3HvPCDGD0dqabAkRtXcl6xc9loGTXmk3K9nX5C1/ZBkm4ZQw3kHJNoBsNLy9GUw2ATAjtcOSzVMKT5yjnIMVWPgAjiqVj1YkOsYZD0J+ixnw+17vgUvvEriUp9qDDQcvUImFSdnrmn43JBEMsuy5aayzSiZCMFqKRHW+dOpPSr5LKEi57cG5DnhHDYwfTKgrxwN2ug+6mqgVZGMR07uw1MVXPiquvFxYUhanbQ5w+qrSElp97Rail4BId25N0Vas0G7Pf5TDLewUIikvD9Jad0Jg2hjAyxM0vt3xkBIJrgGwc+5EWMH082oUv8w7QSrKnYipgctjtNadEInWADTf/tkcW5tTkdQ5jj4grZX4j7H3e6NW5zRwgJj06VfXJpL12fNBvZIUqAPZfLtkhz8AAAD//wMAUEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAgCX3JlbHMvLnJlbHMgogQCKKAAAgAAAAAAAAA

 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Venkat, 

Did you resolve that?
Nishi RanaNishi Rana
Hi Sumit Kumar,
Can you please help me to resolve the same issue.
I have tried all this possible solution still got response Like this :
@@ Content = 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAOwADAP7/CQAGAAAAAAAAAAAAAAABAAAAZAAAAAAAAAAAEAAAAgAAAAEAAAD+////AAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
Nishi RanaNishi Rana
I Want this as in String.
 
Sumit Kumar Singh 9Sumit Kumar Singh 9

Hi Nishi Rana,

You can use following code - 
Please make sure there should not be special characters in th file.

public class displayDocumentController {
    public String docBody{get;set;}   
    
    public displayDocumentController() {
        Document doc = [SELECT body from Document where name='test'];  
        docBody = (doc.body).toString();  
    }
}

Thanks,
Sumit Kumar Singh