Example #1
0
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName          = "Document";
            pp.OverallOperationTotalElements = 2;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement       = 1;
            pp.CurrentOperationName          = "Opening";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            Document document = new Document();

            document.Name     = path.Substring(path.LastIndexOf(DD) + 1);
            document.Location = folderName;

            //write directory for pages
            String pagesPath = System.IO.Path.Combine(documentPath + DD + DOC_FILES);

            System.IO.Directory.CreateDirectory(pagesPath);

            Page page = new Page();

            page.Name = document.Name;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            pp.OverallOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //location where the page is generated
            page.Location = WriteTextDocument(path, documentPath + DD + DOC_FILES + DD + DOCUMENT_HTML);
            document.Pages.Add(page);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            pp.OverallOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //return the built document
            return(document);
        }
Example #2
0
        /// <summary>
        /// parse an excel document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the excel document</param>
        /// <returns>equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the given excel document
            Workbook workbook = excelApplication.Workbooks.Open(path, ReadOnly: true);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            pp.CurrentOperationName    = "Saving pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //create a new internal document
            Document document = new Document();

            document.Name = workbook.Name;

            //save excel document as html
            workbook.SaveAs(System.IO.Path.Combine(documentPath, "document.html"), XlFileFormat.xlHtml);

            //original document location
            document.Location = folderName;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 2;
            pp.OverallOperationTotalElements = workbook.Sheets.Count + 1;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every sheet
            for (int i = 1; i <= workbook.Sheets.Count; i++)
            {
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName          = "Page " + i;
                pp.CurrentOperationTotalElements = 1;
                pp.CurrentOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                Worksheet worksheet = workbook.Sheets[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
                page.Name = worksheet.Name;

                //standard export location of ms excel when exporting as html
                page.Location = documentPath + DD + DOC_FILES + DD + "sheet" + GetSheetNumber(i) + ".html";


                //add page to the document
                document.Pages.Add(page);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            //close workbook without saving any possible changes (this way the "Are you sure?" or "Save changes?" dialogs will be supressed)
            workbook.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement++;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //every generated page contains several javascript functions which facilitate navigation between sheets and other unnecessary stuff
            //this is an impediment for kinesis web browser, because will block the programatic scrolling
            //get every generated page and remove javascripts

            int pageNumber = 1;

            foreach (KineSis.ContentManagement.Model.Page p in document.Pages)
            {
                ProcessSheet(p.Location, pp, pageNumber++);
            }

            //return the built document
            return(document);
        }
Example #3
0
        /// <summary>
        /// parse a picture
        /// </summary>
        /// <param name="path">full path of the picture</param>
        /// <returns>an equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName          = "Document";
            pp.OverallOperationTotalElements = 2;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement       = 1;
            pp.CurrentOperationName          = "Opening";
            pp.CurrentOperationTotalElements = 3;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            Document document = new Document();

            document.Name     = path.Substring(path.LastIndexOf(DD) + 1); //only the filename alone
            document.Location = folderName;

            //write directory for pages
            String pagesPath = documentPath + DD + DOC_FILES;

            System.IO.Directory.CreateDirectory(pagesPath);

            //new page
            Page page = new Page();

            page.Name = document.Name;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //location of the page content
            page.Location = WritePictureDocument(path, pagesPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            pp.OverallOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            page.LocationNoZoom = WritePictureDocumentNoZoom(path, pagesPath);

            //add page to the document
            document.Pages.Add(page);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 3;
            pp.OverallOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //return the built document model
            return(document);
        }
Example #4
0
        /// <summary>
        /// parse a word document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the word document</param>
        /// <returns>equivalent kinesis document model</returns>
        KineSis.ContentManagement.Model.Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();


            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            // Make this instance of word invisible (Can still see it in the taskmgr).
            wordApplication.Visible = false;

            // Interop requires objects.
            object oMissing  = System.Reflection.Missing.Value;
            object isVisible = false;
            object readOnly  = false;
            object oInput    = path;
            object oOutput   = documentPath + DD + DOC_FILES + DD + "document.xps";
            object oFormat   = WdSaveFormat.wdFormatXPS;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Load a document into our instance of word.exe
            Microsoft.Office.Interop.Word._Document wdoc = wordApplication.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            // Make this document the active document.
            wdoc.Activate();

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            KineSis.ContentManagement.Model.Document document = new KineSis.ContentManagement.Model.Document();
            document.Name     = wdoc.Name;
            document.Location = folderName;

            //write directory for pages
            String pagesPath = documentPath + DD + DOC_FILES;

            System.IO.Directory.CreateDirectory(pagesPath);

            //create a new page
            KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
            page.Name     = wdoc.Name;
            page.Location = documentPath + DD + DOC_FILES + DD + "document.html";

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Saving document";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Save this document in XPS format.
            wdoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            wdoc.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            try
            {
                wdoc.Close(SaveChanges: false);
            }
            catch (Exception)
            {
            }
            //CloseOfficeApplication();
            //wordApplication.Quit(ref oMissing, ref oMissing, ref oMissing);

            BuildDocumentHTMLArgs args = new BuildDocumentHTMLArgs(documentPath + DD + DOC_FILES, pp);

            Thread thread = new Thread(new ParameterizedThreadStart(BuildDocumentHTML));

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(args);
            thread.Join();

            //build a html page from saved xps
            //BuildDocumentHTML(documentPath + DD + DOC_FILES, pp);

            //add page to document model
            document.Pages.Add(page);

            //delete the generated xps file
            FileInfo fi = new FileInfo(documentPath + DD + DOC_FILES + DD + "document.xps");

            fi.Delete();

            //return built document
            return(document);
        }
