You need to sign in to do that
Don't have an account?
visualforce page to display content
i am trying to use a visualforce page to display the contents of a document, but when the page loads i get the following error
common.apex.runtime.impl.ExecutionException: BLOB is not a valid UTF-8 string
<apex:page renderAs="pdf" controller="basicWeightPDF" contentType="HTML" >
<html>
<body>
{!dipslaytable}
</body>
</html>
</apex:page>
public class basicWeightPDF{
public string dipslaytable{get;set;}
public basicWeightpdf()
{
document d=[Select id, body from document where id='015190000000W33'];
Blob bodyOfAttachment = EncodingUtil.base64Decode('JVBERi0xLjIgCiXi4');
string strOrgId=UserInfo.getOrganizationID();
dipslaytable=d.body.tostring();
}
}
Instead of:
dipslaytable=d.body.tostring();
Please try:
dipslaytable = EncodingUtil.base64Encode(d.body);
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
You can use the EncodingUtil.base64Encode but it diplays only the base 64 of the content.
If what you want to do is to show an image, you should use something like
Or maybe you have to change the "data:image/png" to "data:image/jpeg" or data:image/bmp or whatever your image is...it may be in the COntentType field of your attachment (but it depends on how the attachment has been added)
here is the current page
<apex:page controller="basicWeightPDF" >
<html>
<body>
<img src="data:image/jpg;base64,{!dipslayTable"/>
</body>
</html>
</apex:page>
and controller
public class basicWeightPDF{
public string dipslaytable{get;set;}
public basicWeightpdf()
{
document d=[Select id, body from document where id='015190000000W33'];
Blob bodyOfAttachment = EncodingUtil.base64Decode('JVBERi0xLjIgCiXi4');
string strOrgId=UserInfo.getOrganizationID();
dipslaytable = EncodingUtil.base64Encode(d.body);
//d = EncodingUtil.urlEncode(d, 'ASCII');
//d = EncodingUtil.urlDecode(d, 'ASCII');
}
}
the document is just a word doc with a jpg
If all you want to do is make the user download the Document, simply make a redirect to the document itself:
try this!
Hope this helps