none
List all fonts used in a powerpoint (pptx) document using with open XML SDK RRS feed

  • Question

  • How can i list all fonts from a powerpoint document using with Open XML SDK 2.0. I have got all fonts from word(docx) and excel(xlsx), thats available in fonttable but i dont know where can be found for powerpoint(pptx) documents. Please help me.
    • Edited by pc.johny Friday, March 23, 2012 6:17 AM
    • Moved by Dummy yoyoModerator Tuesday, March 27, 2012 7:27 AM (From:Visual C# General)
    Thursday, March 22, 2012 1:42 PM

All replies

  • Did you know that there is a special forum for Visual Studio Office Tools

    http://social.msdn.microsoft.com/Forums/en-US/vsto


    Success
    Cor

    Friday, March 23, 2012 6:41 AM
  • Hi pc. johny,

    Welcome to the MSDN forum!

    Based on my research, I'm afraid there is none direct way to list fonts of PPT slides using Open XML SDK.

    However, you can try the following ways:

            //using PPT = Microsoft.Office.Interop.PowerPoint; 
    
            static void Main(string[] args)
            {
                PPT._Application oApp = new PPT.Application();
                PPT.Presentation oPPT = 
                    oApp.Presentations.Open(@"E:\\Test\\Test.pptx", 
                    ReadOnly: Microsoft.Office.Core.MsoTriState.msoCTrue,
                    WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse);
    
                PPT.TextRange oTextRange;
                foreach (PPT.Slide oSlide in oPPT.Slides)
                {
                    foreach (PPT.Shape oShape in oSlide.Shapes)
                    {
                        oTextRange = oShape.TextFrame.TextRange;
                        Console.WriteLine(oTextRange.Font.Name + "   "+oTextRange.Font.Size);
                    }
                }
                oPPT.Close();
                oApp.Quit();
    
                oTextRange = null;
                oPPT = null;
                oApp = null;
    
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();            
    
                Console.WriteLine("Done!");
            }

    Hope it helps.

    Have a nice day.

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 7:19 AM
    Moderator
  • Hi Yoyo Jiang,

    Thank you for your replay and effort given here.

    I have tested this before, its fine. But If document is too big then it will take too much time for this execution. So am looking a specific solution with Open XML SDK. Like this i did for excel doc. 

                inti = -1;

                using(SpreadsheetDocumentexcel = SpreadsheetDocument.Open(filename, false))

                {

                    DocumentFormat.OpenXml.Spreadsheet.Fontsfonts = excel.WorkbookPart.WorkbookStylesPart.Stylesheet.Fonts;

                    foreach(DocumentFormat.OpenXml.Spreadsheet.Fontfont infonts)

                    {

                        fontName[i += 1] = font.FontName.Val;

                    }

                }

    Thanks and regards,

    Johny

    Tuesday, March 27, 2012 6:26 AM
  • Hi Cor Ligthert,

    I am looking a specific solution with Open XML SDK.

    Thanks ad regards,

    Johny

    Tuesday, March 27, 2012 6:27 AM
  • Hi Johny,

    Thanks for your post.

    Based on my knowledge, I am afraid it is impossible to list the fonts in OpenXML for pptx. 

    Also, I have moved the thread to the current OpenXML SDK forum to let more open xml experts involved.

    Thanks.
    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, March 27, 2012 7:30 AM
    Moderator
  • Hi Johny,

    Yeah, we can change font of characters in Excel and Word by assigning font ID, however, the fonts part doesn't exist in PowerPoint. If you open PowerPoint in XML format, you would see something like:

         <a:p>
          <a:r>
           <a:rPr b="1" i="1" sz="2000" lang="en-US" dirty="0" smtClean="0">
            <a:solidFill>
             <a:srgbClr val="FF0000"/>
            </a:solidFill>
            <a:latin charset="0" pitchFamily="66" typeface="Andy"/>
           </a:rPr>
           <a:t>
            Hello world
           </a:t>
          </a:r>
          <a:endParaRPr b="1" i="1" sz="2000" lang="en-US" dirty="0">
           <a:solidFill>
            <a:srgbClr val="FF0000"/>
           </a:solidFill>
           <a:latin charset="0" pitchFamily="66" typeface="Andy"/>
          </a:endParaRPr>
         </a:p>
    

    Every shape defines its font like this, there isn't a shared Fonts collection in PowerPoint. So I'm afraid you would have to custom font for each shape. But I think you can define a structure and a dictionary in your project to store your fonts to reuse them elsewhere.

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, March 27, 2012 7:59 AM
    Moderator

  • Thank you for kindness and help.

    Wednesday, March 28, 2012 9:27 AM
  • Hi Calvin,

    I agree we can find fonts from theme1.xml , but its difficult to figure out what are the fonts using in a document. My requirement is to list out fonts from a pptx document those are given by users.

    Thanks and regards,

    Johny

    Wednesday, March 28, 2012 9:34 AM