Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert the PDF file into base64 string and pass it to the webbrowser control
if (locateText.Text.EndsWith("pdf", true, null) == true &&
File.Exists(locateText.Text) == true)
{
var buffer = File.ReadAllBytes(locateText.Text);
// Document.InvokeScript seems not understanding the Blob type
//object[] args = { fileBytes };
//webBrowser1.Document.InvokeScript("PDFViewerApplication.open", args);
// so convert it to base64 and pass it
var asBase64 = Convert.ToBase64String(buffer);
webBrowser1.Document.InvokeScript("openPdfAsBase64", new[] { asBase64 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment