Issues from the Previous Version

In the previous article (http://ayumax.hatenablog.com/entry/2018/05/06/231645), there were the following issues:

  • Cannot freely change the position of text
  • No image insertion feature
  • All text becomes bullet points

So, this time I addressed these issues.

Text Position Setting

Created a new PPTXTextArea class, allowing Position(x,y) and Size(width, height) to be set. In the PowerPoint world, settings seem to be in cm, so I made it possible to input values in cm (internal conversion is performed).

Image Insertion

Again, created a new PPTXImage class to handle this.
Similar to PPTXTextArea, position can also be specified.
However, there’s an issue: scaling while maintaining the original image’s aspect ratio is not possible… To do this, you need to manually input Size values that maintain the aspect ratio, which is a bit inconvenient.

Text Bullet Point Setting

Created a new PPTXBullet. An enum allows setting the bullet point style for text.

Result

Input Source

        using (PPTXDocument document = new PPTXDocument(PPTXFilePath, settings))
        {
            document.Slides = new List()
            {
                new PPTXSlide()
                {
                    SlideLayout = settings.SlideLayouts[EPPTXSlideLayoutType.TitleAndContents],
                    Title = new PPTXTextArea("Content Page 1"),
                    TextAreas = new List()
                    {
                        new PPTXTextArea("This is the body text.\n\\nAlso allows line breaks")
                    }
                },
                new PPTXSlide()
                {
                    SlideLayout = settings.SlideLayouts[EPPTXSlideLayoutType.TitleOnly],
                    Title = new PPTXTextArea("Content Page 2"),
                    TextAreas = new List()
                    {
                        new PPTXTextArea("Text 1 for the second PowerPoint slide", 1, 5, 20, 2),
                        new PPTXTextArea(1, 7, 20, 7)
                        {
                            Texts = new List()
                            {
                                new PPTXText("Second slide, line 1", PPTXBullet.Circle),
                                new PPTXText("Second slide, line 2", PPTXBullet.Circle),
                                new PPTXText("Second slide, line 3", PPTXBullet.Rectangle),
                                new PPTXText("Second slide, line 4 - Bullet point removed")
                            }
                        }
                    },
                    Images = new List()
                    {
                        new PPTXImage(@"C:\temp\sample.jpg", 1, 15, 5, 3),
                        new PPTXImage(@"C:\temp\sample.jpg", 7, 15, 5, 3)
                    }
                }
            };
        }   

Output

Next Steps

This concludes the main part of the pptx creation feature for now.
I think having a font setting feature would be good too, but if I get too caught up in details, I won’t make progress, so I’ll stick to the bare minimum.
I plan to consider it again if I feel it’s necessary later.

Next, I’ll move on to Markdown parsing.