We are trying to make an integration app for salesforce. The flow is:
My Apex Code (the relevant bits)
public class POCApexClass {
public Blob pdfContent{get;set;}
public Blob pdfContent2{get;set;}
public string pdfContentBase64{get;set;}
public void CommunicationRequestDemoPDF(){
OutputDocument doc = GetDoc();
pdfContentBase64 = doc.outputBase64;
pdfContent = EncodingUtil.base64Decode(pdfContentBase64);
pdfContent2 = Blob.toPDF(pdfContentBase64);
}
}
If there's apex code that will just open the file in the browser or another app or something that would be perfect. It does seem like I might need to use visualForce code for that? I've tried several approaches there.
<apex:page controller="POCApexClass" action="{!CommunicationRequestDemoPDF}">
<apex:form >
Sample PDF
</apex:form>
<apex:outputPanel >
<object data="data:application/pdf;base64,{!pdfContentBase64}"></object>
<!--
<iframe src="/apex/RenderPDFPage?base64String={!pdfContentBase64}" width="100%" height="300px" frameborder="0"></iframe>
<apex:outputText value="{!pdfContent2}" escape="false"/>
<script>
window.location.href = "data:application/pdf;base64,{!pdfContentBase64}";
</script>
-->
</apex:outputPanel>
</apex:page>
They all spit out the error: Maximum view state size limit (170KB) exceeded. Actual view state size for this page was 192.954KB
Is there any way to boost the frame size? or a way for it to display in a new window? or just get downloaded and opened like a normal PDF?
I'm hitting walls every way I look, thanks for the help.
If the answer is you just cannot open anything but small PDFs that's fine too.
Mark your class variables "transient", so "public transient Blob....", this should cause them to not count towards viewstate.
Next limit you'll hit will be 6MB heap size (kind of RAM usage) so you could shave some by deleting unused variables. Going past that will be bit tricky so if it's transmitter as base64 you lose some for encoding overhead, your real max will be 4.27MB of useful file size. Past that you'd need to experiment with async apex like continuations, multipart files... Or reverse the flow, have the external system push files to SF, save them with standard API (up to 2 GB limit) and then you just render link to the file + periodically purge old files?
Visual force works but it's rendered in iframe and then you have yet another iframe in your own code. Bit meh. What's your goal? Display file preview / mini window? Trigger browser's file download prompt (and then browser/user preferences decide whether it'll be new tab, new window or really save to disk)?