Docx file giving error when trying to insert footer

@alexey.noskov
One of the .docx file when trying to insert footer using Aspose words for Java API giving error like “Unsupported file format: Unknown”
This has happened suddenly,previously it used to work

Using this aspose-words-23.12-jdk17.jar jar

This is the code snippet used

com.aspose.words.Document doc = new Document(fileDir + File.separator + fname);
com.aspose.words.DocumentBuilder builder = new com.aspose.words.DocumentBuilder(doc);
			
//to handle for all sections
infolog.info("Code before section" + fname);
for (Section s : doc.getSections())
{
	s.getPageSetup().setDifferentFirstPageHeaderFooter(false);
	s.getPageSetup().setOddAndEvenPagesHeaderFooter(false);
	// Move to the section.
	builder.moveToSection(doc.getSections().indexOf(s));
	// Move to footer and put some text
	builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_PRIMARY);
	//   builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_EVEN);
	//   builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_FIRST);
	builder.getFont().setName("Arial");
	builder.getFont().setBold(false);
	builder.getFont().setSize(10);
	builder.write(footerText);
	//builder.write("Date ");
	//commenting below lines on 05/16/2024 and trying another approach using LocalDateTime
	//	builder.insertField(" DATE", "");
	//trying to print time also 05/16/2024
	//	builder.write(" ");
	//	builder.insertField(" TIME", "");
	infolog.info("Code before time" + fname);

	LocalDateTime today = LocalDateTime.now();
	//to include seconds also on 10/11/2024
//	builder.write(" " + today.getMonthValue() + "/" + today.getDayOfMonth() + "/" + today.getYear() + " " + today.getHour() + ":" + today.getMinute() + ":" + today.getSecond()); 
//	builder.write(footerText1);
	builder.write(" " + today.getMonthValue() + "/" + today.getDayOfMonth() + "/" + today.getYear() + " " + today.getHour() + ":" + today.getMinute() + ":" + today.getSecond() + footerText1); 

}
//	doc.save(fileDir+File.separator+fname);
//modified as per Aspose team suggestion
infolog.info("Code before bytestream" + fname);

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (fname.endsWith(".docx") || fname.endsWith(".DOCX")) {
	doc.save(outputStream, com.aspose.words.SaveFormat.DOCX);
} else if (fname.endsWith(".dotx") || fname.endsWith(".DOTX")){
	doc.save(outputStream, com.aspose.words.SaveFormat.DOTX);
} else if (fname.endsWith(".dot") || fname.endsWith(".DOT")){
	doc.save(outputStream, com.aspose.words.SaveFormat.DOT);
} else if (fname.endsWith(".doc") || fname.endsWith(".DOC")){
	doc.save(outputStream, com.aspose.words.SaveFormat.DOC);					   
}
///modified on 07/23/2024 to rename file in util itself

int dotlastpos = fname.lastIndexOf('.');
String ProdSuffixedFileName = fname.substring(0, dotlastpos) + "-" + fileSuffix + fname.substring(dotlastpos);

FileOutputStream fos1 = new FileOutputStream(fileDir + File.separator + ProdSuffixedFileName);

fos1.write(outputStream.toByteArray());
fos1.close();
outputStream.close();

infolog.info("Footer inserted successfully for document " + fname);
footerinserted = true;
}

} catch (Exception fex)	{
fex.printStackTrace();
errlog.error("Exception occurred during inserting footer for file " + fname + " " + fex.getMessage());

}

with other docx files when tried it works.

Attaching the docx file giving the issue

PR000523_Rev125.docx (1.8 MB)

Thanks
Sabarish

@sabkan I cannot reproduce the problem on my side using the latest 24.10 version of Aspose.Words. Please try using the latest version on your side and let us know if the problem still persists on your side.

@alexey.noskov
Thanks.
When tried the .docx file from another location, the issue is not happening

Earlier when tried the .docx file from earlier location with the latest jar 24.10 also was getting the same issue.

So looks like the file in the earlier location had some issue.
Sabarish

@sabkan It is perfect that you managed to identify the problem.