As the title says: I would like to be able to specify id (as an HTML attribute) for (some) IShapes when they are converted to HTML. Is it possible? Like in:
<rect id=“my_id” … />
@RadekK,
Thank you for posting the question.
Could you please indicate the Aspose.Slides library you are using?
The version is 24.1.0 (Cpp).
@RadekK,
Thank you for the additional information. I am working on the question and will get back to you soon.
Thank you, I will greatly appreciate it.
@RadekK,
Thank you for your patience. Please try using the IHtmlFormattingController
to wrap the shapes and add your attributes as follows:
auto presentation = MakeObject<Presentation>(u"sample.pptx");
auto htmlFormatter = HtmlFormatter::CreateCustomFormatter(MakeObject<CustomFormattingController>());
auto htmlOptions = System::MakeObject<HtmlOptions>();
htmlOptions->set_HtmlFormatter(htmlFormatter);
presentation->Save(u"output.html", SaveFormat::Html, htmlOptions);
presentation->Dispose();
class CustomFormattingController : public IHtmlFormattingController
{
public:
void WriteDocumentStart(SharedPtr<IHtmlGenerator> generator, SharedPtr<IPresentation> presentation) override {}
void WriteDocumentEnd(SharedPtr<IHtmlGenerator> generator, SharedPtr<IPresentation> presentation) override {}
void WriteSlideStart(SharedPtr<IHtmlGenerator> generator, SharedPtr<ISlide> slide) override {}
void WriteSlideEnd(SharedPtr<IHtmlGenerator> generator, SharedPtr<ISlide> slide) override {}
void WriteShapeStart(SharedPtr<IHtmlGenerator> generator, SharedPtr<IShape> shape) override
{
String header = String::Format(ShapeHeader, ShapeId++);
generator->AddHtml(header);
}
void WriteShapeEnd(SharedPtr<IHtmlGenerator> generator, SharedPtr<IShape> shape) override
{
generator->AddHtml(ShapeFooter);
}
private:
static const String ShapeHeader;
static const String ShapeFooter;
static int ShapeId;
};
const String CustomFormattingController::ShapeHeader = u"<div id=\"{0}\">";
const String CustomFormattingController::ShapeFooter = u"</div>";
int CustomFormattingController::ShapeId = 1;
More examples:
Excellent! Thank you very much for your help. This is what I was looking for.