Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 13, 2023 14:19
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 bjoerntx/606e1e4e7aae5cc5696422296f7ba7bd to your computer and use it in GitHub Desktop.
Save bjoerntx/606e1e4e7aae5cc5696422296f7ba7bd to your computer and use it in GitHub Desktop.
private void menuItemLoad_Click(object sender, EventArgs e)
{
// set filter to tx and pdf
openFileDialog1.Filter = "TX Text Control Documents (*.tx)|*.tx|PDF Documents (*.pdf)|*.pdf";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// load the document into a byte array
var bytes = File.ReadAllBytes(openFileDialog1.FileName);
// get the filename
string filename = Path.GetFileName(openFileDialog1.FileName);
// convert the byte array to a Base64 string
var stringBase64 = Convert.ToBase64String(bytes);
// create a JavaScript string that calls the loadDocument() function
string loadSettings = "{ pdfjs: { basePath: 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146' } }";
string js = "TXDocumentViewer.loadDocument('" + stringBase64 + "', '" + filename + "', null, " + loadSettings + ");";
// execute the JavaScript string
webView21.ExecuteScriptAsync(js);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment