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

Free Support Forum - aspose.com

Text justification changed after replacing fonts

We are needing to replace fonts in pdf documents using older fonts, to do this we are using this code snippet provided to us in relation to this issue:

The problem is the font replacement changes the horizontal alignment of all affected text, to fix this we are trying to re-apply FullyJustify horizontal alignment, but it seems this feature is not functional.

Here is the file and code we used:

var document = new Document(inputStream);
for(var page: document.getPages()) {
    var absorber = new TextFragmentAbsorber();

    for(var textFragment: absorber.getTextFragments()) {
        String fontName = textFragment.getTextState().getFont().getFontName();
        if (fontName.endsWith("PSMT"))
            var newFont = FontRepository.findFont(fontName);

SAE Narrative.pdf (83.2 KB)


Please check the attached PDF that we obtained in our environment while testing the case using your code snippet and Aspose.PDF for Java 21.11. Could you please share a screenshot in which effected text is pointed out? We will further proceed to assist you accordingly.

output.pdf (216.3 KB)

Original Document with FullJustify image.png (67.6 KB)

Processed Document with font replaced, no longer FullJustify and characters are either overlapping or spaced too far image.png (49.3 KB)


We were able to this issue in our environment. Therefore, we have logged it as PDFJAVA-41101 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.