Created
October 13, 2023 14:19
-
-
Save bjoerntx/606e1e4e7aae5cc5696422296f7ba7bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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