Header and footer font is increasing when converting from Word to PDF

While converting Word document to PDF using Aspose, the header and footer font is increasing causing the data to move to next line.

@SamanthJain

When converting a Word document to PDF using Aspose.Words, if you notice that the font size of headers and footers is increasing and causing text to wrap to the next line, there are a few things you can check and adjust.

  1. Font Size Settings: Ensure that the font size for the headers and footers is explicitly set in your document. You can do this using the DocumentBuilder class to specify the font size when adding text to headers and footers. For example:

    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
    builder.getFont().setSize(10.0); // Set the desired font size
    builder.write("Your Header Text");
    
  2. Page Setup: Check the page setup properties, particularly the header and footer distances. If these distances are too large, they can push the text down, causing it to wrap. You can adjust these settings as follows:

    PageSetup pageSetup = currentSection.getPageSetup();
    pageSetup.setHeaderDistance(20.0); // Adjust this value as needed
    pageSetup.setFooterDistance(20.0); // Adjust this value as needed
    
  3. Document Conversion Options: When converting the document, you can use the PdfSaveOptions class to specify additional settings that might affect the output. For instance, you can set the compliance level or optimize the output, which may help in maintaining the layout:

    PdfSaveOptions options = new PdfSaveOptions();
    options.setCompliance(PdfCompliance.PDF_A_1_B); // Example compliance setting
    doc.save("output.pdf", options);
    
  4. Testing with Different Formats: If the issue persists, try saving the document in different formats (like DOCX) and then converting it to PDF to see if the problem is specific to the original format.

By carefully adjusting these settings, you should be able to control the font size and layout of headers and footers during the conversion process. If you continue to experience issues, consider reviewing the Aspose documentation for more detailed guidance on handling headers and footers.

For further details, you can refer to the following resources:

Thanks I will look into these options. Meanwhile, I want to give additional information on the issue.

The docx to pdf conversion is perfectly working on server 1 for eg. where header and footer is coming properly in pdf. I have copied the same docx file and the java code to server 2 and try to convert, I observer the header and footer size is increasing on pdf on server 2.

Since the docx file and java code are same, I expect the behavior to be same. Any input on this ?

@SamanthJain The problem with document layout might occur because the fonts used the documents are not available in the environment where documents are converted to PDF. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

If after providing the required fonts the problem still persists, please attach your input and output documents here for our reference.

Thanks Alexey. I see that the word has Arial Narrow but getting converted to Arial on PDF. This is going out of alignment.

On the server, I see Arial Narrow available on Fonts folder on both the servers. Not sure why server 2 is behaving differently. Will add the warning callback to see if there is any warning coming on server 2.

@SamanthJain If possible, could you please also attach your input and output documents? We will test conversion on our side and provide you more information.