Hi Team,
We observe an issue while adding images as logo in the word documents.
Can you please help us to insert the image logo in a word document without adding it into the header or footer because we have added but the image gets blur?
Below code is used:
// private static void insertWatermarkImageIntoWordDocument(Document doc, String watermarkImagePath, DocumentBuilder builder) throws Exception {
Shape watermark = new Shape(doc, ShapeType.IMAGE);
watermark.getImageData().setImage(watermarkImagePath);
watermark.setWidth(80);
watermark.setHeight(35);
// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setLeft(100);
watermark.setTop(100);
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
// // Insert the watermark into all headers of each document section.
for (Section sect : doc.getSections())
{
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
}
private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType)
throws Exception {
HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
if (header == null) {
// builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
// // There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.getDocument(), headerType);
sect.getHeadersFooters().add(header);
}
// Insert a clone of the watermark into the header.
header.appendChild(watermarkPara.deepClone(true));
}
Thanks in advance.