Example #1
0
        //Export all the pages in a Wiki category into a index presentation, each page
        //will contain up to expPagining summaries. A summary will be composed up to
        //descSize characters taken from the first Header of the Page
        public void ExportIndex(string expCat, string outFileName, int expPaging, int descSize, WikiMedia.ExportNotify expNotify)
        {
            Microsoft.Office.Interop.PowerPoint.Slide     slide     = null;
            Microsoft.Office.Interop.PowerPoint.TextRange textRange = null;
            Presentation pres = new Presentation(fTemplatePath);
            PageList     pl   = wiki.GetPages(expCat);
            int          cnt  = 0;

            foreach (Page page in pl)
            {
                string title = GetTitle(page);
                if (title == null)
                {
                    continue;
                }
                cnt++;
                if ((cnt % expPaging) == 1)
                {
                    slide     = pres.Add(Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText, GetTitleName(expCat));
                    textRange = slide.Shapes[2].TextFrame.TextRange;
                }
                if (expNotify != null)
                {
                    expNotify(page.title);
                }
                page.LoadHTML();
                Document doc = HTML2Model.Convert(page.text);
                AddFirstHeader(textRange, doc, page, title, descSize);
            }
            pres.Save(fBasePath + outFileName);
            pres.Close();
        }
Example #2
0
 //Try to preserve Text element formatting into the PowerPoint TextRange
 public void CopyFormatting(Text t, Microsoft.Office.Interop.PowerPoint.TextRange tr)
 {
     if (t.bold)
     {
         tr.Font.Bold = MsoTriState.msoTrue;
     }
     else
     {
         tr.Font.Bold = MsoTriState.msoFalse;
     }
     if (t.italic)
     {
         tr.Font.Italic = MsoTriState.msoTrue;
     }
     else
     {
         tr.Font.Italic = MsoTriState.msoFalse;
     }
     if (t.underline)
     {
         tr.Font.Underline = MsoTriState.msoTrue;
     }
     else
     {
         tr.Font.Underline = MsoTriState.msoFalse;
     }
 }
Example #3
0
            public static void addText()
            {
                try
                {
                    //addind text to the slides
                    objSlide   = objSlides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
                    objTextRng = objSlide.Shapes[1].TextFrame.TextRange;

                    objTextRng.Text      = "VDI POWER POINT TEST";
                    objTextRng.Font.Name = "Comic Sans MS";
                    objTextRng.Font.Size = 48;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Adding Text to " + fileName + " failed");
                }
            }
Example #4
0
        //Create slides with the index of all the pages in a wiki category
        //Pages will be subdivided into two columns and paged in pageSize elements per page
        public void Index2Slide(Presentation pres, PageList pl, string indexName, int pageSize)
        {
            Microsoft.Office.Interop.PowerPoint.Slide     idexSlide;
            Microsoft.Office.Interop.PowerPoint.TextRange index1 = null;
            Microsoft.Office.Interop.PowerPoint.TextRange index2 = null;
            Microsoft.Office.Interop.PowerPoint.TextRange index  = null;
            int  cnt   = 0;
            bool first = true;

            foreach (Page page in pl)
            {
                string title = GetTitle(page);
                if (title == null)
                {
                    continue;
                }
                if ((cnt % pageSize) == 0)
                {
                    idexSlide = pres.Add(Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTwoColumnText, indexName);
                    index1    = idexSlide.Shapes[2].TextFrame.TextRange;
                    index2    = idexSlide.Shapes[3].TextFrame.TextRange;
                    first     = true;
                }
                if ((cnt % 2) == 0)
                {
                    index = index1;
                }
                else
                {
                    index = index2;
                }
                if (!first)
                {
                    index.Text += Presentation.SEP;
                }
                index.Text += title;
                if ((cnt % 2) != 0)
                {
                    first = false;
                }
                cnt++;
            }
        }
