In Cache 2017, I am getting Error while loading a PDF on browser.
Hi All,
I am getting error while opening the PDF report in cache 2017 instance, I am using this below piece of code to open PDF in browser.
S pdf=objResult.FormattedReport // FormattedReport property is a %GlobalBinaryStream
D pdf.%Save()
D pdf.SetAttribute("ContentType","pdf")
D pdf.SetAttribute("Expires",0)
D pdf.SetAttribute("CONTENT","NO-CACHE")
S oid=pdf.%Oid()
S %session.Data("CacheStreamId")=oid
S StrOid=..Encrypt(oid)
W !,"<script type='text/javascript'>"
W !,"window.location='%25CSP.StreamServer.cls?STREAMOID="_StrOid_"';"
W !,"</script>"

Note: Interestingly the same piece of code is working in 2013 instance of cache for the same report data.
Could you please help me to figure out if there is any compatibility issues in code with respect to 2017 Cache?
Any help is very much appreciated. Thanks in Advance :)
Regards,
Arjun
Comments
Verify that calling method %Save is returning 1
Also, that the PDF stream is correctly created in Global ^CacheStream
Hi Juanito,
Yes %Save is returning 1. I see PDF Stream is getting saved in Global ^CacheStream but data is not in readable format.
Thank you,
Arjun
Found the root cause of it, there is no issues with above piece of code. Before that we were trying to Read the data form the stream using Read() without specifying the length. While reading for the first time data is getting truncated leaving PDF file corrupted and truncated.