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

Free Support Forum - aspose.com

Retain FileName Field in Header of Word Document after Converting DOCX to PDF using Java | FileInputStream FileOutputStream

Hi,
when having field FileName in header of the document it is not saved in resulting pdf. But same field does appear in body of the document.
See screenshot.PNG (9.8 KB)
Notice the page field working as expected in header.

Code snippet used to save doc as pdf:
try (
InputStream is = new FileInputStream(path);
OutputStream os = new FileOutputStream(path + “.pdf”);
) {

			com.aspose.words.Document doc = new com.aspose.words.Document(is);

			doc.save(os, com.aspose.words.SaveFormat.PDF);
		}

Sampl doc: field_in_header.zip (15.4 KB)

@konopka,

After an initial test with the licensed latest version of Aspose.Words for Java i.e. 20.2, we were unable to reproduce this issue on our end. We used the following simple code to produce a “awjava-20.2.pdf” on our end:

Java Code to Convert DOCX to PDF

Document doc = new Document("E:\\Temp\\field_in_header\\field_in_header.docx");
doc.save("E:\\Temp\\field_in_header\\awjava-20.2.pdf");

So, please upgrade to the latest version i.e. 20.2. Hope, this helps.

@awais.hafeez

  1. I am using aspose-words 20.2
  2. using path in Document constructor, I cannot reproduce either
  3. please use the sample code I have provided - using InputStream in Document constructor
  4. How is it possible that this field is not visible in document header when using InputStream, but in document body it is rendered correctly?

@konopka,

Thanks for the additional information. We tested the scenario further and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSJAVA-2330. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.