Example #5
0
        //Convert the first "not empty" header element in a document model into a TextRange
        //composed by an hyperlink to the page and a summary composed up to "size" charactes.
        public void AddFirstHeader(Microsoft.Office.Interop.PowerPoint.TextRange parent, Document doc, Page page, string title, int size)
        {
            Microsoft.Office.Interop.PowerPoint.TextRange tr1;
            tr1             = parent.InsertAfter("\r");
            tr1.IndentLevel = 1;
            Microsoft.Office.Interop.PowerPoint.Hyperlink link = tr1.ActionSettings[Microsoft.Office.Interop.PowerPoint.PpMouseActivation.ppMouseClick].Hyperlink;
            link.Address       = wiki.site.site + wiki.site.indexPath + "index.php?title=" + HttpUtility.UrlEncode(page.title);
            link.TextToDisplay = title;
            tr1.InsertAfter(". ");
            int len = tr1.Text.Length;

            for (int i = 0; i < doc.headers.Count; i++)
            {
                Header header = doc.headers[i];
                if (!IsEmptyHeader(header))
                {
                    tr1.InsertAfter(Header2Text(header, 0, size - title.Length, true));
                    break;
                }
            }
            tr1.InsertAfter("\r");
        }
Example #6
0
        public void processFBRReport(string fbrFileLocation)
        {
            DataRow dr = dtFBR.NewRow();

            dr["FILE_NAME"] = Path.GetFileName(fbrFileLocation);

            var stringBuilder = new StringBuilder();

            Microsoft.Office.Interop.PowerPoint.Application pptApp =
                new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations pptPresentations =
                pptApp.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation =
                pptPresentations.Open(fbrFileLocation,
                                      Microsoft.Office.Core.MsoTriState.msoTrue,
                                      Microsoft.Office.Core.MsoTriState.msoFalse,
                                      Microsoft.Office.Core.MsoTriState.msoFalse);

            Microsoft.Office.Interop.PowerPoint.Slides pptSlides = pptPresentation.Slides;

            Graphics gr = this.CreateGraphics();

            var slidesCount = pptSlides.Count;
            int imgCrt      = 0;

            for (int slideIndex = 1; slideIndex <= slidesCount; slideIndex++)
            {
                var slide = pptSlides[slideIndex];

                foreach (Microsoft.Office.Interop.PowerPoint.Shape textShape in slide.Shapes)
                {
                    if (textShape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                    {
                        listofImages.Add(textShape);

                        imgCrt++;
                        textShape.Export(sPowerPointFolderImg + textShape.ZOrderPosition.ToString()
                                         + "-" + ((textShape.Left * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Top * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Width * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Height * gr.DpiX) / 72).ToString("0.00")
                                         + ".png",
                                         Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG,
                                         0,
                                         0,
                                         Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                    }

                    if (textShape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue &&
                        textShape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                    {
                        Microsoft.Office.Interop.PowerPoint.TextRange pptTextRange = textShape.TextFrame.TextRange;

                        if (pptTextRange != null && pptTextRange.Length > 0)
                        {
                            stringBuilder.Append(" " + pptTextRange.Text);

                            if (pptTextRange.Text.StartsWith("ACTUAL CUSTOMER COMPLAINT") == true)
                            {
                                string tmpString = pptTextRange.Text;
                                tmpString = pptTextRange.Text.Replace("ACTUAL CUSTOMER COMPLAINT", string.Empty);

                                dr["ACTUAL CUSTOMER COMPLAINT"] = tmpString.Replace(",", "").Replace("\r", String.Empty);
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().Equals("MARKET FEED BACK") == true)
                            {
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().StartsWith("RANK:") == true)
                            {
                                string tmpString = pptTextRange.Text.ToUpper();
                                tmpString = pptTextRange.Text.Replace("RANK:", string.Empty);
                                var regex = new Regex(Regex.Escape("\r"));
                                tmpString = regex.Replace(tmpString, "", 1);

                                dr["RANK"] = tmpString;
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().StartsWith("TRACKING #") == true)
                            {
                                string tmpString = pptTextRange.Text.ToUpper();
                                tmpString      = tmpString.ToUpper().Replace("TRACKING #:", string.Empty);
                                dr["TRACKING"] = tmpString.Replace(",", "").Replace("\r", String.Empty);
                            }
                            else if (pptTextRange.Text.Trim().StartsWith("This sheet is intended for quick feed back to increase associate") == true)
                            {
                            }
                            else if (pptTextRange.Text.Trim().Equals("For Reference Only") == true)
                            {
                            }
                            else
                            {
                                if (textShape.Name.ToString().Equals("Title 1") == true)
                                {
                                    dr["TITLE"] = pptTextRange.Text.Replace(",", "").Replace("\r", String.Empty);
                                }
                            }
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptTextRange);
                        }
                    }

                    if (textShape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
                    {
                        if (textShape.Table.Rows.Count > 1)
                        {
                            int iNumRows = textShape.Table.Rows.Count;
                            int iNumCols = textShape.Table.Rows[1].Cells.Count;

                            string sKey = textShape.Table.Rows[1].Cells[1].Shape.TextFrame.TextRange.Text;
                            if ((sKey.Trim().ToUpper().Equals("VIN") == true) ||
                                (sKey.Trim().ToUpper().Equals("PART NAME") == true) ||
                                (sKey.Trim().ToUpper().Equals("CUSTOMER CONCERN:") == true) ||
                                (sKey.Trim().ToUpper().Equals("DEALER REPAIR:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ADDITIONAL DETAILS:") == true) ||
                                (sKey.Trim().ToUpper().Equals("CLAIM COST:") == true)
                                )
                            {
                                //Process VIN Block
                                for (int iCol = 1; iCol <= iNumCols; iCol++)
                                {
                                    dr[textShape.Table.Rows[1].Cells[iCol].Shape.TextFrame.TextRange.Text] =
                                        textShape.Table.Rows[2].Cells[iCol].Shape.TextFrame.TextRange.Text.Replace(",", String.Empty).Replace("\r", String.Empty);
                                }
                            }
                            if ((sKey.Trim().ToUpper().Equals("MODEL:") == true) ||
                                (sKey.Trim().ToUpper().Equals("DEPT:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ISSUED DATE:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ISSUER:") == true)
                                )
                            {
                                //Process VIN Block
                                for (int iRow = 1; iRow <= iNumRows; iRow++)
                                {
                                    dr[textShape.Table.Rows[iRow].Cells[1].Shape.TextFrame.TextRange.Text] =
                                        textShape.Table.Rows[iRow].Cells[2].Shape.TextFrame.TextRange.Text.Replace(",", "");
                                }
                            }
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(textShape);
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(slide);
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptSlides);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentation);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentations);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);

            dtFBR.Rows.Add(dr);
            string[] filePaths = Directory.GetFiles(sPowerPointFolderImg);

            int min_left   = 10000000;
            int min_top    = 10000000;
            int max_bottom = 0;
            int max_right  = 0;

            foreach (string filePath in filePaths)
            {
                string   imagefilename = Path.GetFileNameWithoutExtension(filePath);
                string[] filesplit     = imagefilename.Split('-');

                imageInfo imgInfoObj = new imageInfo();
                imgInfoObj.position = Convert.ToInt32(filesplit[0]);
                imgInfoObj.left     = Convert.ToInt32(filesplit[1].Substring(0, filesplit[1].IndexOf('.')));
                imgInfoObj.top      = Convert.ToInt32(filesplit[2].Substring(0, filesplit[2].IndexOf('.')));
                imgInfoObj.width    = Convert.ToInt32(filesplit[3].Substring(0, filesplit[3].IndexOf('.')));
                imgInfoObj.height   = Convert.ToInt32(filesplit[4].Substring(0, filesplit[4].IndexOf('.')));
                imgInfoObj.filename = filePath;
                dicImageFileInfo.Add(imgInfoObj.position, imgInfoObj);

                if (imgInfoObj.left < min_left)
                {
                    min_left = imgInfoObj.left;
                }
                if (imgInfoObj.top < min_top)
                {
                    min_top = imgInfoObj.top;
                }
                if (max_bottom < (imgInfoObj.height + imgInfoObj.top))
                {
                    max_bottom = (imgInfoObj.height + imgInfoObj.top);
                }
                if (max_right < (imgInfoObj.left + imgInfoObj.width))
                {
                    max_right = imgInfoObj.left + imgInfoObj.width;
                }
            }

            List <int> list = dicImageFileInfo.Keys.ToList();

            list.Sort();

            Bitmap target = new Bitmap(max_right - min_left + 50, max_bottom - min_top + 50);

            using (Graphics g = Graphics.FromImage(target))
            {
                g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;

                foreach (var key in list)
                {
                    imageInfo temImgInfo = (imageInfo)dicImageFileInfo[key];
                    Bitmap    src        = Image.FromFile(temImgInfo.filename) as Bitmap;

                    g.DrawImage(src,
                                (temImgInfo.left - min_left),
                                ((temImgInfo.top - min_top)));
                    src.Dispose();
                }

                g.Dispose();
            }
            string sImageNameCropTemp = sPowerPointFolderImgProcessed + Path.GetFileName(fbrFileLocation) + "_MergedImages.png";

            target.Save(sImageNameCropTemp);
            dicImageFileInfo.Clear();
            target.Dispose();
            gr.Dispose();
            Array.ForEach(Directory.GetFiles(sPowerPointFolderImg), File.Delete);
        }
Example #7
0
        //Convert an header element into PowerPoint TextRage
        public void AddHeader(Microsoft.Office.Interop.PowerPoint.TextRange parent, Header header, bool firstSpecial, int maxElems)
        {
            Microsoft.Office.Interop.PowerPoint.TextRange tr = null;
            if ((maxElems < 1) || (maxElems > header.elements.Count))
            {
                maxElems = header.elements.Count;
            }
            bool trim = true;

            for (int i = 0; i < maxElems; i++)
            {
                Element e = header.elements[i];
                if (e is NewLine)
                {
                    trim = true;
                    tr   = parent.InsertAfter("\r");
                    tr   = null;
                }
                else
                {
                    string row = e.ToString();
                    if (trim)
                    {
                        row = row.TrimStart();
                    }
                    trim = false;
                    int level = 1;
                    if (!String.IsNullOrEmpty(row))
                    {
                        if (e is ListItem)
                        {
                            level          = (e as ListItem).level + 1;
                            tr             = parent.InsertAfter(row.Trim() + "\r");
                            tr.IndentLevel = level;
                            trim           = true;
                        }
                        else if (e is HyperLink)
                        {
                            HyperLink link = e as HyperLink;
                            if (tr == null)
                            {
                                tr = parent;
                            }
                            tr = tr.InsertAfter(" ");
                            Microsoft.Office.Interop.PowerPoint.Hyperlink l = tr.ActionSettings[Microsoft.Office.Interop.PowerPoint.PpMouseActivation.ppMouseClick].Hyperlink;
                            string url = link.URL;
                            if (url != null)
                            {
                                if ((!url.StartsWith("http:")) || (!url.StartsWith("mailto:")))
                                {
                                    url = wiki.site.site + url;
                                }
                                l.Address = url;
                            }
                            l.TextToDisplay = link.text.ToString();
                        }
                        else
                        {
                            tr = parent.InsertAfter(row);
                            if (e is Text)
                            {
                                CopyFormatting(e as Text, tr);
                            }
                        }
                    }
                }
            }
            if (firstSpecial)
            {
                if (header.elements.Count == 1)
                {
                    tr.ParagraphFormat.Bullet.Visible = MsoTriState.msoFalse;
                    tr.Text = '\t' + tr.Text;
                }
            }
        }