Depending on the presentation I opened the text on the new slide is sometimes centerd and sometimes left aligned. Additionally the text “Click to edit Master title style” occurs sometimes. So far I failed to modify the master or the layout to avoid these effects. Can you please provide a suggestion so that the text on the new slide is just left aligned?
The issue you’re experiencing with text alignment and the appearance of “Click to edit Master title style” is likely due to the default settings of the slide layout and the text frame properties. When you insert text using insertFromHtml, it may inherit formatting from the master slide or the layout slide, which can lead to inconsistent text alignment.
Solution
To ensure that the text on your new slide is left-aligned and does not show the default title style, you can explicitly set the text frame properties after inserting the text. Here’s how you can do that:
After adding the new slide, access the text frame of the shape where you want to insert the text.
Set the text alignment to left.
Clear any default title text that might be present.
Code
Here’s a code snippet that demonstrates how to achieve this:
// Add a new slide with a blank layout
IMasterLayoutSlideCollection layoutSlides = emptyMaster.getLayoutSlides();
ISlide emptySlide = ppt.getSlides().addEmptySlide(blankLayout);
// Insert text from HTML
ISlide[] notesSlides = slides.insertFromHtml(slides.size(), "Some text .... ");
// Access the newly added slide's shape
IAutoShape shape = (IAutoShape) emptySlide.getShapes().get_Item(0);
ITextFrame textFrame = shape.getTextFrame();
// Set text alignment to left
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
// Clear any default title text
textFrame.setText("Some text .... "); // Set your desired text here
// Optionally, remove the empty slide if not needed
ppt.getSlides().remove(emptySlide);
Next Steps
Test the above code to see if it resolves the alignment issue.
If you still encounter the “Click to edit Master title style” text, ensure that you are not using a layout that has a title placeholder.
Adjust any other text frame properties as needed to fit your design requirements.
Please implement these changes and let me know if it resolves your issue!
I tested your scenario using the latest version of Aspose.Slides for Java 25.6. Using a basic PowerPoint presentation file, everything functioned correctly and as expected. I set the text alignment to left for the shapes on the new slides. Here is my sample code.
e.g., Sample code:
// Load the existing presentation
Presentation pres = new Presentation("d:\\files\\Brush Skript MT.pptx");
// Get a blank layout
IMasterLayoutSlideCollection layoutSlides = pres.getMasters().get_Item(0).getLayoutSlides();
ILayoutSlide blankLayout = layoutSlides.getByType(SlideLayoutType.Blank);
if (blankLayout == null) {
blankLayout = layoutSlides.add(SlideLayoutType.Blank, null);
}
// Add an empty slide based on the truly blank layout
ISlide slide = pres.getSlides().addEmptySlide(blankLayout);
// Add a text frame manually instead of insertFromHtml
float x = 50;
float y = 50;
float width = 600;
float height = 100;
IAutoShape textShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, x, y, width, height);
textShape.getTextFrame().setText("Your free text goes here.");
// Set font and left alignment
IPortion portion = textShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().setFontHeight(14);
textShape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
textShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, x , y+200, width, height);
textShape.getTextFrame().setText("This is new text.");
// Set font and left alignment
portion = textShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().setFontHeight(14);
textShape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);
textShape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
// Save result
pres.save("d:\\files\\output1.pptx", com.aspose.slides.SaveFormat.Pptx);
Please find attached the zipped archive having input and output PowerPoint presentation files for your reference. output1.zip (30.6 KB)
In case you still find any issue, kindly do provide sample (runnable) code and PowerPoint presentation files. We will check your issue soon.
Alright, if the suggested approach using the insertFromHtml API meets your requirements, please feel free to proceed with it. Should you have any additional questions or feedback, please do not hesitate to reach out to us.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.