+ Start a Discussion
nvgoghnvgogh 

Opening documents

Oke I have been toying around with this the whole day and I don't seem to get it working ... and it frustrates me.

 

I want to open the documents which are in the document table, this is a test for some future development.

 

So I developed a apex class/controller class 

 

 

public class AttachmentOpener { public String attachment {get; set;} public String contenttype {get; set;} public String filetype {get; set;} public AttachmentOpener () { Document doc = [Select d.Body, d.ContentType, d.Type From Document d where d.type='xls']; contenttype = doc.ContentType; filetype = doc.Type; Blob b = doc.Body; attachment = b.ToString(); } }

 

 And an visual force page

 

<apex:page showHeader="false" cache="true" Controller="AttachmentOpener" contenttype="{!contenttype}#test.{!filetype}"> <apex:OutputText escape="false" value="{!attachment}" /> </apex:page>

 

When I open the page Firefox askes me to open or save the attachment (with the correct contenttype), so that all goes according to the way it should.

 

However the content of the file looks all wrong. For text files it works, but when they have more complex content like pdf, excel or word it doesn't work.

 

For instance a pdf does show me the correct number of pages (like 4) but no content (alle pages are blank). The document is correct since salesforce it able to show it to me using the standard functionality.

 

I have the feeling that it has to be something to do with (en)coding but I fail to find a reference as to what to do.

 

So can anybody give a clue to look for next?

 

Thnx

   Natalie

 

 

SuperfellSuperfell
I don't think you'll be able to do this, as far as i know, VF doesn't have any support for returning binary data.
nvgoghnvgogh

Here and there I see the discussion on this subject but apparently everybody hit a dead-end on this???

 

Is there another way to do this?

 

I want to do a simular thing as this user is asking

 

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=17522

nvgoghnvgogh
*bump* :smileywink:
XactiumBenXactiumBen
I have done many attempts at getting something like this working but I always seem to hit problems.  I have only managed to generate plain text content in this way (csv, text, xml) but nothing that is more complex like excel spreadsheets, pdf files etc.