Example #5
0
        /// <summary>
        /// parse a power point document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the power point document</param>
        /// <param name="pp">processing progress reporter</param>
        /// <returns>equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the presentation
            Presentation presentation = powerPointApplication.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);

            Document document = new Document();

            document.Name     = presentation.Name;
            document.Location = folderName;

            //write directory for pages
            String pagesPath = System.IO.Path.Combine(documentPath + DD + DOC_FILES);

            System.IO.Directory.CreateDirectory(pagesPath);

            int H = (int)(DocumentService.SLIDE_WIDTH * presentation.SlideMaster.Height / presentation.SlideMaster.Width);
            int W = DocumentService.SLIDE_WIDTH;

            int T_H = (int)(DocumentService.THUMB_WIDTH * H / W);
            int T_W = DocumentService.THUMB_WIDTH;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 1;
            pp.OverallOperationTotalElements = presentation.Slides.Count;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every slide
            for (int i = 1; i <= presentation.Slides.Count; i++)
            {
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName          = "Page " + i;
                pp.CurrentOperationTotalElements = 4;
                pp.CurrentOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //get slide
                Slide slide = presentation.Slides[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
                page.Name = slide.Name;

                //export the slide as image
                slide.Export(documentPath + DD + DOC_FILES + DD + SLIDE + i + ImageUtil.PNG_EXTENSION, ImageUtil.PNG_FILTER, W, H);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //export the slide as image
                slide.Export(documentPath + DD + DOC_FILES + DD + SLIDE + i + "_thumb" + ImageUtil.PNG_EXTENSION, ImageUtil.PNG_FILTER, T_W, T_H);

                page.SetThumbnailUrl(documentPath + DD + DOC_FILES + DD + SLIDE + i + "_thumb" + ImageUtil.PNG_EXTENSION);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 2;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //html page location, including the no-zoom version
                page.Location = GenerateHtmlPage(documentPath + DD + DOC_FILES + DD + SLIDE + i);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 3;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                page.LocationNoZoom = GenerateHtmlPageNoZoom(documentPath + DD + DOC_FILES + DD + SLIDE + i);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 4;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //add page to document model
                document.Pages.Add(page);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.OverallOperationElement = i;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            //close presentation
            presentation.Close();

            //return built document
            return(document);
        }