/// <summary>
        /// Do all the extraction to generate JSON
        /// </summary>
        public void extractSlide()
        {
            if (Globals.Ribbons.PowerPointStudioRibbon.ediBxExerKey.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("Please Enter Excercise Key First");
                return;
            }
            Application  pptApp       = new Application();
            Presentation presentation = pptApp.ActivePresentation;

            prevPresentationName = Globals.ThisAddIn.Application.ActivePresentation.Name; //it will be stored in a static variable for later use

            if (presentation.Name.Contains("pptx"))                                       //pptx files are only extractable
            {
                string pptPath = presentation.Path;                                       //Provides directory

                //Copying this presentation to the same original directory with temp name
                //All the work will be done on the copied presentation
                //So not visible to user
                if (File.Exists(pptPath + @"\temp\CSV.csv"))
                {
                    try
                    {
                        File.Delete(pptPath + @"\temp\CSV.csv");
                        if (File.Exists(pptPath + @"\temp\Json.JSON"))
                        {
                            File.Delete(pptPath + @"\temp\Json.JSON");
                        }
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show("Please close the CSV or JSON file if already opened");
                    }
                }


                while (Directory.Exists(pptPath + @"\temp"))
                {
                    //Waiting until the temp directory is successfully deleted
                    try
                    {
                        Directory.Delete(pptPath + @"\temp", true);
                    }
                    catch (Exception err)
                    {
                        //MessageBox.Show(err.ToString());
                    }
                }

                Directory.CreateDirectory(pptPath + @"\temp");

                File.Copy(pptPath + @"\" + presentation.Name, pptPath + @"\temp\temp.pptx");

                Presentation tempPresentation = pptApp.Presentations.Open(pptPath + @"/temp/temp.pptx", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                currentPPTPath = tempPresentation.Path;

                //Extract medias from this presentation and copy them in a medias folder
                //Setting media path
                mediaPath = Utility.createZipAndExtract(tempPresentation);  //Getting copy of the current presentation with zip extension path


                //Extract info from this tempPresentation
                ezPresentation cusPresentation = new ezPresentation(tempPresentation);

                //Creating and writing JSON
                Utility.writeJsonToFile(cusPresentation, currentPPTPath + "\\Json.JSON");


                //Close the presentation
                tempPresentation.Close();
                System.Windows.Forms.MessageBox.Show("Extraction Complete");

                Utility.staticResourceClear();
                prevTotalShapeCount = getTotalShapeCount(presentation);
                prevTotalSlideCount = presentation.Slides.Count;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Extraction is only possible with pptx files");
            }
        }
Пример #2
0
        /// <summary>
        /// Generate HTML from JSON of the ezPresentation
        /// </summary>
        /// <param name="JSON"></param>
        public HtmlGenerator(string JSON)
        {
            //delete directory if already exists
            if (Directory.Exists(PowerPointStudioRibbon.currentPPTPath + "\\HTML"))
            {
                Directory.Delete(PowerPointStudioRibbon.currentPPTPath + "\\HTML", true);
            }

            //Parse JSON to ezPresentation
            ezPresentation presentation = Newtonsoft.Json.JsonConvert.DeserializeObject <ezPresentation>(JSON);

            //Vatiables Global Level
            int PageWidth  = 960;
            int PageHeight = 700;


            int htmlCount = 0;

            //Generate HTML for all slides
            foreach (ezSlide slide in presentation.ezSlides)
            {
                string styleClass = "a {" +
                                    "  text-decoration: none;" +
                                    "  display: inline-block;" +
                                    "  padding: 8px 16px;" +
                                    "}" +
                                    "a:hover {" +
                                    "  background-color: #ddd;" +
                                    "  color: black;" +
                                    "}" +
                                    ".previous {" +
                                    "  background-color: #d49764;" +
                                    "  color: black;" +
                                    "}" +
                                    ".next {" +
                                    "  background-color: #4CAF50;" +
                                    "  color: white;" +
                                    "}" +
                                    ".round {" +
                                    "  border-radius: 50%;" +
                                    "}";

                string headHtml = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">" +
                                  "    <title>Test Application </title>" +
                                  "</head>" + "<style>" + styleClass + "</style>" +
                                  "<body style=\"width: " + PageWidth + "; height:" + PageHeight + ";  margin: 8px;\">";

                //headHtml = headHtml + SlideDiv(slide.backGround.image.actualUrl, (float)Convert.ToDouble(slide.backGround.css.width.Replace("px", "")),
                //    (float)Convert.ToDouble(slide.backGround.css.height.Replace("px", "")), (float)Convert.ToDouble(slide.backGround.css.left.Replace("px", "")),
                //    (float)Convert.ToDouble(slide.backGround.css.top.Replace("px", "")));

                foreach (ezShape shape in slide.shapes)
                {
                    if (shape.image.imgurlLarge != null)
                    {
                        string imageActualUrl = ((shape.image.imgurlLarge).Replace("https://ezilmdev.org", Globals.ThisAddIn.Application.ActivePresentation.Path + @"\temp")).Replace(@"/", @"\");

                        headHtml = headHtml + DivAdded(imageActualUrl, (float)Convert.ToDouble(shape.image.css.width.Replace("px", "")),
                                                       (float)Convert.ToDouble(shape.image.css.height.Replace("px", "")), (float)Convert.ToDouble(shape.image.css.left.Replace("px", "")),
                                                       (float)Convert.ToDouble(shape.image.css.top.Replace("px", "")), false, false, shape.image.css.rotation);
                    }
                }

                //Adding navigation button
                string navigation = "";

                if (htmlCount == 0 && presentation.ezSlides.Count > 1)
                {
                    navigation = "<div style=\"margin: 0px; position: absolute; top: 720px; left: 400px;\">" +
                                 "            <a href=\"html0.html\" class=\"previous\">&laquo; Previous</a><a href=\"html" + (htmlCount + 1) + ".html\" class=\"next\">Next &raquo;</a>" +
                                 "        </div>";
                    headHtml = headHtml + navigation;
                }
                else if (htmlCount == 0 && presentation.ezSlides.Count == 1)
                {
                    navigation = "<div style=\"margin: 0px; position: absolute; top: 720px; left: 400px;\">" +
                                 "            <a href=\"html0.html\" class=\"previous\">&laquo; Previous</a><a href=\"html" + (htmlCount) + ".html\" class=\"next\">Next &raquo;</a>" +
                                 "        </div>";
                    headHtml = headHtml + navigation;
                }
                else if (htmlCount < presentation.ezSlides.Count - 1)
                {
                    navigation = "<div style=\"margin: 0px; position: absolute; top: 720px; left: 400px;\">" +
                                 "            <a href=\"html" + (htmlCount - 1) + ".html\" class=\"previous\">&laquo; Previous</a><a href=\"html" + (htmlCount + 1) + ".html\" class=\"next\">Next &raquo;</a>" +
                                 "        </div>";
                    headHtml = headHtml + navigation;
                }
                else if (htmlCount < presentation.ezSlides.Count)
                {
                    navigation = "<div style=\"margin: 0px; position: absolute; top: 720px; left: 400px;\">" +
                                 "            <a href=\"html" + (htmlCount - 1) + ".html\" class=\"previous\">&laquo; Previous</a><a href=\"html" + (htmlCount) + ".html\" class=\"next\">Next &raquo;</a>" +
                                 "        </div>";
                    headHtml = headHtml + navigation;
                }


                string closeString;
                if (headHtml != "")
                {
                    closeString = @"</div></body>" + Environment.NewLine + @"</html > ";
                    headHtml    = headHtml + closeString;
                }

                //creates a directory to save html files
                if (!Directory.Exists(PowerPointStudioRibbon.currentPPTPath + "\\HTML"))
                {
                    Directory.CreateDirectory(PowerPointStudioRibbon.currentPPTPath + "\\HTML");
                }

                System.IO.File.WriteAllText(PowerPointStudioRibbon.currentPPTPath + "\\HTML" + "\\html" + htmlCount + ".html", headHtml);
                htmlCount++;
            }

            if (File.Exists(PowerPointStudioRibbon.currentPPTPath + "\\HTML" + "\\html" + 0 + ".html"))
            {
                Process.Start(PowerPointStudioRibbon.currentPPTPath + "\\HTML" + "\\html" + 0 + ".html");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("No HTML found");
            }
        }
        private System.Data.DataTable GetDataTableFromJSON(string JSON)
        {
            System.Data.DataTable dataTable = new System.Data.DataTable();
            ezPresentation        dt        = JsonConvert.DeserializeObject <ezPresentation>(JSON);

            dataTable.Columns.Add("sid", typeof(string));
            dataTable.Columns.Add("shapeId", typeof(string));
            dataTable.Columns.Add("shClass", typeof(string));
            dataTable.Columns.Add("objectType", typeof(string));//can not get this from JSON
            dataTable.Columns.Add("width", typeof(string));
            dataTable.Columns.Add("height", typeof(string));
            dataTable.Columns.Add("left", typeof(string));
            dataTable.Columns.Add("top", typeof(string));
            dataTable.Columns.Add("rotation", typeof(float));
            dataTable.Columns.Add("zindex", typeof(int));
            dataTable.Columns.Add("imagePath", typeof(string));
            dataTable.Columns.Add("uploadImagePath", typeof(string));
            dataTable.Columns.Add("imageUrlLarge", typeof(string));
            dataTable.Columns.Add("imageUrlMedium", typeof(string));
            dataTable.Columns.Add("imageUrlSmall", typeof(string));
            dataTable.Columns.Add("onClick", typeof(string));
            dataTable.Columns.Add("onHover", typeof(string));
            dataTable.Columns.Add("onLoad", typeof(string));
            dataTable.Columns.Add("audioUrl", typeof(string));

            foreach (ezSlide sld in dt.ezSlides)
            {
                //DataRow dataRow=null;
                foreach (ezShape shp in sld.shapes)
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow[0] = sld.sid;
                    dataRow[1] = shp.id;     //shape id
                    dataRow[2] = shp.@class; //shape.class
                    dataRow[3] = "N//A";     //objectType
                    if (shp.image.css != null)
                    {
                        dataRow[4] = shp.image.css.width;    //width
                        dataRow[5] = shp.image.css.height;   //height
                        dataRow[6] = shp.image.css.left;     //left
                        dataRow[7] = shp.image.css.top;      //top
                        dataRow[8] = shp.image.css.rotation; //rotation
                        dataRow[9] = shp.image.css.zIndex;   //zindex
                    }

                    if (shp.image.imgurlLarge != null)
                    {
                        dataRow[10] = currentPPTPath + (shp.image.imgurlLarge.Replace("https://ezilmdev.org", "")).Replace("/", @"\");                        //imagePath Actual
                        dataRow[11] = sld.sid.Replace("_", "/") + @"/" + sld.sid + "-" + (shp.image.imgurlLarge.Replace("https://ezilmdev.org/images/", "")); //uploadImagePath
                        dataRow[12] = shp.image.imgurlLarge;                                                                                                  //imageUrlLarge
                        dataRow[13] = shp.image.imgurlMedium;                                                                                                 //imageUrlMedium
                        dataRow[14] = shp.image.imgurlSmall;                                                                                                  //imageUrlSmall
                    }

                    if (shp.actions != null)
                    {
                        dataRow[15] = (shp.actions.onClick != null) ? shp.actions.onClick : ""; //onClick
                        dataRow[16] = (shp.actions.onHover != null) ? shp.actions.onHover : ""; //onHover
                        dataRow[17] = (shp.actions.onLoad != null) ? shp.actions.onLoad : "";   //onLoad
                    }
                    dataRow[18] = shp.audioUrl != null? shp.audioUrl:"";                        //audioUrl
                    dataTable.Rows.Add(dataRow);
                }
            }


            return(dataTable);
        }
Пример #4
0
 /// <summary>
 /// Generate HTML from ezPresentation
 /// </summary>
 /// <param name="presentation"></param>
 public HtmlGenerator(ezPresentation presentation)
 {
 }