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

Free Support Forum - aspose.com

Inserting Image Into Header

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

I’m trying to insert an image into the header of a word document but it doesn’t seem to work. My code is below (it’s mostly from Aspose documentation) and everything executes fine and the word doc is produced but without an image. The header text is produced though.

private Document InsertHeaderLogo(Document doc)


DocumentBuilder builder = new DocumentBuilder(doc);

Section currentSection = builder.CurrentSection;

PageSetup pageSetup = currentSection.PageSetup;

pageSetup.DifferentFirstPageHeaderFooter = true;

// --- Create header for the first page. ---

pageSetup.HeaderDistance = 20;


builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// Set font properties for header text.

builder.Font.Name = "Arial";

builder.Font.Bold = true;

builder.Font.Size = 14;

// Specify header title for the first page.

builder.Write("Synergy Connect - Child Care Invoice.");

// --- Create header for pages other than first. ---

pageSetup.HeaderDistance = 20;


// Insert absolutely positioned image into the top/left corner of the header.

// Distance from the top/left edges of the page is set to 10 points.

if (File.Exists(mHeaderLogoPath))


builder.InsertImage(mHeaderLogoPath, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through);


return doc;

} //InsertHeaderLogo

Any ideas?




Thanks for your inquiry. Your code works fine. But note that you insert image only into the primary header and your document also contains FirstPage header. So if your document has only one page you will never see primary header with image.

You should just insert image into the first page header also.

Best regards.

Ahh your right. I've got it working now. Many thanks for the prompt response.