We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose words footer identifier

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Dear Team,

We are currently Evaluating Aspose.words dll to meet our project needs before purchasing the product . We are using Apsose.words dll to convert the word documents to HTML web page, However we need to add an identifier for the footer content in the Rendered HTML to identify it as the footer element of the web page .

For example : If there is an image added in the source word document footer content , we need to identify that is in the footer .

So can an identifier like class or id attribute could be added to the rendered html like below.

Ex: <img class=”Footerelement” src=”~/footerimage.gig” />

Kindly help us to achieve the Functionality .

Is there anyway this can be done pls help us ??

Hi,

Thanks for your inquiry and sorry for the delayed response. The HtmlSaveOptions.ExportHeadersFootersMode property can be used to specify how headers and footers are output to HTML, MHTML or EPUB. Please try run the following code snippet:

Document doc = new Document(MyDir + “HeaderFooter.doc”);
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html);
saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstSectionHeaderLastSectionFooter;
doc.Save(MyDir + "HeaderFooter Out.html", saveOptions);

Please note that it is hard to meaningfully output headers and footers to HTML because HTML is not paginated. When this property is PerSection, Aspose.Words exports only primary headers and footers at the beginning and the end of each section. When it is FirstSectionHeaderLastSectionFooter only first primary header and the last primary footer ( including linked to previous ) are exported. You can disable export of headers and footers altogether by setting this property to None.

Secondly, you can output an " alt " attribute to “img” tag by using Shape.AlternativeText property. Please let me know if this is acceptable for you?

Best regards,

Awais,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We would like to identify the Header, footer element in the Rendered HTML just to separate or Identify from the Main word Document Content .

Is it possible to set an Identifier through code for the Header and Footer during the time of conversion using HTMLSaveoptions class .

Please Let us know if this is Achievable

Awais,

Is it possible achieve the functionality as this is an immediate requirement from our client .

Hi,


Thanks for your inquiry. There are the following two ways you can set identifier for a Shape i.e. contained inside header or footer:

1) By obtaining a live collection of Shape nodes in document:

Document doc = new
Document(@“C:\Temp\in.doc”);

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

foreach (Shape shape in shapes)

{

HeaderFooter hf = (HeaderFooter)shape.GetAncestor(NodeType.HeaderFooter);

if (hf != null)

shape.AlternativeText = hf.HeaderFooterType.ToString() + "Element";

}

doc.Save(@"C:\Temp\out.html");


2) Using HtmlSaveOptions.ImageSavingCallback property:

Document doc = new Document(@"C:\Temp\in.doc");

HtmlSaveOptions saveOptions = new HtmlSaveOptions();

saveOptions.PrettyFormat = true;

saveOptions.ImageSavingCallback = new HandleImageSaving();

doc.Save(@"C:\Temp\outg.html", saveOptions);


public class HandleImageSaving : IImageSavingCallback

{

void IImageSavingCallback.ImageSaving(ImageSavingArgs e)

{

Shape shape = e.CurrentShape as Shape;

HeaderFooter hf = (HeaderFooter)shape.GetAncestor(NodeType.HeaderFooter);

if (hf != null)

shape.AlternativeText = hf.HeaderFooterType.ToString() + "Element";

}

}


I hope, this helps.

Best regards,

Awais,

The source word document header and footer content needs to be encapsulated using a single element set with an identifier .

Ex: Source word document has an image and text in the footer of the document and image in the Header .

In the renedered HTML :

an Element may be a

or

with the identifier Class="header" or "footer" to be set .

like

Footer text

Please let us know if this achievable .

Hi,

Thanks for your inquiry. The output Html depends on the layout of elements in input Word document. For example, Paragraphs in Word document are exported to Html as

Paragraphs with built-in heading styles are exported as elements ( please see the documentation Save in the HTML (.HTML, .XHTML, .MHTML) Format ). You need to arrange the elements in your Word document to be able to produce the desired Html output. For example, I have created a “sample.docx” Word document here for your reference. Please try run the following code snippet which produces the desired Html output:

Document doc = new Document(@“C:\Temp\sample.docx”);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
    HeaderFooter hf = (HeaderFooter)shape.GetAncestor(NodeType.HeaderFooter);
    if (hf != null)
        shape.AlternativeText = hf.HeaderFooterType.ToString() + "Element";
}
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html);
saveOptions.PrettyFormat = true;
saveOptions.CssStyleSheetType = CssStyleSheetType.Embedded;
saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstSectionHeaderLastSectionFooter;

doc.Save(@"C:\Temp\out.html", saveOptions);

Best regards,