Font style

Hello .. i am using your library syncfusio.presentations to edit my presentations but i wanna know how to modify the font for wach section in the slide for example as attached i wanna my side to have for section 1 different font than section 2... and so on how can i get the text in each section and apply the changes on it ..


Thanks in advance

Attachment: Trial_901965f7.7z

1 Reply 1 reply marked as answer

HC Hemalatha Chiranjeevulu Syncfusion Team January 25, 2021 12:13 PM UTC

Hi NadaB,

Thank you for contacting Syncfusion support.

Yes, you can iterate into the elements in PowerPoint slide using Essential Presentation library and set the formats for text. Please refer the below code example, to iterate shapes in the slide and change font for contents of each shape.

 
//Opens an existing Presentation from file system. 
IPresentation pptxDoc = Presentation.Open(@"Trial.pptx"); 
//Retrieves the first slide from Presentation 
ISlide slide = pptxDoc.Slides[0]; 
//Retrieves the shape to format the section1. 
IShape shape = slide.Shapes[5] as IShape; 
if(shape.TextBody.Paragraphs.Count!=0) 
{ 
//Retrieves the first paragraph of the shape.  
IParagraph paragraph = shape.TextBody.Paragraphs[0]; 
ChangeFont(paragraph,"Arial",25f); 
}    
//Retrieves the shape to format the section2. 
shape = slide.Shapes[1] as IShape; 
if (shape.TextBody.Paragraphs.Count != 0) 
{ 
//Retrieves the first paragraph of the shape.  
IParagraph paragraph = shape.TextBody.Paragraphs[0]; 
ChangeFont(paragraph, "Times New Roman", 36f); 
} 
//Saves the presentation to the file system. 
pptxDoc.Save("Result.pptx"); 
//Closes the Presentation. 
pptxDoc.Close(); 
private static void ChangeFont(IParagraph paragraph,string fontName, float fontSize) 
{ 
foreach (ITextPart textpart in paragraph.TextParts) 
{ 
//Sets font for texts  
textpart.Font.FontName = fontName; 
textpart.Font.FontSize = fontSize; 
} 
} 

Please refer the below links to know more about working with presentation:
https://help.syncfusion.com/file-formats/presentation/working-with-powerpoint-presentation
https://help.syncfusion.com/file-formats/presentation/working-with-slide
https://help.syncfusion.com/file-formats/presentation/working-with-paragraphs
https://help.syncfusion.com/file-formats/presentation/working-with-shapes

Please let us know if you have any other questions.

Regards,
Hemalatha C


Marked as answer
Loader.
Up arrow icon