2015-03-12 6 views
0

я получаю все формы в слайдах РРТ файла теперь я хочу, чтобы получить текст из этих фигур, как я могу это сделатьКак получить текст из слайда в C# с помощью Aspose

здесь мой метод, где я получаю форму всех слайдов в файле п.п.

public void Main(string[] args) 
    { 
     // The path to the documents directory. 
     string dataDir = Path.GetFullPath(@"C:\Users\Vipin\Desktop\"); 
     //Load the desired the presentation 
     Presentation pres = new Presentation(dataDir + "Android.ppt"); 
     using (Presentation prestg = new Presentation(dataDir + "Android.ppt")) 
     { 


      //Accessing a slide using its slide index 
      int slideCount = prestg.Slides.Count(); 
      for (int i = 0; i <= slideCount - 1; i++) 
      { 
       ISlide slide = pres.Slides[i]; 
       foreach (IShape shap in slide.Shapes) 
       { 
        int slideCountNumber = i + 1; 

        float shapeHeight = shap.Frame.Height; 
        float shapeWidth = shap.Frame.Width; 
        Debug.Write("slide Number: " + slideCountNumber + " shape width = " + shapeWidth + " shapeHeight = " + shapeHeight); 

       } 
      } 

     } 
    } 

Теперь хо я могу получить текст из него

ответ

0

Aspose будет дать и усеченный текст, если у вас нет лицензии на него. так что это будет лучше для вас, если вы будете использовать Microsoft.Office.Interop.PowerPoint

использовать как ниже

public void ReadSlide(){ 

     string filePath= @"C:\Users\UserName\Slide.pptx"; 

     Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); 
     Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; 
     Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); 

     string presentation_textforParent = ""; 
     foreach (var item in presentation.Slides[1].Shapes) 
     { 
      var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; 
      if (shape.HasTextFrame == MsoTriState.msoTrue) 
      { 
       if (shape.TextFrame.HasText == MsoTriState.msoTrue) 
       { 
        var textRange = shape.TextFrame.TextRange; 
        var text = textRange.Text; 

        presentation_textforParent += text + " "; 
       } 
      } 
     } 

}

0

Вы можете захотеть, чтобы извлечь текст не из всех форм, но с фреймами вместо этого. Для этого используйте GetAllTextFrames статического метода предоставляемого PresentationScanner класса

using (Presentation prestg = new Presentation(dataDir + "Android.ppt")) 
{ 
    //Get an Array of ITextFrame objects from all slides in the PPTX 
    ITextFrame[] textFramesPPTX = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(pptxPresentation, true); 

    //Loop through the Array of TextFrames 
    for (int i = 0; i < textFramesPPTX.Length; i++) 

    //Loop through paragraphs in current ITextFrame 
    foreach (IParagraph para in textFramesPPTX[i].Paragraphs) 

     //Loop through portions in the current IParagraph 
     foreach (IPortion port in para.Portions) 
     { 
      //Display text in the current portion 
      Console.WriteLine(port.Text); 

      //Display font height of the text 
      Console.WriteLine(port.PortionFormat.FontHeight); 

      //Display font name of the text 
      if (port.PortionFormat.LatinFont != null) 
       Console.WriteLine(port.PortionFormat.LatinFont.FontName); 
     } 

См documentation

+0

это showslike «Нажмите ... Текст был урезано из-за оценки ограничение версии '@Max Brodin –

+0

@NeerajMehta Это означает, что Aspose libriary не является бесплатным, и вы должны его покупать перед использованием. –

+0

есть ли какой-либо другой метод или библиотека, которые могут это сделать бесплатно? –