Skip to content

Instantly share code, notes, and snippets.

@heejune
Created June 21, 2016 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heejune/d5d7150371038cc3fc25cd869d84c538 to your computer and use it in GitHub Desktop.
Save heejune/d5d7150371038cc3fc25cd869d84c538 to your computer and use it in GitHub Desktop.
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