GemBox Support Forum

Replace placeholder text with HTML formatted text

Is it possible to replace text with html or add html to the Content property or the PresentationDocument?
Maybe something like the HtmlLoadOptions at the GemboxDocument library

1 Like

Unfortunately no.
I’m afraid that GemBox.Presentation currently doesn’t support HTML format.

Note, we have this feature in our feature request collection, and please feel free to vote for it in order to increase its priority:

However, at the moment I cannot say exactly when this will be implemented.

@mario.gembox, could you please suggest any workaround, as we need to implement HTML insertion to placeholders. My idea was to import HTML to Gembox.Document first and then try to convert the model to Gembox.Presentation. What would be limitations of such approach?

Unfortunately, I don’t have any straightforward workaround.

The idea you have is valid, but I’m afraid there is no built-in conversion between GemBox.Document’s and GemBox.Presentation’s content model. So you would have to write the whole mapping yourself which would be rather tedious.

Perhaps you can simplify that to just the use cases that you need.
For example, something like this:

using System;
using System.Linq;
using GemBox.Document;
using GBD = GemBox.Document;
using GemBox.Presentation;
using GBP = GemBox.Presentation;

// ...

var presentation = PresentationDocument.Load("Placeholders.pptx");
var slide = presentation.Slides[0];
var textBox = slide.Content.Drawings
    .First(item => item.Placeholder?.PlaceholderType == PlaceholderType.Text)

var document = DocumentModel.Load("Input.html");
foreach (var docPar in document.GetChildElements(true).OfType<Paragraph>())
    var slidePar = textBox.AddParagraph();

    slidePar.Format.SpacingBefore = TextSpacing.Exactly(docPar.ParagraphFormat.SpaceBefore);
    slidePar.Format.SpacingAfter = TextSpacing.Exactly(docPar.ParagraphFormat.SpaceAfter);
    slidePar.Format.Alignment = docPar.ParagraphFormat.Alignment switch
        GBD.HorizontalAlignment.Center => GBP.HorizontalAlignment.Center,
        GBD.HorizontalAlignment.Right => GBP.HorizontalAlignment.Right,
        GBD.HorizontalAlignment.Justify => GBP.HorizontalAlignment.Justify,
        _ => GBP.HorizontalAlignment.Left
    // TODO...

    foreach (var docRun in docPar.Inlines.OfType<Run>())
        var slideRun = slidePar.AddRun(docRun.Text);

        slideRun.Format.Font = docRun.CharacterFormat.FontName;
        slideRun.Format.Size = docRun.CharacterFormat.Size;
        // TODO...


I hope this helps.

1 Like

Thank you Mario, will try to go with mapping as a temporary solution. Hope HTML support will be implemented in GemBox.Presentation in foreseeable future.