I want to show a PDF file of which I have the binary data in a TBytes variable, like so:
Var Bytes : TBytes;
Bytes := MyFunc();
I can successfully do the following to conventionally show the PDF to the user:
Application.DownloadPDFFile(Bytes,'MyDoc',False);
This downloads the file MyDoc.pdf and the file shows OK in the browser or Acrobat, so I know the data in Bytes are OK.
Now I want to show the PDF directly without the download step. I found something similar to what follows in a TMS Blog (TMS Software | Blog):
Var BlobURL : String;
ASM
BlobURL = window.URL.createObjectURL(new Blob([Bytes], { type: 'application/pdf' }));
End;
Application.Navigate(BlobURL)
or alternatively:
WebBrowserControl1.URL := BlobURL
Unfortunately, the BlobURL creation seems to create garbage, as all I get to see is a popup saying the PDF is unreadable.
I think my problem is that this step is not correct:
new Blob([Bytes], { type: 'application/pdf' })
as I input TBytes into the Blob() function whereas in the Blog article the input came from a HTTP request (ARequest.req.response). So the question is:
How would I correctly create the BlobURL from my Bytes?
Thank you very much!