I am going to add a image to the header using the path as a string. ("https://localhost:44985/content/api/Contents/commentary-banner"
)
private static void SetupHeader(HtmlDocument htmlDoc, IDictionary<string, string> options)
{
if (options.TryGetValue(ContentsConstants.CONVERT_ADD_BANNER, out string addBannerAsString))
{
//addBannerAsString="https://localhost:44358/contentservice/api/Contents/commentary-banner-trowe-logo"
//var banner = addBannerAsString;
}
}
Could you please help me with this method implementation??
@nethmi You can use DocumentBuilder
to create header/footers. Please see our documentation for more information.
In your case, you can use DocumentBuilder.InsertImage
method to insert image from url. For example see the following simple code that inserts image from url into the document’s header:
// Create an empty document. If you need to put an image into an exsisting document,
// open your document by passing it's path or stream into the document's constructor.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Move DocumentBuilder's cursor into the document header.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Insert an image.
builder.InsertImage(@"https://cms.admin.containerize.com/templates/aspose/App_Themes/V3/images/aspose-logo.png");
// Save the document.
doc.Save(@"C:\Temp\out.docx");
Also, instead of passing instance of HtmlDocument
into SetupHeader
method, you should pass Aspose.Words.Document
where header should be added.
1 Like
Hii team,
It’s working.Thank you very much
1 Like