none
Font size issue Text rendered In PPT generated by Open xml. RRS feed

  • Question

  • Hi there 

    we are using the open xml tech to generate the ppt. when we use empty line with bullets formated text it is showning bigger line height then the size mentiond for complete text. dont know why this is heppen.

    to render the text from red document we are using below code:

    RadDocument document = newXamlFormatProvider().Import(xamlData);                 MemoryStream memStrm = newMemoryStream();                 newDocxFormatProvider().Export(document, memStrm);                 // open the docx in memory and get the paragraphs, bullets, runs, etcusing (Package docxPackage = Package.Open(memStrm, FileMode.Open, FileAccess.Read))                 using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(docxPackage))                 {

    var paragraphs = wordDoc.MainDocumentPart.Document.Body.Elements<W.Paragraph>();                     // iterate docx paragraphs and create Powerpoint paragraphs with same dataforeach (var docxPara in paragraphs)                     {                         // make a new pptx paragraph for each docx paragraphvar docxProps = docxPara.ParagraphProperties;                         bool hasBulletPoint = false;                         int indentLevel = 0;                         if (docxProps.NumberingProperties != null)                         {// bullet point                             hasBulletPoint = true;

    }

                            if (docxProps.Elements<W.Indentation>().Count() > 0)                         {                             int indentAmount = 0;                             var indentOb = docxProps.Elements<W.Indentation>().FirstOrDefault();                             if (indentOb != null)                             {                                 Int32.TryParse(indentOb.Left, out indentAmount);                             }                             indentLevel = indentAmount / 360; // this has to change if they change the bullet indent amount in the UI                         }                         D.BulletFont bulletFont = null;                         D.CharacterBullet bulletChar = null;                         if (hasBulletPoint == true)                         {                             bulletFont = new D.BulletFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 };                             //bulletChar =  new D.CharacterBullet() { Char = bulletChars[indentLevel % 3]};                             bulletChar = new D.CharacterBullet() { Char = bulletChars[0] }; // ppt only does a single kind of bullet                         }                         // the default indent and margin are too big for the AD powerpoint. they like tight spacingint leftMargin = baseBulletMargin;                         var paragraphProps = new D.ParagraphProperties() { Alignment = this.textAlignment, LeftMargin = leftMargin, Indent = hasBulletPoint ? bulletIndent : 0, Level = indentLevel };                         paragraphProps.Append(new D.LineSpacing(new D.SpacingPercent() { Val = lineSpacing }));                         paragraphProps.Append(new D.SpaceBefore(new D.SpacingPoints() { Val = spaceBefore }));                         paragraphProps.Append(new D.SpaceAfter(new D.SpacingPoints() { Val = spaceAfter }));                         if (bulletFont != null)                         {                             paragraphProps.Append(bulletFont);                             paragraphProps.Append(bulletChar);                         }                         // add the paragraph propertiesvar pptParagraph = new D.Paragraph(paragraphProps);                         /////////////////////////////////////////////////////////////// Build pptx Runs. Paragraphs are made of runs.// A separate run is needed for each style change.// Unneeded run breaks sometimes come from the editor but are copied into the PPT//var docxRuns = docxPara.Elements<W.Run>();                         foreach (var docxRun in docxRuns)                         { // we dont care about font since it is fixed to Georgia 9 (specified in the master slide)// both docxRun.RunProperties.Italic and docxRun.RunProperties.Bold properties dont seem to work so we have to check the child elementsbool isItalic = false;                             // DON'T REMOVE// DISABLE ITALIC: // Comment the below code to enable italic in codeif (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Italic>().Count() > 0) // these may or may not be present with a true/false value                             {                                 isItalic = docxRun.RunProperties.Elements<W.Italic>().First().Val.Value;                             }                             bool isBold = false;                             if (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Bold>().Count() > 0)                             {                                 isBold = docxRun.RunProperties.Elements<W.Bold>().First().Val.Value;                             }                             // only supporting solid underline.// if we need more, have to map from docx to pptx underline -- the Enum int values are not the same (of course).                             D.TextUnderlineValues pptxUnderline = D.TextUnderlineValues.None;                             // dont care about the underline type -- only supporting solid at the moment// DON'T REMOVE// DISABLE UNDERLINE: // Comment the below code to enable underline in codebool isUnderline = false;                             if (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Underline>().Count() > 0)                             {                                 isUnderline = docxRun.RunProperties.Elements<W.Underline>().First().Val.Value != W.UnderlineValues.None;                                 // Only set the Undeline Property in PPTX if it is set in the XAMLif (isUnderline)                                     pptxUnderline = D.TextUnderlineValues.Single;                             }                             int fontSize = defaultFontSize;                             if (this.fontSize != 0)                             {                                 fontSize = this.fontSize;                             }                             D.RunProperties pptxRunProps = new D.RunProperties() { FontSize = fontSize, Underline = pptxUnderline, Bold = isBold, Italic = isItalic };                             pptxRunProps.SetAttribute(newOpenXmlAttribute("""smtClean""""0"));                             D.SolidFill fill = new D.SolidFill(new D.RgbColorModelHex() { Val = this.textColor.ToRGBHex() });                             pptxRunProps.InsertAt(fill, 0);                             string textVal = "";                             var txt = docxRun.Elements<W.Text>().FirstOrDefault();                             if (txt == null)                             {                                 //textVal = "ERROR";                                 textVal = "";                             }                             else                             {                                 textVal = txt.Text;                             }                             D.Text pptxText = new D.Text(textVal);                             // add each run                             pptParagraph.Append(new D.Run(pptxRunProps, pptxText));                         }                         // add each paragraph to our list                         pptParagraphs.Add(pptParagraph);

    Waiting for your reply.

    Thanks,

    neha

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    


    • Edited by neha ezirs Monday, February 26, 2018 6:50 AM
    Monday, February 26, 2018 6:48 AM

All replies

  • By default it is showing font 18 for those spaces and empty lines.
    Monday, February 26, 2018 1:07 PM
  • Hello neha eirs,

    >>RadDocument document = newXamlFormatProvider().Import(xamlData);

    What's the xamlData? It seems that the ppt is created based on some specific XAML file?

    I would suggest you share your project so we could try to reproduce your issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 27, 2018 7:59 AM
  • Hi thanks for responding.

    i resolved this issue by edding paragraph end properties of open xml.

    Wednesday, February 28, 2018 7:46 AM
  • Hi neha,

    I am glad you have resolved your issue, I would suggest you mark your reply as answer to close this thread.

    In addition, have you resolved thread below?

    #Issue in open of PPT using code, after the generation by open xml /c#

    https://social.msdn.microsoft.com/Forums/office/en-US/c6d18cab-6d9a-4854-a61f-3a9a4b6b7b13/issue-in-open-of-ppt-using-code-after-the-generation-by-open-xml-c?forum=oxmlsdk

    If you have, I would suggest you share us your solution, and mark it as answer.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 28, 2018 8:52 AM