'How to apply margin in Presentation Document using OpenXml
I wrote code to create Presentation Document using open-xml SDK. I follow this sample code. MSDD Sample Code. Now i need to apply margin before starting my text. I've tried below code but didn't get expected result.
slidePart1.Slide = new Slide(
new CommonSlideData(
new ShapeTree(
new P.NonVisualGroupShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
new P.NonVisualGroupShapeDrawingProperties(),
new ApplicationNonVisualDrawingProperties()),
new GroupShapeProperties(new A.TransformGroup()),
new P.Shape(
new P.NonVisualShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
new P.NonVisualShapeDrawingProperties(new D.ShapeLocks() { NoGrouping = true }),
new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
new P.ShapeProperties(),
new P.TextBody(
new D.BodyProperties(),
new D.ListStyle(),
new A.Paragraph(new D.EndParagraphRunProperties() { Language = "en-US" }, new D.ParagraphProperties() { LeftMargin = 10 }),
//new A.Paragraph(new A.Run(new A.RunProperties() { Bold = true, Italic = true, Underline = D.TextUnderlineValues.Single }, new A.Text()
//{ Text = text })))))),
new A.Paragraph(textListWithStyle.ToArray()))))),
new ColorMapOverride(new D.MasterColorMapping()));
My generated PPT File looks like:
No left margin applied but in code i applied 10 left margin.
Solution 1:[1]
It seems not so easy to add an indented paragraph using Open XML SDK. With Aspose.Slides for .NET, this can be done like this:
// Create a new presentation.
using var presentation = new Presentation();
// Add a text box to the first slide.
var slide = presentation.Slides[0];
var rectangle = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 200, 150);
// Create a new paragraph.
var paragraph = new Paragraph();
paragraph.Text = "Some text.";
// Set left margin for the paragraph.
paragraph.ParagraphFormat.MarginLeft = 10;
// Add the paragraph to the text box.
rectangle.TextFrame.Paragraphs.Add(paragraph);
// Save the presentation to PPTX format.
presentation.Save("example.pptx", SaveFormat.Pptx);
This is a paid product, but you can get a temporary license to evaluate all features of this library. I work as a Support Developer at Aspose.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrey Potapov |