I have a Webview2 Control in my application, used to view PDF documents.
The application also stores to and reads from MS SQL server PDFs data.
Currently, I am retrieving binary data from SQL, convert them to a temporary file to disk and set:
webview2.source = New Uri("file://" + filename)
That's working fine so far, but of course I would like to do the job without writing and reading to and from disk.
Is there a way to do the same without accessing the disk?
Update (as recommended), what I tried. With part of code for better understandg:
Dim fieldOrdinal = reader.GetOrdinal(ColumnName)
reader.Read()
Dim blob = New Byte(reader.GetBytes(fieldOrdinal, 0, Nothing, 0, 0) - 1) {}
reader.GetBytes(fieldOrdinal, 0, blob, 0, blob.Length)
Dim pdfBase64 As String = Convert.ToBase64String(blob)
Dim html As String = "<!DOCTYPE html><html><head></head><body><div>" & $"<iframe width=100% height=500 src=\" & Chr(&H22) & "data:Application/pdf;base64,{pdfBase64}\" & Chr(&H22) & ">" & "</iframe></div></body></html>"
The webview2
control shows a frame, but without content
Final Update: Here the (correct) to VB translated and working code:
Dim html As String = "<!DOCTYPE html><html><head></head><body><div>" & $"<iframe width=100% height=500 src=""data:Application/pdf;base64,{pdfBase64}"">" & "</iframe></div></body></html>"
src
needs to be surrounded in quotes. Also the backslash was an escape for"
in C#. – Haplo