Open XML Attributes in the Generated HTML


#1

Hello,

I’m using Apose.Slides to convert a powerpoint document to HTML (SVG format). Is it possible to add data attributes to the Open XML elements and have then appear in the HTML?

For example, setting the attribute data-id on run elements and having then appear in the html as data attributes on the tspan elements (or whichever element they happen to map to).

Thank you.


#2

@taha123,

Can you please share your requirements in form of sample. We will investigate on our end to help you out.


#3

Hi Adnan,

Here’s a full walk-through of what I’m hoping to do with some examples in the attachments.

1. Attach attributes to a:p elements in the xml of a powerpoint document using the following code (see attachment “output.xml” for the result):

// @param root: This is a Slide, SlideLayout or SlideMaster element.
private static void AttachIdToParagraphs(OpenXmlPartRootElement root)
{
        IEnumerable<A.Paragraph> paragraphs = root.Descendants<A.Paragraph>();

        foreach (A.Paragraph paragraph in paragraphs)
        {
                string ns = "http://www.w3.org/XML/1998/namespace";
                paragraph.SetAttribute(new OpenXmlAttribute("attr-name", ns, "attr-value"));

                // -- OR ---
                                                                 
                paragraph.SetAttribute(new OpenXmlAttribute("attr-name", "", "attr-value"));
        }
}

2. Generate a HTML document from the edited powerpoint using Aspose.Slides (see attachment “output.html” for the result):

using (Presentation pptx = new Presentation("file/path/to/edited/pptx"))
{
        HtmlOptions htmlOpt = new HtmlOptions
        {
                HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("", false),
                SvgResponsiveLayout = true
        };
        
        pptx.Save(htmlfile, SaveFormat.Html, htmlOpt);
}

As you can see the attribute “attr-name” was not reflected in the generated HTML. I’m hoping there’s a way to attach some attributes and have them reflect in the generated HTML. Please see attachment “desired-output.html” for an example of the desired output where the attribute has been added to the element.

attachments.zip (49.3 KB)

Thank you,
Taha


#4

@taha123,

I have observed your comments. You can create your own implementation of IHtmlController. Please visit this documentation link for more details.


#5

Thanks Adnan. Can this be done for word documents? I’m again looking for a way to add some sort of mapping between the document’s open xml paragraph elements and the generated html elements (SVG Format).

For example:

1. Add attributes to the open xml elements.

using (WordprocessingDocument document = WordprocessingDocument.Open("file/path/to/docx", true))
{
    Body body = document.MainDocumentPart.Document.Body;

    foreach (Paragraph paragraph in body.Descendants<Paragraph>())
    {
        paragraph.SetAttribute(new OpenXmlAttribute("attr-name", "namespace", "attr-value"));
    }

    ...
}

2. Generate the HTML file from the edited word document using Apose.Words.

using (Aspose.Words.Document document = new Aspose.Words.Document("file/path/to/edited/docx")
{
    SvgSaveOptions options = new SvgSaveOptions
    {
        PrettyFormat = true,
        UpdateFields = false,
        UseAntiAliasing = true,
        MemoryOptimization = true,
        ExportEmbeddedImages = true,
        OptimizeOutput = true,
        ShowPageBorder = false,
        FitToViewPort = false,
        UpdateSdtContent = false,
        UseHighQualityRendering = true,
        UpdateLastSavedTimeProperty = false,
        DmlRenderingMode = DmlRenderingMode.DrawingML,
        TextOutputMode = SvgTextOutputMode.UseSvgFonts
    };
    
     document.Save("Output.html", options);
}

3. Output.html.

...
<g transform="matrix(1,0,0,1,0,0)">
    <text attr-name="attr-value">
	    <tspan x="0" y="39.124000549" font-family="Georgia">Text in run</tspan>
    </text>
</g>
...

#6

@taha123,

We are checking this scenario related to Aspose.Words and will get back to you soon.


#7

Hi Awais,

Any update on this?


#8

@taha123,

We had logged your requirement in our issue tracking system. Your ticket number is WORDSNET-18743. We will further look into the details of this requirement and will keep you updated on the status of the linked issue.