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
Karthik SankarKarthik Sankar 

Displaying the content of the Word Document in a Visualforce Page?

I am having a word document stored in Document object. I need to retrieve only the content and display it in a VF page.

I have written the query in a controller class to get the body of the document. The body is returning as Blob data type. Then I am converting the Blob to String using ToString() method in Apex.

Code for your reference:
----------------------------------
Document d = [Select body, bodyLength, ContentType, Url from Document where id = :'01580000000n17L'];
Blob b = d.body;
String s = b.toString();

But the output is showing as more encoded characters along with the content. These encoded characters, I suppose, are meta-data for the word document like font properties, alignment, etc. I need only the content of the document.

In the same way, if I use a Notepad file to get the content, it is working fine and I get only the content.

Please tell me a way to get the content only from a Word document without the encoded characters.
wesnoltewesnolte

Hmmm.. not sure if this will work but give it a shot any way..

 

If you output the content using an outputTextArea for example try

 

<apex:outputTextArea escape="false" value="{!myContent}" ..../>

 

Cheers,

Wes 

Karthik SankarKarthik Sankar

Hi,

 

<apex:outputTextArea> tag is not available in VF component.

 

Do you have any other suggestion?

wesnoltewesnolte

Silly me, it should be <apex:outputText ... and then the rest.

 

Sorry about that.

Wes

Karthik SankarKarthik Sankar

Hi,

 

I am using <apex:outputText> only for display in the VF page.

 

Blob value of the content is showing as: core.filemanager.FileBlobValue@13baffc

 

I am converting this blob value to string using myBlob.toString()

 

The output of the above code is showing as more encoded characters with the content in between them.

 

The content with encoded characters is too large to show here.

 

I tried splitting the content only but there is no logic involved in it.

 

Please let me know if anything comes up in your mind. 

 

 

 

 

Suzan2009Suzan2009

Hi Guys,

 

I have same issue. Any workarround, let me know. Thank you so much, so much, so much

 

 

Suzan

 

 

 

SidzSidz

hi,

i am not sure if we can read the content of the blob by converting to string but we can download it for sure.

ex:<a href="{!URLFOR($Action.Attachment.Download, attachment.id)}">Download ME</a>

if we can use a javascript to directly process this and get us the document may be we can use some document viewer which is installed in the browser to display that.:manhappy:


Karthik Sankar wrote:

Hi,

 

I am using <apex:outputText> only for display in the VF page.

 

Blob value of the content is showing as: core.filemanager.FileBlobValue@13baffc

 

I am converting this blob value to string using myBlob.toString()

 

The output of the above code is showing as more encoded characters with the content in between them.

 

The content with encoded characters is too large to show here.

 

I tried splitting the content only but there is no logic involved in it.

 

Please let me know if anything comes up in your mind. 

 

 

 

 


 

 

 

communitycommunity

Any solution for this, please?

DBA2012DBA2012

try to remove the line break from the string ( \n , \r , \n\r)