Inserting image in the .doc header / footer

Hi

While converting the html file to .doc, How we can insert a image in the header / footer area.

Whether we can insert the html content contains img tag directly into header / footer using DocumentBuilder.

With Regards

Chandrasekar P

Hi
Thanks fro your inquiry. You I think that you can try using InsertHtml method to achieve this. For example see the following code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml("");
doc.Save(@"372_103474_chandrasekar\out.doc");

I hope that this will help you.
Please let me know if you would like to know something else.
Best regards.

Hi

Thanks for your reply.

Im using the below code.

DocumentBuilder builder = new DocumentBuilder(doc);

builder.getPageSetup().setPaperSize(PaperSize.LETTER);

builder.getPageSetup().setOrientation(Orientation.PORTRAIT);

builder.moveToDocumentStart();

builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);

// Inserting a cell and formatting.

builder.insertCell();

builder.getCellFormat().setWidth(2 * 72);

builder.getParagraphFormat().clearFormatting();

builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);

Style thlStyle = doc.getStyles().add(StyleType.PARAGRAPH, "theadleft");

thlStyle.setBaseStyle("Normal");

thlStyle.setNextParagraphStyle("theadleft");

thlStyle.getFont().setSize(font_size);

thlStyle.getFont().setBold(font_bold);

builder.getParagraphFormat().setStyle(thlStyle);

// Inserting a image through Shape and positioning.

Shape shape = builder.insertImage(imgPath);

shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.COLUMN);

if (alignStr.equalsIgnoreCase("left"))

{

    shape.setHorizontalAlignment(HorizontalAlignment.LEFT);

}

else if (alignStr.equalsIgnoreCase("middle"))

{

    shape.setHorizontalAlignment(HorizontalAlignment.CENTER);

}

else if (alignStr.equalsIgnoreCase("right"))

{

    shape.setHorizontalAlignment(HorizontalAlignment.RIGHT);

}

shape.setRelativeVerticalPosition(RelativeVerticalPosition.PARAGRAPH);

shape.setVerticalAlignment(VerticalAlignment.TOP);

shape.setWrapType(WrapType.NONE);

shape.setBehindText(true);

builder.endRow();

builder.endTable();

builder.getParagraphFormat().clearFormatting();

Im getting the header and footer with border and the images are not aligned well.

Can you please tell me how to remove the table border, and How to align the images within the table and parallel to the header/footer text.

Im attaching the generated doc (new.doc) for your reference.

Please get back to me if you need further clarifications.

With Regards

Chandrasekar P

Hi
Thanks for additional information.

  1. Table borders are transparent by default. Use Table menu/hide gridlines in MSWord to hide transparent borders.
  2. I think that you should use inline image.

shape.setWrapType(WrapType.INLINE);
Please let me know if you would like to know something else.
Best regards.

Hi

Thanks, it works.

How we can hide the gridlines of the header/footer table through Aspose.

With Regards

Chandrasekar P

Hi
Unfortunately, you can’t hide gridlines using Aspose.Words because “Table / Hide Gridlines” is option of MSWord.
Best regards.