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();
page.accept(absorber);
for(var textFragment: absorber.getTextFragments()) {
String fontName = textFragment.getTextState().getFont().getFontName();
if (fontName.endsWith("PSMT"))
{
var newFont = FontRepository.findFont(fontName);
textFragment.getTextState().setFont(newFont);
textFragment.setHorizontalAlignment(5);
}
}
}
SAE Narrative.pdf (83.2 KB)