コード例 #1
0
        //ExEnd:GetHTMLContentsWithExternalResources

        //ExStart:GetHTMLContentsWithEmbeddedResources
        /// <summary>
        /// Get HTML document with embedded resources.
        /// </summary>
        public static void GetHTMLContentsWithEmbeddedResources()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                //  Obtain HTML document with embedded resources
                string cssContent = htmlDoc.GetEmbeddedHtml();

                Console.WriteLine(cssContent);
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
コード例 #2
0
        private LoadDocumentEntity LoadDocument(string guid, string password)
        {
            try
            {
                dynamic options = null;
                //GroupDocs.Editor cannot detect text-based Cells documents formats (like CSV) automatically
                if (guid.EndsWith("csv", StringComparison.OrdinalIgnoreCase))
                {
                    options = new SpreadsheetToHtmlOptions();
                }
                else
                {
                    options = EditorHandler.DetectOptionsFromExtension(guid);
                }

                if (options is SpreadsheetToHtmlOptions)
                {
                    options.TextOptions = options.TextLoadOptions(",");
                }
                else
                {
                    options.Password = password;
                }
                string bodyContent;

                using (System.IO.FileStream inputDoc = System.IO.File.OpenRead(guid))

                    using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(inputDoc, options))
                    {
                        bodyContent = htmlDoc.GetEmbeddedHtml();
                    }
                LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();
                loadDocumentEntity.SetGuid(System.IO.Path.GetFileName(guid));
                PageDescriptionEntity page = new PageDescriptionEntity();
                page.SetData(bodyContent);
                loadDocumentEntity.SetPages(page);
                return(loadDocumentEntity);
            }
            catch
            {
                throw;
            }
        }