Exemple #1
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            // Creating a new document.
            WordDocument document    = new WordDocument();
            Stream       inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.WordtoHTML.doc");

            //Open the Word document to convert
            document.Open(inputStream, FormatType.Doc);
            //Export the Word document to HTML file
            MemoryStream stream     = new MemoryStream();
            HTMLExport   htmlExport = new HTMLExport();

            htmlExport.SaveAsXhtml(document, stream);
            document.Close();
            stream.Position = 0;
            StreamReader reader     = new StreamReader(stream);
            string       htmlString = reader.ReadToEnd();

            isGenerateButtonClicked = true;
            UIWebView webView = new UIWebView(this.Bounds);

            webView.Frame = new CGRect(0, 0, this.Bounds.Width, this.Bounds.Height);
            this.AddSubview(webView);
            webView.LoadHtmlString(htmlString, NSBundle.MainBundle.BundleUrl);
            webView.ScalesPageToFit = false;
        }
        /// <summary>
        /// Generate html string from document template
        /// </summary>
        /// <returns>string of html</returns>
        public string GenerateHtml()
        {
            ProcessDocument();
            ProcessDocumentGroup();
            HTMLExport export = new HTMLExport();

            export.SaveAsXhtml(DocumentTemplate, HTMLStreamOutput);
            StreamReader reader = new StreamReader(HTMLStreamOutput);

            HTMLStreamOutput.Position = 0;
            return(reader.ReadToEnd());
        }
Exemple #3
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = typeof(WordToHTML).GetTypeInfo().Assembly;
            // Creating a new document.
            WordDocument document = new WordDocument();

#if COMMONSB
            string rootPath = "SampleBrowser.Samples.DocIO.Samples.Templates.";
#else
            string rootPath = "SampleBrowser.DocIO.Samples.Templates.";
#endif
            Stream inputStream = assembly.GetManifestResourceStream(rootPath + "WordtoHTML.doc");
            //Open the Word document to convert
            document.Open(inputStream, FormatType.Doc);
            //Export the Word document to HTML file
            MemoryStream stream     = new MemoryStream();
            HTMLExport   htmlExport = new HTMLExport();
            htmlExport.SaveAsXhtml(document, stream);
            document.Close();

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("WordtoHTML.html", "application/html", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("WordtoHTML.html", "application/html", stream);
            }
            if (!(Device.Idiom != TargetIdiom.Phone && Device.RuntimePlatform == Device.UWP))
            {
                //Set the stream to start position to read the content as string
                stream.Position = 0;
                StreamReader reader     = new StreamReader(stream);
                string       htmlString = reader.ReadToEnd();

                //Set the HtmlWebViewSource to the html string
                HtmlWebViewSource html = new HtmlWebViewSource();
                html.Html = htmlString;

                //Create the web view control to view the web page
                WebView view = new WebView();
                view.Source = html;
                ContentPage webpage = new ContentPage();
                webpage.Content = view;
                this.Content.Navigation.PushAsync(webpage);
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (this.textBox1.Text != String.Empty)
                {
                    //Open the document to convert from word to HTML
                    WordDocument doc = new WordDocument(textBox1.Tag.ToString());
                    //Export the document to HTML and save as .html file
                    HTMLExport htmlExport = new HTMLExport();
                    htmlExport.SaveAsXhtml(doc, "DocToHtml.html");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the HTML file?", "File has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("DocToHtml.html")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("DocToHtml.html");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    MessageBoxAdv.Show("Browse a word document and click the button to convert as a HTML.");
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = typeof(App).GetTypeInfo().Assembly;
            // Creating a new document.
            WordDocument document = new WordDocument();
            Stream inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.WordtoHTML.doc");
            //Open the Word document to convert
            document.Open(inputStream, FormatType.Doc);
            //Export the Word document to HTML file
            MemoryStream stream = new MemoryStream();
            HTMLExport htmlExport = new HTMLExport();
            htmlExport.SaveAsXhtml(document, stream);
            document.Close();

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("WordtoHTML.html", "application/html", stream);
            else
                Xamarin.Forms.DependencyService.Get<ISave>().Save("WordtoHTML.html", "application/html", stream);
            if (!(Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows))
            {
                //Set the stream to start position to read the content as string
                stream.Position = 0;
                StreamReader reader = new StreamReader(stream);
                string htmlString = reader.ReadToEnd();

                //Set the HtmlWebViewSource to the html string
                HtmlWebViewSource html = new HtmlWebViewSource();
                html.Html = htmlString;

                //Create the web view control to view the web page
                WebView view = new WebView();
                view.Source = html;
                ContentPage webpage = new ContentPage();
                webpage.Content = view;
                this.ContentView.Navigation.PushAsync(webpage);
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            // Creating a new document.
            WordDocument document    = new WordDocument();
            Stream       inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.WordtoHTML.doc");

            //Open the Word document to convert
            document.Open(inputStream, FormatType.Doc);
            //Export the Word document to HTML file
            MemoryStream stream     = new MemoryStream();
            HTMLExport   htmlExport = new HTMLExport();

            htmlExport.SaveAsXhtml(document, stream);
            document.Close();
            //Set the stream to start position to read the content as string
            stream.Position = 0;
            StreamReader reader     = new StreamReader(stream);
            string       htmlString = reader.ReadToEnd();
            Intent       i          = new Intent(m_context, typeof(WebViewActivity));

            i.PutExtra("HtmlString", htmlString);
            m_context.StartActivity(i);
        }