2

I am trying to read powerpoint slides. But when my program is encountered with text like " Vo = Σ CF/(1+t) " , the shape.TextFrame.TextRange.Paragraphs(paraindex,1).Text property can not read it properly(Specially Σ symbol and subscript 0(zero)with V). So the end result is garbled text.

[EDIT]: I discovered that the creator of the ppt has used Insert->Equation of powerpoint for writing "Σ CF" . So it becomes a special text.

[Note]: Writing above text/equation without using Insert->Equation tool, [pressing Alt+228, and subscript option] my code yields expected results.

Plz suggest if there is a way to handle text/equation written using Insert->Equation tool.

Thank You.

rohitvk
  • 277
  • 3
  • 13
  • The end result is garbled text when you do what with it? – Steve Rindsberg Apr 16 '13 at 13:06
  • when i use the above mentioned property to read text/equation into a string. – rohitvk Apr 17 '13 at 06:19
  • You can't see text in a string until you display it somehow. How are you LOOKING at the text? Where do you see it garbled? For example, if the equation editor uses a special symbol font but you're displaying the text in Courier, there will be character substitutions. Likewise, if it's displaying unicode text and you're displaying the string in some way that only supports single-byte characters, you'll again get gibberish. – Steve Rindsberg Apr 17 '13 at 15:19
  • Now, I get you steve. The program converts ppt to swf, so the garbled text appears in the result ie swf file. The font being used is Calibri math, but it is taken care of by my code. I am yet to figure out the other details. in short the aim is to find a way to render such equation in swf. – rohitvk Apr 18 '13 at 06:25
  • @rohitvk i am having the same problem http://stackoverflow.com/questions/28343914/how-to-read-math-equations-from-powerpoint-and-write-it-to-word-document-in-c-sh. Did you got any solutions? – ashishkumar148 Feb 05 '15 at 13:42
  • nope i didn't. Using LaTeX was the answer i got from everywhere. – rohitvk Feb 10 '15 at 14:48

2 Answers2

0

If you're getting gibberish in your SWF, it might be because Flash doesn't support Unicode or because the wrong characters are being passed into the SWF. This will give you an idea of what's in a selected equation, for example. Note that if you were to use Asc() instead of AscW(), you'd get incorrect results.

Sub WhatsInTheEquation()
    Dim oSh As Shape
    Dim oRng As TextRange2
    Dim sTemp As String
    Dim x As Long

    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    For Each oRng In oSh.TextFrame2.TextRange.Runs
        Debug.Print oRng.Text
        Debug.Print oRng.Font.Name
        Debug.Print "Size: " & oRng.Font.Size
        sTemp = ""
        For x = 1 To Len(oRng.Text)
            sTemp = sTemp & " " & AscW(Mid$(oRng.Text, x, 1))
        Next
        Debug.Print sTemp
    Next

End Sub
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • The problem with the equation is that you cannot get its value in textual form (i.e using oRng.Text). AscW throws exception that "Input string not in correct format". Font, size properties can be known from powerpoint itself. – rohitvk Apr 19 '13 at 11:53
  • That may depend on how the equation was inserted. The code I quoted works in PPT 2010 with an equation I inserted using Insert | Equation. In this case I picked one of the more complex looking pre-formatted ones. How were the equations you're dealing with inserted? – Steve Rindsberg Apr 19 '13 at 14:34
  • This is I am getting in log : _WARN SWFWriter - Given font[Cambria Math Italic] is not available on this system. Decided to switch to the pre-decided default font [arial]._ Also was trying with TextRange2 MathZone(start,length) [to detect if shape contains Math Equation] ; but no success. – rohitvk Apr 23 '13 at 08:58
  • "Given font[Cambria Math Italic] is not available on this system." That would seem to answer the question, wouldn't it? – Steve Rindsberg Apr 23 '13 at 14:46
  • Ok. That may be the case. Now I want to detect the text that is actually Equation to differentiate and export only that part(equation text) as image. How should i detect where it starts and ends as an eqution ? – rohitvk Apr 24 '13 at 10:41
0

This isn't an answer, but comments are too short and don't allow for code formatting.
Anyhow, this isn't quite right but might get you pointed in the right direction.

Dim oSh As Shape
Dim x As Long
Dim y As Long
Dim lMathStart As Long
Dim lMathEnd As Long
Dim oTempShape As Shape

Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh.TextFrame2.TextRange

    For x = 1 To .MathZones.Count
        With .MathZones(x)
            lMathEnd = .Characters.Count
            lMathStart = InStr(oSh.TextFrame.TextRange.Text, .Characters)

            Set oTempShape = oSh.Duplicate(1)
            With oTempShape.TextFrame.TextRange
                '.Characters(lMathStart, lMathEnd).Delete
                .Characters(1, lMathStart).Delete
                .Characters(lMathEnd).Delete
            End With

        End With
    Next
End With

The logic would actually be more like: For each mathzone, duplicate the original shape, then for each mathzone in the duplicated shape, delete all the characters prior to and after the mathzone, leaving you with just the equation to export as a shape.

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • I think the above code can work. But the issue I am facing is MathZones prpperty is not accessible to me. I am only able to access shape.TextFrame2.Textrange.get_MathZones(Start, length) method which is confusing. I have Office 2010 Standard SP1 installed on my system. What do you think can be a problem ? – rohitvk Apr 26 '13 at 07:15
  • I don't think the specific edition of Office 2010 would matter; mine's Office 2010 Pro/32-bit. So you're not able to see .MathZones.Count, for example? It might be worth poking at it a bit in VBA from within PowerPoint to see if you can solve the problem there, then work backward to port it to C#. Even if C# to VBA may seem like the real step backward ;-) – Steve Rindsberg Apr 26 '13 at 14:51
  • Thanks Steve for assistance provided so far. VBA solution seems infeasible for me. I'll update this section as I get a concrete solution. – rohitvk May 03 '13 at 06:12
  • I didn't suggest a VBA solution; just using VBA as a tool to figure out how you can solve the problem in C#. – Steve Rindsberg May 03 '13 at 14:37
  • Okay. btw I don't have much know-how about VBA, so if you could help me in that direction, it'd be great. – rohitvk May 06 '13 at 13:24