Image Alignment in Header

Hi,
I am inserting two images in header. First image should be left aligned and the second right. What is the solution for this?

Hi

Thanks for your request. You can achieve this using different approaches. For example.

  1. You can insert images as floating shapes.
// Create document and DocuemntBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Move to header
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Insert first image (left aligned)
Shape img1 = builder.InsertImage(@"Common\test.jpg");
img1.WrapType = WrapType.None;
img1.RelativeHorizontalPosition = RelativeHorizontalPosition.Margin;
img1.HorizontalAlignment = HorizontalAlignment.Left;
// Insert the second image (right aligned)
Shape img2 = builder.InsertImage(@"Common\test.jpg");
img2.WrapType = WrapType.None;
img2.RelativeHorizontalPosition = RelativeHorizontalPosition.Margin;
img2.HorizontalAlignment = HorizontalAlignment.Right;
doc.Save(@"Test132\out.doc");
  1. You can insert table into the header with 2 cells and insert one image into the first cell and the second into the second one.
// Create document and DocuemntBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Calculate width of the page
PageSetup ps = builder.PageSetup;
double pageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin - ps.Gutter;
// Move to header
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Insert first cell
builder.InsertCell();
// Specify width of cell
builder.CellFormat.Width = pageWidth / 2;
// Specify paragraph alignment
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
// Insert first image (left aligned)
builder.InsertImage(@"Common\test.jpg");
// Do the same to insert the second image
builder.InsertCell();
// Specify width of cell
builder.CellFormat.Width = pageWidth / 2;
// Specify paragraph alignment
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
// Insert first image (right aligned)
builder.InsertImage(@"Common\test.jpg");
// End the table
builder.EndRow();
builder.EndTable();
doc.Save(@"Test132\out.doc");

Hope this could help you.
Best regards.

Hi,
In the second solution, I dont want to show the cell borders. Just two images have to be shown.
Using this code the cell borders are also showing. How I will hide that?

Hi
Thanks for your inquiry. Table borders are disabled by default. You will not see these borders in print preview or when print document.
By default, MS Word shows disabled borders as single gray borders. You can disable this option in MS Word, just select “Hide Gridlines” from “Table” menu.
Best regards.